Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kirill Smelkov
cpython
Commits
490602d6
You need to sign in or sign up before continuing.
Commit
490602d6
authored
22 years ago
by
Neal Norwitz
Browse files
Options
Download
Email Patches
Plain Diff
Fix julian day problem with strptime. Note: XXX about using 0, suggestions?
parent
4c0db788
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
Lib/_strptime.py
Lib/_strptime.py
+3
-1
Lib/test/test_strptime.py
Lib/test/test_strptime.py
+12
-0
No files found.
Lib/_strptime.py
View file @
490602d6
...
...
@@ -306,12 +306,14 @@ class TimeRE(dict):
def
__init__
(
self
,
locale_time
=
LocaleTime
()):
"""Init inst with non-locale regexes and store LocaleTime object."""
# XXX: should 0 be valid for:
# day (d), julian day (j), month (m), and hour12 (I)?
super
(
TimeRE
,
self
).
__init__
({
# The " \d" option is to make %c from ANSI C work
'd'
:
r
"(?P<d>3[0-1]|[0-2]\d|\d| \d)"
,
'H'
:
r
"(?P<H>2[0-3]|[0-1]\d|\d)"
,
'I'
:
r
"(?P<I>0\d|1[0-2]|\d)"
,
'j'
:
r
"(?P<j>(?:3[0-5]\d|6[0-6])|[0-2]\d\d|\d)"
,
'j'
:
r
"(?P<j>(?:3[0-5]\d|
3
6[0-6])|[0-2]\d\d|\d
\d|\d
)"
,
'm'
:
r
"(?P<m>0\d|1[0-2]|\d)"
,
'M'
:
r
"(?P<M>[0-5]\d|\d)"
,
'S'
:
r
"(?P<S>6[0-1]|[0-5]\d|\d)"
,
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_strptime.py
View file @
490602d6
...
...
@@ -379,6 +379,17 @@ class Strptime12AMPMTests(unittest.TestCase):
eq
(
_strptime
.
strptime
(
'12 AM'
,
'%I %p'
)[
3
],
0
)
class
JulianTests
(
unittest
.
TestCase
):
"""Test a _strptime regression that all julian (1-366) are accepted"""
def
test_all_julian_days
(
self
):
eq
=
self
.
assertEqual
# XXX: should 0 be accepted?
for
i
in
range
(
1
,
367
):
# use 2004, since it is a leap year, we have 366 days
eq
(
_strptime
.
strptime
(
'%d 2004'
%
i
,
'%j %Y'
)[
7
],
i
)
def
test_main
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
LocaleTime_Tests
))
...
...
@@ -386,6 +397,7 @@ def test_main():
suite
.
addTest
(
unittest
.
makeSuite
(
StrptimeTests
))
suite
.
addTest
(
unittest
.
makeSuite
(
FxnTests
))
suite
.
addTest
(
unittest
.
makeSuite
(
Strptime12AMPMTests
))
suite
.
addTest
(
unittest
.
makeSuite
(
JulianTests
))
test_support
.
run_suite
(
suite
)
...
...
This diff is collapsed.
Click to expand it.
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