MCPcopy
hub / github.com/tornadoweb/tornado / test_format_date

Method test_format_date

tornado/test/locale_test.py:87–142  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

85
86class EnglishTest(unittest.TestCase):
87 def test_format_date(self):
88 locale = tornado.locale.get("en_US")
89 date = datetime.datetime(2013, 4, 28, 18, 35)
90 self.assertEqual(
91 locale.format_date(date, full_format=True), "April 28, 2013 at 6:35 pm"
92 )
93
94 aware_dt = datetime.datetime.now(datetime.timezone.utc)
95 naive_dt = aware_dt.replace(tzinfo=None)
96 for name, now in {"aware": aware_dt, "naive": naive_dt}.items():
97 with self.subTest(dt=name):
98 self.assertEqual(
99 locale.format_date(
100 now - datetime.timedelta(seconds=2), full_format=False
101 ),
102 "2 seconds ago",
103 )
104 self.assertEqual(
105 locale.format_date(
106 now - datetime.timedelta(minutes=2), full_format=False
107 ),
108 "2 minutes ago",
109 )
110 self.assertEqual(
111 locale.format_date(
112 now - datetime.timedelta(hours=2), full_format=False
113 ),
114 "2 hours ago",
115 )
116
117 self.assertEqual(
118 locale.format_date(
119 now - datetime.timedelta(days=1),
120 full_format=False,
121 shorter=True,
122 ),
123 "yesterday",
124 )
125
126 date = now - datetime.timedelta(days=2)
127 self.assertEqual(
128 locale.format_date(date, full_format=False, shorter=True),
129 locale._weekdays[date.weekday()],
130 )
131
132 date = now - datetime.timedelta(days=300)
133 self.assertEqual(
134 locale.format_date(date, full_format=False, shorter=True),
135 "%s %d" % (locale._months[date.month - 1], date.day),
136 )
137
138 date = now - datetime.timedelta(days=500)
139 self.assertEqual(
140 locale.format_date(date, full_format=False, shorter=True),
141 "%s %d, %d" % (locale._months[date.month - 1], date.day, date.year),
142 )
143
144 def test_friendly_number(self):

Callers

nothing calls this directly

Calls 4

format_dateMethod · 0.80
replaceMethod · 0.80
itemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected