I've created an events site with Django 1.5.4 and postgres 9.1. The time just changed for "fall back" and all the date/time data entered by admins before the time change are now an hour off.
In my Django settings I have TIME_ZONE = 'America/Chicago'
and USE_TZ = True
. The events site is for a small city in the US Central time zone. The server and the database are also set for this time zone. Looking in the database I can tell which event occurrences are from before the change, because they all say '-05' at the end, and the ones entered after say '-06'. Though, as I understand it, postgres should be saving the timestamps as UTC, even though it's displaying it to me with the offset.
To display the data, I'm pulling it out of the database via Django's ORM, then using astimezone
on each occurrence's start datetime, like so:
LOCAL_TZ = pytz.timezone(settings.TIME_ZONE)
def upcoming_week(start=None):
if not start:
start = date.today()
plus7 = start + timedelta(days=6)
occurs = models.Occurrence.objects.between(start, plus7) \
.select_related('event', 'event__location', 'event__priority')
return (start, plus7, occurs)
def upcoming_week_by_date(start=None):
start, plus7, occurs = upcoming_week()
_occurs_by_date = defaultdict(list)
for o in occurs:
dt = o.start.astimezone(LOCAL_TZ)
_occurs_by_date[dt.date()].append(o)
occurs_by_date = _occurs_by_date.items()
occurs_by_date.sort()
return (start, plus7, occurs_by_date)
This particular piece of code is used to arrange events by date on the home page, and all day events, which are set to start at midnight, are now showing up on the previous day. The time is also displayed as "11pm", and that is being rendered by Django (not processed with pytz by me).
I also have code that converts the occurrences to json for consumption by javascript, and that uses astimezone
the same way as above, and all the events (created before the time change) are showing an hour too early there as well.
I'm using a fork of eventtools here: https://github.com/FirelightWebware/glamkit-eventtools, and the times show correctly in the admin.
Update: It's only the occurrences that were created before the time change and occur after the time change that are off by an hour. So technically everything is working correctly, since those were created in a different time zone, the adjustment makes some kind of sense. So the question is, is there a way to create, before a time change, occurrences that should happen after the time change, with the correct time? For now I will have to tell admins to only create occurrences up until a time change, then after the time change, create more occurrences. Which is ridiculous.