]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix locale.format_date on python 3.
authorBen Darnell <ben@bendarnell.com>
Sun, 28 Apr 2013 22:40:31 +0000 (18:40 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 28 Apr 2013 22:40:31 +0000 (18:40 -0400)
There's probably more work to be done on this largely-untested code,
but this was the case I could find by grepping for stray references
to `long`.

tornado/locale.py
tornado/test/locale_test.py

index 66e9ff6d8a149e316cb1acf3ada43d11b9efea3b..310a5178491585bef4ce1cfdc184ab268c6d4bfd 100644 (file)
@@ -43,6 +43,7 @@ from __future__ import absolute_import, division, print_function, with_statement
 
 import csv
 import datetime
+import numbers
 import os
 import re
 
@@ -287,7 +288,7 @@ class Locale(object):
         """
         if self.code.startswith("ru"):
             relative = False
-        if type(date) in (int, long, float):
+        if isinstance(date, numbers.Real):
             date = datetime.datetime.utcfromtimestamp(date)
         now = datetime.datetime.utcnow()
         if date > now:
index 043f5d278ec5ef8171a03ebab679d2d3ff104f3b..948228f18d6698ffae5048f0c16729f75b0e73cf 100644 (file)
@@ -1,5 +1,6 @@
 from __future__ import absolute_import, division, print_function, with_statement
 
+import datetime
 import os
 import tornado.locale
 from tornado.escape import utf8
@@ -48,3 +49,11 @@ class LocaleDataTest(unittest.TestCase):
         self.assertTrue(isinstance(name, unicode_type))
         self.assertEqual(name, u('Espa\u00f1ol'))
         self.assertEqual(utf8(name), b'Espa\xc3\xb1ol')
+
+
+class EnglishTest(unittest.TestCase):
+    def test_format_date(self):
+        locale = tornado.locale.get('en_US')
+        date = datetime.datetime(2013, 4, 28, 18, 35)
+        self.assertEqual(locale.format_date(date, full_format=True),
+                         'April 28, 2013 at 6:35 pm')