mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Fix when parsing tz offsets microseconds shorter than 6 (#4781)
As the remainder was directly parsed as an int, strings like .600 were parsed as 600 microseconds rather than milliseconds.
This commit is contained in:
parent
d4864c61e3
commit
f80c0ca133
2 changed files with 7 additions and 1 deletions
|
@ -470,7 +470,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
|
|||
minutes = int(z[3:5])
|
||||
seconds = int(z[5:7] or 0)
|
||||
gmtoff = (hours * 60 * 60) + (minutes * 60) + seconds
|
||||
gmtoff_fraction = int(z[8:] or 0)
|
||||
gmtoff_remainder = z[8:]
|
||||
# Pad to always return microseconds.
|
||||
gmtoff_remainder_padding = "0" * (6 - len(gmtoff_remainder))
|
||||
gmtoff_fraction = int(gmtoff_remainder + gmtoff_remainder_padding)
|
||||
if z.startswith("-"):
|
||||
gmtoff = -gmtoff
|
||||
gmtoff_fraction = -gmtoff_fraction
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue