Login

Tag "timezones"

Snippet List

Generate iCal VTIMEZONE block with DAYLIGHT and STANDARD components, based on pytz zoneinfo data

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
Read More

UTC-based astimezone filter

A version of http://djangosnippets.org/snippets/2388/ which assumes UTC-based dates. This is when you store dates in UTC (as you should), and want to display them in your site's local timezone, and you notice that Django's timesince/time template tags still do not support timezones.

  • timezone
  • utc
  • timezones
  • times
Read More

Template tags for localizing UTC times with pytz

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

  • timezone
  • pytz
  • timezones
Read More

South introspection rules for TimeZoneFields

TimeZoneField is not supported with South 0.7. This snippet adds a custom rule to the introspection rules for TimeZoneField. The code is found in the following thread, and fixed according to the latest version of TimeZoneField. http://groups.google.com/group/south-users/browse_thread/thread/34a05331140ee4dd **Usage** Simplest way is to save this snippet in a south_rules.py file and add an import in the models.py.

  • timezones
  • south
  • timezonefield
Read More

5 snippets posted so far.