MCPcopy Create free account
hub / github.com/EasyIME/PIME / test_format_date

Method test_format_date

python/python3/tornado/test/locale_test.py:89–134  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

87
88class EnglishTest(unittest.TestCase):
89 def test_format_date(self):
90 locale = tornado.locale.get("en_US")
91 date = datetime.datetime(2013, 4, 28, 18, 35)
92 self.assertEqual(
93 locale.format_date(date, full_format=True), "April 28, 2013 at 6:35 pm"
94 )
95
96 now = datetime.datetime.utcnow()
97
98 self.assertEqual(
99 locale.format_date(now - datetime.timedelta(seconds=2), full_format=False),
100 "2 seconds ago",
101 )
102 self.assertEqual(
103 locale.format_date(now - datetime.timedelta(minutes=2), full_format=False),
104 "2 minutes ago",
105 )
106 self.assertEqual(
107 locale.format_date(now - datetime.timedelta(hours=2), full_format=False),
108 "2 hours ago",
109 )
110
111 self.assertEqual(
112 locale.format_date(
113 now - datetime.timedelta(days=1), full_format=False, shorter=True
114 ),
115 "yesterday",
116 )
117
118 date = now - datetime.timedelta(days=2)
119 self.assertEqual(
120 locale.format_date(date, full_format=False, shorter=True),
121 locale._weekdays[date.weekday()],
122 )
123
124 date = now - datetime.timedelta(days=300)
125 self.assertEqual(
126 locale.format_date(date, full_format=False, shorter=True),
127 "%s %d" % (locale._months[date.month - 1], date.day),
128 )
129
130 date = now - datetime.timedelta(days=500)
131 self.assertEqual(
132 locale.format_date(date, full_format=False, shorter=True),
133 "%s %d, %d" % (locale._months[date.month - 1], date.day, date.year),
134 )
135
136 def test_friendly_number(self):
137 locale = tornado.locale.get("en_US")

Callers

nothing calls this directly

Calls 2

format_dateMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected