FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-152305: Fix `_pydatetime.time.strftime()` raising on year directives (GH-152306) by miss-islington · Pull Request #152425 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions Lib/_pydatetime.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ def _wrap_strftime(object, format, timetuple):
newformat.append(Zreplace)
# Note that datetime(1000, 1, 1).strftime('%G') == '1000' so
# year 1000 for %G can go on the fast path.
elif ((ch in 'YG' or ch in 'FC') and
object.year < 1000 and _need_normalize_century()):
elif (ch in 'YGFC' and timetuple[0] < 1000 and
_need_normalize_century()):
if ch == 'G':
year = int(_time.strftime("%G", timetuple))
else:
year = object.year
year = timetuple[0]
if ch == 'C':
push('{:02}'.format(year // 100))
else:
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/datetimetester.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,11 @@ def test_strftime_special(self):
self.assertEqual(t.strftime('\0'*1000), '\0'*1000)
self.assertEqual(t.strftime('\0%I%p%Z\0%X'), f'\0{s1}\0{s2}')
self.assertEqual(t.strftime('%I%p%Z\0%X\0'), f'{s1}\0{s2}\0')
# gh-152305: the year directives must not raise on a time.
for directive, expected in (('%Y', '1900'), ('%G', '1900'),
('%C', '19'), ('%F', '1900-01-01')):
with self.subTest(directive=directive):
self.assertEqual(t.strftime(directive), expected)

def test_format(self):
t = self.theclass(1, 2, 3, 4)
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the pure-Python :meth:`datetime.time.strftime` implementation raising :exc:`AttributeError` for the
year directives. Patch by tonghuaroot.
Loading

Back | FazBrowse Home | New Git URL