comparison babel/tests/dates.py @ 577:e57abed6542a trunk

fix format_date() with a datetime parameter (#282)
author fschwarz
date Mon, 30 Jul 2012 21:48:55 +0000
parents 33153e2550a8
children 5ba68e40d1d0
comparison
equal deleted inserted replaced
576:e77dd06c40ef 577:e57abed6542a
81 81
82 def test_day_of_year(self): 82 def test_day_of_year(self):
83 d = date(2007, 4, 1) 83 d = date(2007, 4, 1)
84 fmt = dates.DateTimeFormat(d, locale='en_US') 84 fmt = dates.DateTimeFormat(d, locale='en_US')
85 self.assertEqual('91', fmt['D']) 85 self.assertEqual('91', fmt['D'])
86
87 def test_day_of_year_works_with_datetime(self):
88 d = datetime(2007, 4, 1)
89 fmt = dates.DateTimeFormat(d, locale='en_US')
90 self.assertEqual('91', fmt['D'])
86 91
87 def test_day_of_year_first(self): 92 def test_day_of_year_first(self):
88 d = date(2007, 1, 1) 93 d = date(2007, 1, 1)
89 fmt = dates.DateTimeFormat(d, locale='en_US') 94 fmt = dates.DateTimeFormat(d, locale='en_US')
90 self.assertEqual('001', fmt['DDD']) 95 self.assertEqual('001', fmt['DDD'])
228 def test_with_time_fields_in_pattern_and_datetime_param(self): 233 def test_with_time_fields_in_pattern_and_datetime_param(self):
229 self.assertRaises(AttributeError, dates.format_date, 234 self.assertRaises(AttributeError, dates.format_date,
230 datetime(2007, 04, 01, 15, 30), 235 datetime(2007, 04, 01, 15, 30),
231 "yyyy-MM-dd HH:mm", locale='en_US') 236 "yyyy-MM-dd HH:mm", locale='en_US')
232 237
238 def test_with_day_of_year_in_pattern_and_datetime_param(self):
239 # format_date should work on datetimes just as well (see #282)
240 d = datetime(2007, 04, 01)
241 self.assertEqual('14', dates.format_date(d, 'w', locale='en_US'))
242
233 243
234 class FormatTimeTestCase(unittest.TestCase): 244 class FormatTimeTestCase(unittest.TestCase):
235 245
236 def test_with_naive_datetime_and_tzinfo(self): 246 def test_with_naive_datetime_and_tzinfo(self):
237 string = dates.format_time(datetime(2007, 4, 1, 15, 30), 247 string = dates.format_time(datetime(2007, 4, 1, 15, 30),
Copyright (C) 2012-2017 Edgewall Software