8000 gh-122781: Fix `%z` in `strptime` by StanFromIreland · Pull Request #132922 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-122781: Fix %z in strptime #132922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move tests
  • Loading branch information
StanFromIreland committed May 20, 2025
commit ff751c8f7b937605b9cb75b95d6335bc5fe10621
17 changes: 11 additions & 6 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2921,12 +2921,6 @@ def test_strptime(self):
with self.assertRaises(ValueError): strptime("-000", "%z")
with self.assertRaises(ValueError): strptime("z", "%z")

# gh-issue: 122781; empty %z should pass
string = '2025-04-25 11:42:47'
format = '%Y-%m-%d %H:%M:%S%z'
result = self.theclass.strptime(string, format)
self.assertEqual(result, self.theclass(2025, 4, 25, 11, 42, 47))

def test_strptime_single_digit(self):
# bpo-34903: Check that single digit dates and times are allowed.

Expand Down Expand Up @@ -2975,6 +2969,17 @@ def test_strptime_leap_year(self):
with self._assertNotWarns(DeprecationWarning):
self.theclass.strptime('02-29,2024', '%m-%d,%Y')

def test_strptime_z_empty(self):
for directive in ('z',):
string = '2025-04-25 11:42:47'
format = f'%Y-%m-%d %H:%M:%S%{directive}'
target = self.theclass(2025, 4, 25, 11, 42, 47)
with self.subTest(string=string,
format=format,
target=target):
result = self.theclass.strptime(string, format)
self.assertEqual(result, target)

def test_more_timetuple(self):
# This tests fields beyond those tested by the TestDate.test_timetuple.
t = self.theclass(2004, 12, 31, 6, 22, 33)
Expand Down
Loading
0