Class: Time

Inherits:
Object show all
Defined in:
lib/jss/ruby_extensions/time.rb

Overview

The JSS API can take incoming timestamp data in three formats:

  • plain date: YYYY-mm-dd HH:MM:SS, which is assumed to be in the local timezone

  • UTC date: YYYY-mm-ddTHH:MM:SS.mmm [+-]zzzz, the local time with milliseconds and the timezone offset

  • Unix epoch with milliseconds, nnnnnnnnnnnnn, which like all epoch times, is UTC

Here we extend Time to return the three formats for use in XML data to pass back to the API. The API xml works with any of the formats, in appropriate elements.

Generally this gem uses the epoch format for passing values back to the API, just to help avoid timezone weirdness, but any should work.

When reading from the API, all three formats are returned in different xml elements, and the APIObjects in the gem will use the epoch format and the JSS.epoch_to_time method (q.v.) to store the data as a Ruby Time.

Instance Method Summary collapse

Instance Method Details

#jss_msecInteger


45
46
47
# File 'lib/jss/ruby_extensions/time.rb', line 45

def jss_msec
  (self.usec/1000.0).round
end

#to_jss_dateString


55
56
57
# File 'lib/jss/ruby_extensions/time.rb', line 55

def to_jss_date
  self.strftime '%Y-%m-%d %H:%M:%S'
end

#to_jss_epochInteger


50
51
52
# File 'lib/jss/ruby_extensions/time.rb', line 50

def to_jss_epoch
  (self.strftime('%s') + self.jss_msec.to_s.ljust(3,'0')).to_i
end

#to_jss_utcString


60
61
62
# File 'lib/jss/ruby_extensions/time.rb', line 60

def to_jss_utc
  self.strftime("%Y-%m-%dT%H:%M:%S.#{self.jss_msec}%z")
end