Snippet List
In the last few days I spent a lot of time trying to find a library or repository of some kind that could help me generate the required DAYLIGHT and STANDARD components of ical VTIMEZONE blocks.
Since I couldn't find anything, I cobbled together this snippet to poke around in pytz timezone information and output the bare minimum I needed to make my ICS files compliant and useful (DST transitions for this year and the next).
I promise it's (superficially) tested against "real" ICS files, but that's all.
UPDATE: Thanks to @ariannedee for a much improved version (see comment for details)
- pytz
- timezones
- ical
- icalendar
- ics
For example:
Last modified: {% localdt item.modified_utc %} ({% localtimesince time.modified_utc %})
Converts the input datetimes to the timezone specified by the localtz context variable (it can also be explicitly specified, and all those other sensible things).
Input UTC datetimes can be specified using either a datetime or a timestamp.
Provides `localdt`, `localtime`, `localdate` and `localtimesince`.
should probably be migrated to an inclusion tag to allow a source timezone that isn't the site specific TIME_ZONE.
This code assumes that your database stores dates according to the django.conf.settings.TIME_ZONE variable.
Yes.. this assumes that dates are stored in the database according to system time. On my systems the system time of a server is always UTC therefore avoiding problems with datetime (no tz info) columns in backend databases having no timezone information and stored according to the database or system timezone information. I find it a good practice to always use UTC for any stored information and always retrieve information as UTC and localize the date during display.
- templatetag
- datetime
- timezone
- pytz
4 snippets posted so far.