app/django/utils/timesince.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
--- a/app/django/utils/timesince.py	Tue Oct 14 12:36:55 2008 +0000
+++ b/app/django/utils/timesince.py	Tue Oct 14 16:00:59 2008 +0000
@@ -28,15 +28,12 @@
     # Convert datetime.date to datetime.datetime for comparison
     if d.__class__ is not datetime.datetime:
         d = datetime.datetime(d.year, d.month, d.day)
-    if now:
-        t = now.timetuple()
-    else:
-        t = time.localtime()
-    if d.tzinfo:
-        tz = LocalTimezone(d)
-    else:
-        tz = None
-    now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz)
+
+    if not now:
+        if d.tzinfo:
+            now = datetime.datetime.now(LocalTimezone(d))
+        else:
+            now = datetime.datetime.now()
 
     # ignore microsecond part of 'd' since we removed it from 'now'
     delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
@@ -62,6 +59,9 @@
     Like timesince, but returns a string measuring the time until
     the given time.
     """
-    if now == None:
-        now = datetime.datetime.now()
+    if not now:
+        if getattr(d, 'tzinfo', None):
+            now = datetime.datetime.now(LocalTimezone(d))
+        else:
+            now = datetime.datetime.now()
     return timesince(now, d)