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.
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.
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.