Opened 9 years ago

Closed 9 years ago

#5054 closed defect (fixed)

timesince doens't seem to respect UTC timestamps in db

Reported by: ayleph Owned by:
Priority: minor Milestone: 0.8.0
Component: programming Keywords: timezone, UTC, timesince
Cc: Parent Tickets:


After upgrading my db for 0.8.0, new media entries have UTC timestamps (rather than GMT-5 that all of my old media entries have). However, new media always shows as added/submitted 0 mins ago. It seems that timesince doesn't account for the time zone difference.

Attachments (1)

0001-Use-UTC-for-all-timesince-comparisons.patch (1.9 KB ) - added by ayleph 9 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by ayleph, 9 years ago

I should add that after some hours have passed, the media which previously showed "Added 0 mins ago" will update to say "Added x hours, y mins ago." Of course, it's off by the 5 or so hours I am behind UTC, so media added 6 hours, 37 mins ago might say "Added 1 hour, 37 mins ago."

comment:2 by ayleph, 9 years ago

I tracked down the problem to this line in mediagoblin/tools/

now = if is_aware(d) else None)

is_aware(d) always returns false for me, indicating the timestamps stored in the postgresql db are hardcoded UTC and don't contain timezone information. This causes this line to perform a comparison between the current system timezone time and the db object UTC time in this line:

delta = (d - now) if reversed else (now - d)

comment:3 by ayleph, 9 years ago

Status: newreview

The attached patch modifies to always use UTC when instantiating now. This works okay for my server, but this solution is naive and would cause problems if other parts of the code do things in timezone-aware, non-UTC timestamps.

comment:4 by Jessica Tallon, 9 years ago

Resolution: fixed
Status: reviewclosed

I've reviewed the patch and it works where timesince is used (should be everywhere in webUI). A potentially better solution might have been a UTCField which reads the timestamp from the database and adds the UTC timezone so it's not aware however, all code should assume timestamps are in UTC.

This is in master as of c975bd3.

Note: See TracTickets for help on using tickets.