|
1 import unittest |
|
2 |
|
3 from datetime import date as original_date, datetime as original_datetime |
|
4 from django.utils.datetime_safe import date, datetime |
|
5 |
|
6 class DatetimeTests(unittest.TestCase): |
|
7 |
|
8 def setUp(self): |
|
9 self.just_safe = (1900, 1, 1) |
|
10 self.just_unsafe = (1899, 12, 31, 23, 59, 59) |
|
11 self.really_old = (20, 1, 1) |
|
12 self.more_recent = (2006, 1, 1) |
|
13 |
|
14 def test_compare_datetimes(self): |
|
15 self.assertEqual(original_datetime(*self.more_recent), datetime(*self.more_recent)) |
|
16 self.assertEqual(original_datetime(*self.really_old), datetime(*self.really_old)) |
|
17 self.assertEqual(original_date(*self.more_recent), date(*self.more_recent)) |
|
18 self.assertEqual(original_date(*self.really_old), date(*self.really_old)) |
|
19 |
|
20 self.assertEqual(original_date(*self.just_safe).strftime('%Y-%m-%d'), date(*self.just_safe).strftime('%Y-%m-%d')) |
|
21 self.assertEqual(original_datetime(*self.just_safe).strftime('%Y-%m-%d'), datetime(*self.just_safe).strftime('%Y-%m-%d')) |
|
22 |
|
23 def test_safe_strftime(self): |
|
24 self.assertEquals(date(*self.just_unsafe[:3]).strftime('%Y-%m-%d (weekday %w)'), '1899-12-31 (weekday 0)') |
|
25 self.assertEquals(date(*self.just_safe).strftime('%Y-%m-%d (weekday %w)'), '1900-01-01 (weekday 1)') |
|
26 |
|
27 self.assertEquals(datetime(*self.just_unsafe).strftime('%Y-%m-%d %H:%M:%S (weekday %w)'), '1899-12-31 23:59:59 (weekday 0)') |
|
28 self.assertEquals(datetime(*self.just_safe).strftime('%Y-%m-%d %H:%M:%S (weekday %w)'), '1900-01-01 00:00:00 (weekday 1)') |
|
29 |
|
30 # %y will error before this date |
|
31 self.assertEquals(date(*self.just_safe).strftime('%y'), '00') |
|
32 self.assertEquals(datetime(*self.just_safe).strftime('%y'), '00') |
|
33 |
|
34 self.assertEquals(date(1850, 8, 2).strftime("%Y/%m/%d was a %A"), '1850/08/02 was a Friday') |
|
35 |
|
36 def test_zero_padding(self): |
|
37 """ |
|
38 Regression for #12524 |
|
39 |
|
40 Check that pre-1000AD dates are padded with zeros if necessary |
|
41 """ |
|
42 self.assertEquals(date(1, 1, 1).strftime("%Y/%m/%d was a %A"), '0001/01/01 was a Monday') |