Coverage for ion/util/iontime : 70.00%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/util/iontime.py @author Dave Foster <dfoster@asascience.com> @brief Time utility class """
""" Time utility class. Used for generating times in commonly used "milliseconds since unix epoch" format as used in many GPB messages.
Can be used to generate/convert string based ISO8601 (yyyy-MM-dd'T'HH:mm:ss.sss'Z').
@TODO: ISO8601 is hard to parse as there's a lot of optional stuff that python cannot really handle without a dedicated module. Needs to be able to handle a string as input. """
""" Constructs an IonTime instance using an optional time parameter. If specified, that time is used. If not, the current time is used.
@param time_in_ms Optional, the number of ms since the UNIX epoch (1970). """ self._time_ms = time_in_ms else:
""" Gets the current system time and converts to milliseconds from the unix epoch (1970). """
""" Gets the time in milliseconds since the UNIX epoch. This is the internal representation of time in this class and is just a passthrough to the private member var. """
""" Gets the time as ISO8601 Date Format (yyyy-MM-dd'T'HH:mm:ss.sss'Z'). """ # need to shift off the millis as python does not handle it well
(secs, fracsecs) = divmod(self._time_ms, 1000)
gmtuple = time.gmtime(secs)
iso_time = time.strftime("%Y-%m-%d'T'%H:%M:%S", gmtuple)
# append fractional time iso_time += '.' + str(fracsecs) + "'Z'"
return iso_time
|