Date/Time Utils¶
TimeZoneHelper
¶
- class djem.utils.dt.TimeZoneHelper(tz)[source]¶
A simple helper class that provides shortcuts for getting the current date and the current datetime for a known local timezone.
tz
should be a valid timezone name string (as accepted by thepytz.timezone
function) or apytz
tzinfo
instance (as returned by thepytz.timezone
function).- tz¶
The
pytz
tzinfo
instance representing the timezone used by thisTimeZoneHelper
instance.
- name¶
The name of the timezone represented by this
TimeZoneHelper
instance, as a string. Equivalent totz.zone
, wheretz
is theinstance's tz attribute
.
Warning
Be careful when dealing with local times. Django recommends you “use UTC in the code and use local time only when interacting with end users”, with the conversion from UTC to local time usually only being performed in templates. And the pytz documentation notes “The preferred way of dealing with times is to always work in UTC, converting to localtime only when generating output to be read by humans”. See the Django timezone documentation and the pytz documentation.