For minimum support of time zones, without adding any external dependencies e.g. pytz, Sider had to implement Utc class which is a subtype of datetime.tzinfo.
Because datetime module provided by the Python standard library doesn’t contain UTC or any other tzinfo subtype implementations. (A funny thing is that the documentation of datetime module shows an example of how to implement UTC tzinfo.)
If you want more various time zones support use the third-party pytz package.
Fixed offset in minutes east from UTC.
>>> import datetime
>>> day = FixedOffset(datetime.timedelta(days=1))
>>> day
sider.datetime.FixedOffset(1440)
>>> day.tzname(None)
'+24:00'
>>> half = FixedOffset(-720)
>>> half
sider.datetime.FixedOffset(-720)
>>> half.tzname(None)
'-12:00'
>>> half.utcoffset(None)
datetime.timedelta(-1, 43200)
>>> zero = FixedOffset(0)
>>> zero.tzname(None)
'UTC'
>>> zero.utcoffset(None)
datetime.timedelta(0)
Parameters: |
|
---|---|
Raises exceptions.ValueError: | |
when offset‘s precision is too short or too long |
(datetime.timedelta) The maximum precision of utcoffset().
(datetime.timedelta) The minimum precision of utcoffset().
The datetime.tzinfo implementation of UTC.
>>> from datetime import datetime
>>> utc = Utc()
>>> dt = datetime(2012, 3, 15, 0, 15, 30, tzinfo=utc)
>>> dt
datetime.datetime(2012, 3, 15, 0, 15, 30, tzinfo=sider.datetime.Utc())
>>> utc.utcoffset(dt)
datetime.timedelta(0)
>>> utc.dst(dt)
datetime.timedelta(0)
>>> utc.tzname(dt)
'UTC'
(datetime.timedelta) No difference.
For Python 2.6 compatibility. Equivalent to timedelta.total_seconds() method which was introduced in Python 2.7.
Parameters: | timedelta (datetime.timedelta) – the timedelta |
---|---|
Returns: | the total number of seconds contained in the duration |
The current time in UTC. The Python standard library also provides datetime.datetime.utcnow() function except it returns a naive datetime.datetime value. This function returns tz-aware datetime.datetime value instead.
>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(...)
>>> utcnow()
datetime.datetime(..., tzinfo=sider.datetime.Utc())
Returns: | the tz-aware datetime value of the current time |
---|---|
Return type: | datetime.datetime |
Full-text doc search.
sider.warnings — Warning categories
Enter search terms or a module, class or function name.