| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,12 +272,12 @@ def _wrap_strftime(object, format, timetuple): | |||
| 272 | 272 | newformat.append(Zreplace) | |
| 273 | 273 | # Note that datetime(1000, 1, 1).strftime('%G') == '1000' so | |
| 274 | 274 | # year 1000 for %G can go on the fast path. | |
| 275 | - elif ((ch in 'YG' or ch in 'FC') and | ||
| 276 | - object.year < 1000 and _need_normalize_century()): | ||
| 275 | + elif (ch in 'YGFC' and timetuple[0] < 1000 and | ||
| 276 | + _need_normalize_century()): | ||
| 277 | 277 | if ch == 'G': | |
| 278 | 278 | year = int(_time.strftime("%G", timetuple)) | |
| 279 | 279 | else: | |
| 280 | - year = object.year | ||
| 280 | + year = timetuple[0] | ||
| 281 | 281 | if ch == 'C': | |
| 282 | 282 | push('{:02}'.format(year // 100)) | |
| 283 | 283 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4119,6 +4119,11 @@ def test_strftime_special(self): | |||
| 4119 | 4119 | self.assertEqual(t.strftime('\0'*1000), '\0'*1000) | |
| 4120 | 4120 | self.assertEqual(t.strftime('\0%I%p%Z\0%X'), f'\0{s1}\0{s2}') | |
| 4121 | 4121 | self.assertEqual(t.strftime('%I%p%Z\0%X\0'), f'{s1}\0{s2}\0') | |
| 4122 | + # gh-152305: the year directives must not raise on a time. | ||
| 4123 | + for directive, expected in (('%Y', '1900'), ('%G', '1900'), | ||
| 4124 | + ('%C', '19'), ('%F', '1900-01-01')): | ||
| 4125 | + with self.subTest(directive=directive): | ||
| 4126 | + self.assertEqual(t.strftime(directive), expected) | ||
| 4122 | 4127 | ||
| 4123 | 4128 | def test_format(self): | |
| 4124 | 4129 | t = self.theclass(1, 2, 3, 4) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix the pure-Python :meth:`datetime.time.strftime` implementation raising :exc:`AttributeError` for the | ||
| 2 | + year directives. Patch by tonghuaroot. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments