Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dateutil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
dateutil
Commits
7b95e1210409
Commit
7b95e1210409
authored
7 years ago
by
Paul Ganssle
Browse files
Options
Downloads
Plain Diff
Merge pull request #700 from jbrockmendel/687
Fix for B.Y.d format corner case #687
parents
88a6caafead2
6b0fc9b73d6a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/687.bugfix.rst
+1
-0
1 addition, 0 deletions
changelog.d/687.bugfix.rst
dateutil/parser/_parser.py
+35
-4
35 additions, 4 deletions
dateutil/parser/_parser.py
dateutil/test/test_parser.py
+6
-0
6 additions, 0 deletions
dateutil/test/test_parser.py
with
42 additions
and
4 deletions
changelog.d/687.bugfix.rst
0 → 100644
+
1
−
0
View file @
7b95e121
Fixed incorrect parsing of certain dates earlier than 100 AD when repesented in the form "%B.%Y.%d", e.g. "December.0031.30". (gh issue #687, pr #700)
This diff is collapsed.
Click to expand it.
dateutil/parser/_parser.py
+
35
−
4
View file @
7b95e121
...
...
@@ -458,7 +458,25 @@
raise
ValueError
(
'
Year is already set
'
)
self
.
ystridx
=
len
(
self
)
-
1
def
_resolve_from_stridxs
(
self
,
strids
):
"""
Try to resolve the identities of year/month/day elements using
ystridx, mstridx, and dstridx, if enough of these are specified.
"""
if
len
(
self
)
==
3
and
len
(
strids
)
==
2
:
# we can back out the remaining stridx value
missing
=
[
x
for
x
in
range
(
3
)
if
x
not
in
strids
.
values
()]
key
=
[
x
for
x
in
[
'
y
'
,
'
m
'
,
'
d
'
]
if
x
not
in
strids
]
assert
len
(
missing
)
==
len
(
key
)
==
1
key
=
key
[
0
]
val
=
missing
[
0
]
strids
[
key
]
=
val
assert
len
(
self
)
==
len
(
strids
)
# otherwise this should not be called
out
=
{
key
:
self
[
strids
[
key
]]
for
key
in
strids
}
return
(
out
.
get
(
'
y
'
),
out
.
get
(
'
m
'
),
out
.
get
(
'
d
'
))
def
resolve_ymd
(
self
,
yearfirst
,
dayfirst
):
len_ymd
=
len
(
self
)
year
,
month
,
day
=
(
None
,
None
,
None
)
...
...
@@ -461,7 +479,16 @@
def
resolve_ymd
(
self
,
yearfirst
,
dayfirst
):
len_ymd
=
len
(
self
)
year
,
month
,
day
=
(
None
,
None
,
None
)
strids
=
((
'
y
'
,
self
.
ystridx
),
(
'
m
'
,
self
.
mstridx
),
(
'
d
'
,
self
.
dstridx
))
strids
=
{
key
:
val
for
key
,
val
in
strids
if
val
is
not
None
}
if
(
len
(
self
)
==
len
(
strids
)
>
0
or
(
len
(
self
)
==
3
and
len
(
strids
)
==
2
)):
return
self
.
_resolve_from_stridxs
(
strids
)
mstridx
=
self
.
mstridx
if
len_ymd
>
3
:
...
...
@@ -470,6 +497,10 @@
# One member, or two members with a month string
if
mstridx
is
not
None
:
month
=
self
[
mstridx
]
del
self
[
mstridx
]
# since mstridx is 0 or 1, self[mstridx-1] always
# looks up the other element
other
=
self
[
mstridx
-
1
]
else
:
other
=
self
[
0
]
if
len_ymd
>
1
or
mstridx
is
None
:
...
...
@@ -474,5 +505,5 @@
if
len_ymd
>
1
or
mstridx
is
None
:
if
self
[
0
]
>
31
:
year
=
self
[
0
]
if
other
>
31
:
year
=
other
else
:
...
...
@@ -478,5 +509,5 @@
else
:
day
=
self
[
0
]
day
=
other
elif
len_ymd
==
2
:
# Two members with numbers
...
...
This diff is collapsed.
Click to expand it.
dateutil/test/test_parser.py
+
6
−
0
View file @
7b95e121
...
...
@@ -1106,3 +1106,9 @@
# constructed with an invalid value
with
pytest
.
raises
(
ValueError
):
parse
(
value
)
def
test_BYd_corner_case
():
# GH#687
res
=
parse
(
'
December.0031.30
'
)
assert
res
==
datetime
(
31
,
12
,
30
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment