gpstime package

datetime with GPS time support

This module primarily provides functions for converting to/from UNIX and GPS times, as well as a gpstime class that directly inherits from the builtin datetime class, adding additional methods for GPS time input and output.

Leap seconds are expected to be provided by the core libc Time Zone Database tzdata. If for some reason the tzdata leapsecond file is not available, a local cache of the IETF leap second record will be maintained:

KNOWN BUGS: This module does not currently handle conversions of time strings describing the actual leap second themselves, which are usually represented as the 60th second of the minute during which the leap second occurs.

exception gpstime.GPSTimeException[source]

Bases: Exception

class gpstime.GPSTimeParseAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

gpstime argparse argumention parser Action.

Parses an arbitrary date/time string into a gpstime object.

gpstime.gps2unix(gps)[source]

Convert GPS time to UNIX timestamp.

gpstime.gpsnow()[source]

Return current GPS time as a float.

class gpstime.gpstime[source]

Bases: datetime

GPS-aware datetime class

An extension of the datetime class, with the addition of methods for converting to/from GPS times:

>>> from gpstime import gpstime
>>> gt = gpstime.fromgps(1088442990)
>>> gt.gps()
1088442990.0
>>> gt.strftime('%Y-%m-%d %H:%M:%S %Z')
'2014-07-03 17:16:14 UTC'
>>> gpstime.now().gps()
1133737481.204008

In addition a natural language parsing parse classmethod returns a gpstime object for a arbitrary time string:

>>> gpstime.parse('2014-07-03 17:16:14 UTC').gps()
1088442990.0
>>> gpstime.parse('2 days ago').gps()
1158440653.553765
classmethod fromdatetime(datetime)[source]

Return gpstime object from datetime object

classmethod fromgps(gps)[source]

Return gpstime object corresponding to GPS time.

gps()[source]

Return GPS time as a float.

iso()[source]

Return time in standard UTC ISO format.

classmethod parse(string='now')[source]

Parse an arbitrary time string into a gpstime object.

If string not specified ‘now’ is assumed. Strings that can be cast to float are assumed to be GPS times. Prepend ‘@’ to a float to specify a UNIX timestamp.

This parse uses the natural lanuage parsing abilities of the GNU coreutils ‘date’ utility. See “DATE STRING” in date(1) for information on possible date/time descriptions.

classmethod tconvert(string='now')

Parse an arbitrary time string into a gpstime object.

If string not specified ‘now’ is assumed. Strings that can be cast to float are assumed to be GPS times. Prepend ‘@’ to a float to specify a UNIX timestamp.

This parse uses the natural lanuage parsing abilities of the GNU coreutils ‘date’ utility. See “DATE STRING” in date(1) for information on possible date/time descriptions.

gpstime.parse(string='now')

Parse an arbitrary time string into a gpstime object.

If string not specified ‘now’ is assumed. Strings that can be cast to float are assumed to be GPS times. Prepend ‘@’ to a float to specify a UNIX timestamp.

This parse uses the natural lanuage parsing abilities of the GNU coreutils ‘date’ utility. See “DATE STRING” in date(1) for information on possible date/time descriptions.

gpstime.tconvert(string='now', form='%Y-%m-%d %H:%M:%S.%f %Z')[source]

Reimplementation of LIGO “tconvert” binary behavior

Given a GPS time string, return the date/time string with the specified format. Given a date/time string, return the GPS time.

This just uses the gpstime.parse() method internally.

gpstime.unix2gps(unix)[source]

Convert UNIX timestamp to GPS time.

Submodules