]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make Locale.format_date() behave sanely with dates in the future.
authorBen Darnell <ben@bendarnell.com>
Tue, 12 Oct 2010 00:17:13 +0000 (17:17 -0700)
committerBen Darnell <ben@bendarnell.com>
Tue, 12 Oct 2010 00:19:03 +0000 (17:19 -0700)
Closes #150.

tornado/locale.py

index a2d9b2b139eda436f09004e7c811942b526e9e75..0e3d7967fbe8b17b86743afbd1114abbc594b482 100644 (file)
@@ -242,15 +242,24 @@ class Locale(object):
 
         You can force a full format date ("July 10, 1980") with
         full_format=True.
+
+        This method is primarily intended for dates in the past.
+        For dates in the future, we fall back to full format.
         """
         if self.code.startswith("ru"):
             relative = False
         if type(date) in (int, long, float):
             date = datetime.datetime.utcfromtimestamp(date)
         now = datetime.datetime.utcnow()
-        # Round down to now. Due to click skew, things are somethings
-        # slightly in the future.
-        if date > now: date = now
+        if date > now:
+            if relative and (date - now).seconds < 60:
+                # Due to click skew, things are some things slightly
+                # in the future. Round timestamps in the immediate
+                # future down to now in relative mode.
+                date = now
+            else:
+                # Otherwise, future dates always use the full format.
+                full_format = True
         local_date = date - datetime.timedelta(minutes=gmt_offset)
         local_now = now - datetime.timedelta(minutes=gmt_offset)
         local_yesterday = local_now - datetime.timedelta(hours=24)