Opened 8 years ago
Closed 8 years ago
#5054 closed defect (fixed)
timesince doens't seem to respect UTC timestamps in db
|Reported by:||ayleph||Owned by:|
|Component:||programming||Keywords:||timezone, UTC, timesince|
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.
Change History (5)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
I tracked down the problem to this line in
now = datetime.datetime.now(utc 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)
by , 8 years ago
comment:3 by , 8 years ago
|Status:||new → review|
The attached patch modifies
timesince.py 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 , 8 years ago
|Status:||review → closed|
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.
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."