Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b90252ed
Commit
b90252ed
authored
May 14, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Followup to issue #14157: respect the relative ordering of values produced by time.strptime().
Patch by Hynek.
parent
e7f67b5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
Lib/_strptime.py
Lib/_strptime.py
+8
-0
Lib/test/test_strptime.py
Lib/test/test_strptime.py
+5
-0
No files found.
Lib/_strptime.py
View file @
b90252ed
...
@@ -426,8 +426,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
...
@@ -426,8 +426,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
else
:
else
:
tz
=
value
tz
=
value
break
break
leap_year_fix
=
False
if
year
is
None
and
month
==
2
and
day
==
29
:
if
year
is
None
and
month
==
2
and
day
==
29
:
year
=
1904
# 1904 is first leap year of 20th century
year
=
1904
# 1904 is first leap year of 20th century
leap_year_fix
=
True
elif
year
is
None
:
elif
year
is
None
:
year
=
1900
year
=
1900
# If we know the week of the year and what day of that week, we can figure
# If we know the week of the year and what day of that week, we can figure
...
@@ -451,6 +453,12 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
...
@@ -451,6 +453,12 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
day
=
datetime_result
.
day
day
=
datetime_result
.
day
if
weekday
==
-
1
:
if
weekday
==
-
1
:
weekday
=
datetime_date
(
year
,
month
,
day
).
weekday
()
weekday
=
datetime_date
(
year
,
month
,
day
).
weekday
()
if
leap_year_fix
:
# the caller didn't supply a year but asked for Feb 29th. We couldn't
# use the default of 1900 for computations. We set it back to ensure
# that February 29th is smaller than March 1st.
year
=
1900
return
(
time
.
struct_time
((
year
,
month
,
day
,
return
(
time
.
struct_time
((
year
,
month
,
day
,
hour
,
minute
,
second
,
hour
,
minute
,
second
,
weekday
,
julian
,
tz
)),
fraction
)
weekday
,
julian
,
tz
)),
fraction
)
...
...
Lib/test/test_strptime.py
View file @
b90252ed
...
@@ -381,6 +381,11 @@ class StrptimeTests(unittest.TestCase):
...
@@ -381,6 +381,11 @@ class StrptimeTests(unittest.TestCase):
def test_feb29_on_leap_year_without_year(self):
def test_feb29_on_leap_year_without_year(self):
time.strptime("
Feb
29
", "
%
b
%
d
")
time.strptime("
Feb
29
", "
%
b
%
d
")
def test_mar1_comes_after_feb29_even_when_omitting_the_year(self):
self.assertLess(
time.strptime("
Feb
29
", "
%
b
%
d
"),
time.strptime("
Mar
1
", "
%
b
%
d
"))
class Strptime12AMPMTests(unittest.TestCase):
class Strptime12AMPMTests(unittest.TestCase):
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment