From: Ben Darnell Date: Tue, 12 Oct 2010 00:17:13 +0000 (-0700) Subject: Make Locale.format_date() behave sanely with dates in the future. X-Git-Tag: v1.2.0~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c7b0117cffb6abb336407e392f0ecd3b3e3c1da;p=thirdparty%2Ftornado.git Make Locale.format_date() behave sanely with dates in the future. Closes #150. --- diff --git a/tornado/locale.py b/tornado/locale.py index a2d9b2b13..0e3d7967f 100644 --- a/tornado/locale.py +++ b/tornado/locale.py @@ -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)