Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
2fcbf674
Commit
2fcbf674
authored
Mar 28, 2018
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better date parsing
parent
249469c3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
4 deletions
+14
-4
dates.py
gargantext/utils/dates.py
+14
-4
No files found.
gargantext/utils/dates.py
View file @
2fcbf674
...
...
@@ -45,6 +45,7 @@ SEASONS_ABBR = {k[:3]: v for k, v in SEASONS.items()}
_RE_SEASON
=
re
.
compile
(
r'\b(
%
s)\b'
%
'|'
.
join
(
SEASONS
.
keys
()),
re
.
I
)
_RE_SEASON_ABBR
=
re
.
compile
(
r'\b(
%
s)\b'
%
'|'
.
join
(
SEASONS_ABBR
.
keys
()),
re
.
I
)
_RE_SLASHES
=
re
.
compile
(
r'//+'
)
class
datetime
(
_datetime
):
...
...
@@ -64,6 +65,12 @@ class datetime(_datetime):
for
r
,
table
in
seasons
:
s
=
r
.
sub
(
lambda
m
:
'
%0.2
d'
%
table
[
m
.
group
(
1
)
.
lower
()],
s
,
count
=
1
)
# To parse partial RIS dates (eg. 2018/4//)
s
=
_RE_SLASHES
.
sub
(
'/'
,
s
)
.
strip
(
' /'
)
if
not
s
:
return
default
try
:
# Try to parse first with Django parser utility, then with dateutil
dt
=
parse_datetime
(
s
)
or
\
...
...
@@ -74,10 +81,13 @@ class datetime(_datetime):
except
ValueError
:
# Second chance...
# For date intervals try taking first part only (eg. 2018-04 for
# "2018 Apr-May")
if
'-'
in
s
:
return
datetime
.
parse
(
s
.
split
(
'-'
,
1
)[
0
])
# This may be a date interval, try taking first part only
# eg. 2018-04 for "2018 Apr-May"
for
sep
in
(
'-'
,
'/'
,
None
):
if
sep
in
s
or
not
sep
:
break
if
sep
:
return
datetime
.
parse
(
s
.
split
(
sep
,
1
)[
0
])
# Otherwise, just fail
raise
...
...
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