pyrfc3339.utils
– Utilities for working with timestamps¶
-
class
pyrfc3339.utils.
FixedOffset
(hours, minutes)¶ Represent a timezone with a fixed offset from UTC and no adjustment for DST.
>>> FixedOffset(4,0) <UTC+04:00> >>> FixedOffset(-4,0) <UTC-04:00> >>> FixedOffset(4,30) <UTC+04:30>
>>> tz = FixedOffset(-5,0) >>> tz.dst(None) datetime.timedelta(0)
The class tries to do the right thing with the sign of the time zone offset:
>>> FixedOffset(-9,30) <UTC-09:30> >>> FixedOffset(-9,-30) Traceback (most recent call last): ... ValueError: minutes must not be negative
Offsets must thus be normalized so that the minute value is positive:
>>> FixedOffset(-8,30) <UTC-08:30>
-
dst
(dt)¶ Return offset for DST. Always returns timedelta(0).
-
tzname
(dt)¶ Return name of timezone.
-
utcoffset
(dt)¶ Return offset from UTC.
-
-
pyrfc3339.utils.
timedelta_seconds
(td)¶ Return the offset stored by a
datetime.timedelta
object as an integer number of seconds. Microseconds, if present, are rounded to the nearest second.Delegates to
timedelta.total_seconds()
if available.>>> timedelta_seconds(timedelta(hours=1)) 3600 >>> timedelta_seconds(timedelta(hours=-1)) -3600 >>> timedelta_seconds(timedelta(hours=1, minutes=30)) 5400 >>> timedelta_seconds(timedelta(hours=1, minutes=30, ... microseconds=300000)) 5400 >>> timedelta_seconds(timedelta(hours=1, minutes=30, ... microseconds=900000)) 5401
-
pyrfc3339.utils.
timezone
(utcoffset)¶ Return a string representing the timezone offset. Remaining seconds are rounded to the nearest minute.
>>> timezone(3600) '+01:00' >>> timezone(5400) '+01:30' >>> timezone(-28800) '-08:00'