From: Lee Kyoung chan Date: Tue, 23 Sep 2014 10:13:22 +0000 (+0900) Subject: Improve test_format_date X-Git-Tag: v4.1.0b1~78^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9b305a10dcbf2be41519c5ccdaca7c3f902ce20;p=thirdparty%2Ftornado.git Improve test_format_date --- diff --git a/tornado/test/locale_test.py b/tornado/test/locale_test.py index 948228f18..b28f37d1b 100644 --- a/tornado/test/locale_test.py +++ b/tornado/test/locale_test.py @@ -57,3 +57,26 @@ class EnglishTest(unittest.TestCase): date = datetime.datetime(2013, 4, 28, 18, 35) self.assertEqual(locale.format_date(date, full_format=True), 'April 28, 2013 at 6:35 pm') + + self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(seconds=2), full_format=False), + '2 seconds ago') + self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(minutes=2), full_format=False), + '2 minutes ago') + self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(hours=2), full_format=False), + '2 hours ago') + + now = datetime.datetime.utcnow() + self.assertEqual(locale.format_date(now - datetime.timedelta(days=1), full_format=False, shorter=True), + 'yesterday') + + date = now - datetime.timedelta(days=2) + self.assertEqual(locale.format_date(date, full_format=False, shorter=True), + locale._weekdays[date.weekday()]) + + date = now - datetime.timedelta(days=300) + self.assertEqual(locale.format_date(date, full_format=False, shorter=True), + '%s %d' % (locale._months[date.month - 1], date.day)) + + date = now - datetime.timedelta(days=500) + self.assertEqual(locale.format_date(date, full_format=False, shorter=True), + '%s %d, %d' % (locale._months[date.month - 1], date.day, date.year))