Permalink
Browse files

Merge pull request #49 from spookylukey/fix_timezone_support

Fixed bug with Django 1.4 with image/file popups caused by naive/aware d...
  • Loading branch information...
2 parents 6a79625 + 88801ae commit 6950b23b45d4372bc4d500e50fb2bcf3db1685c0 @dbunskoek dbunskoek committed Jan 17, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 fiber/utils/date.py
View
@@ -1,14 +1,21 @@
from django.utils.translation import ugettext_lazy as _
+from datetime import datetime
+
+try:
+ # For Django 1.4, django.utils.timezone exists, and we need to handle
+ # timezone aware datetimes being passed in to friendly_datetime
+ from django.utils import timezone
+ tz_now = timezone.now
+except ImportError:
+ tz_now = datetime.now
def friendly_datetime(date_time):
"""
Given a datetime object or an int() Unix timestamp, return a friendly
string like 'an hour ago', 'yesterday', '3 months ago', 'just now', etc.
"""
- from datetime import datetime
-
- now = datetime.now()
+ now = tz_now()
if type(date_time) is datetime:
diff = now - date_time
elif type(date_time) is int:

0 comments on commit 6950b23

Please sign in to comment.