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.
tzshould be a valid timezone name string (as accepted by thepytz.timezonefunction) or apytztzinfoinstance (as returned by thepytz.timezonefunction).- tz
The
pytztzinfoinstance representing the timezone used by thisTimeZoneHelperinstance.
- name
The name of the timezone represented by this
TimeZoneHelperinstance, as a string. Equivalent totz.zone, wheretzis 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.