Skip to content

gh-122781: fix time format bug #122829

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,14 @@ def pattern(self, format):
while '%' in format:
directive_index = format.index('%')+1
format_char = format[directive_index]
processed_format = "%s%s%s" % (processed_format,
format[:directive_index-1],
self[format_char])
if format_char == 'z':
processed_format = "%s(?:%s%s)?" % (processed_format,
format[:directive_index - 1],
self[format_char])
else:
processed_format = "%s%s%s" % (processed_format,
format[:directive_index-1],
self[format_char])
format = format[directive_index+1:]
match format_char:
case 'Y' | 'y' | 'G':
Expand Down Expand Up @@ -450,7 +455,7 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
z = found_dict['z']
if z == 'Z':
gmtoff = 0
else:
elif z is not None:
if z[3] == ':':
z = z[:3] + z[4:]
if len(z) > 5:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed it such that %z is optional
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make %z represent an optional UTC offset instead of mandating a UTC offset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate NEWS

Loading