Skip to content

Commit 4dddf14

Browse files
committed
Added support for ISO-format dates (or RFC 3339 dates, if you will) to the date parsing done for the submission tool. Also refined the regexes a bit to avoid false matches on for instance things like 'Juniper 2014'.
- Legacy-Id: 8501
1 parent 9d5a9c1 commit 4dddf14

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

ietf/utils/draft.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import sys
4141
import time
4242

43-
version = "0.31"
43+
version = "0.33"
4444
program = os.path.basename(sys.argv[0])
4545
progdir = os.path.dirname(sys.argv[0])
4646

@@ -75,7 +75,10 @@
7575
}
7676
longform = dict([ (short+" ", longform[short]+" ") for short in longform ])
7777

78-
month_names = [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ]
78+
79+
month_names = [ 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december' ]
80+
month_names_abbrev3 = [ n[:3] for n in month_names ]
81+
month_names_abbrev4 = [ n[:4] for n in month_names ]
7982

8083
# ----------------------------------------------------------------------
8184
# Functions
@@ -304,15 +307,17 @@ def get_creation_date(self):
304307
if self._creation_date:
305308
return self._creation_date
306309
date_regexes = [
307-
r'^(?P<month>\w+)\s+(?P<day>\d{1,2})(,|\s)+(?P<year>\d{4})',
308-
r'^(?P<day>\d{1,2})(,|\s)+(?P<month>\w+)\s+(?P<year>\d{4})',
310+
r'^(?P<month>\w+)\s(?P<day>\d{1,2})(,|\s)+(?P<year>\d{4})',
311+
r'^(?P<day>\d{1,2})(,|\s)+(?P<month>\w+)\s(?P<year>\d{4})',
309312
r'^(?P<day>\d{1,2})-(?P<month>\w+)-(?P<year>\d{4})',
310-
r'^(?P<month>\w+)\s+(?P<year>\d{4})',
311-
r'\s{3,}(?P<month>\w+)\s+(?P<day>\d{1,2})(,|\s)+(?P<year>\d{4})',
312-
r'\s{3,}(?P<day>\d{1,2})(,|\s)+(?P<month>\w+)\s+(?P<year>\d{4})',
313+
r'^(?P<month>\w+)\s(?P<year>\d{4})',
314+
r'\s{3,}(?P<month>\w+)\s(?P<day>\d{1,2})(,|\s)+(?P<year>\d{4})',
315+
r'\s{3,}(?P<day>\d{1,2})(,|\s)+(?P<month>\w+)\s(?P<year>\d{4})',
313316
r'\s{3,}(?P<day>\d{1,2})-(?P<month>\w+)-(?P<year>\d{4})',
317+
# RFC 3339 date (also ISO date)
318+
r'\s{3,}(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})',
314319
# 'October 2008' - default day to today's.
315-
r'\s{3,}(?P<month>\w+)\s+(?P<year>\d{4})',
320+
r'\s{3,}(?P<month>\w+)\s(?P<year>\d{4})',
316321
]
317322

318323
dates = []
@@ -326,11 +331,20 @@ def get_creation_date(self):
326331
dates.sort()
327332
for start, match in dates:
328333
md = match.groupdict()
329-
mon = md['month'][0:3].lower()
334+
mon = md['month'].lower()
330335
day = int( md.get( 'day', 0 ) )
331336
year = int( md['year'] )
332337
try:
333-
month = month_names.index( mon ) + 1
338+
if mon in month_names:
339+
month = month_names.index( mon ) + 1
340+
elif mon in month_names_abbrev3:
341+
month = month_names_abbrev3.index( mon ) + 1
342+
elif mon in month_names_abbrev4:
343+
month = month_names_abbrev4.index( mon ) + 1
344+
elif mon.isdigit() and int(mon) in range(1,13):
345+
month = mon
346+
else:
347+
continue
334348
today = datetime.date.today()
335349
if day==0:
336350
# if the date was given with only month and year, use
@@ -1079,7 +1093,7 @@ def getmeta(fn):
10791093
fields["docaffiliations"] = ", ".join(draft.get_authors_with_firm())
10801094
if opt_debug:
10811095
fields["docheader"] = draft._docheader
1082-
normrefs, rfcrefs, draftrefs, refs = draft.get_refs()
1096+
normrefs, rfcrefs, draftrefs, refs = draft.old_get_refs()
10831097
fields["docrfcrefs"] = ", ".join(rfcrefs)
10841098
fields["docdraftrefs"] = ", ".join(draftrefs)
10851099
fields["doccreationdate"] = str(draft.get_creation_date())

0 commit comments

Comments
 (0)