Onyx logo

Previous topic

onyx.util.timedict – Simple storage for timing information.

Next topic

Base

This Page

onyx.util.timestamp – Generation of time stamps for general use

class onyx.util.timestamp.TZ

Bases: datetime.tzinfo

dst(dt)
fromutc

datetime in UTC -> datetime in local time.

tzname

datetime -> string name of time zone.

utcoffset(dt)
onyx.util.timestamp.get_timestamp(dt=None)

Return a timestamp string for general use.

This function returns a timestamp string in the format YYYY-MM-DD-ddd-HH:MM:SS.mmmmmmm+HH:MM. If dt is not None, it should be a Python datetime.datetime object which will be formatted, otherwise, a datetime object is created by calling datetime.now().

>>> dt = datetime.datetime(2002, 12, 25, 13, 45, 56, 123456, _DummyTZ())
>>> get_timestamp(dt)
'2002-12-25-Wed-13:45:56.123456+0000'

The expected use will be to get a current time stamp, but this is hard to test.

>>> ts0 = get_timestamp()
>>> len(ts0)
35
>>> ts0[0:2], ts0[4], ts0[7]
('20', '-', '-')

Uncomment this to see what time it is :->.

>>> # ts0

The TIMESTAMP_RE object in this module is a compiled regular expression that matches a timestamp string and groups it into 9 parts: year, month, date, day, hour, minute, second, microsecond, and UTC offset.

>>> match = TIMESTAMP_RE.match(ts0)
>>> len(match.groups())
9