tweak some DateParser comments

This commit is contained in:
Paul Franklin 2017-09-22 11:54:11 -07:00
parent 829a8bd01d
commit c632d0f6a9
3 changed files with 14 additions and 12 deletions

View File

@ -229,6 +229,7 @@ class DateParserHU(DateParser):
self._numeric = re.compile( self._numeric = re.compile(
"((\d+)[/\.])?\s*((\d+)[/\.])?\s*(\d+)[/\. ]?$") "((\d+)[/\.])?\s*((\d+)[/\.])?\s*(\d+)[/\. ]?$")
# this next RE has the (possibly-slashed) year at the string's start
self._text2 = re.compile('((\d+)(/\d+)?\.)?\s+?%s\.?\s*(\d+\.)?\s*$' self._text2 = re.compile('((\d+)(/\d+)?\.)?\s+?%s\.?\s*(\d+\.)?\s*$'
% self._mon_str, re.IGNORECASE) % self._mon_str, re.IGNORECASE)
_span_1 = ['-tó\\)l', '-tól', '-től'] _span_1 = ['-tó\\)l', '-tól', '-től']

View File

@ -130,6 +130,7 @@ class DateParserLT(DateParser):
def init_strings(self): def init_strings(self):
DateParser.init_strings(self) DateParser.init_strings(self)
# this next RE has the (possibly-slashed) year at the string's start
self._text2 = re.compile('((\d+)(/\d+)?)?\s+?m\.\s+%s\s*(\d+)?\s*d?\.?$' self._text2 = re.compile('((\d+)(/\d+)?)?\s+?m\.\s+%s\s*(\d+)?\s*d?\.?$'
% self._mon_str, re.IGNORECASE) % self._mon_str, re.IGNORECASE)
_span_1 = ['nuo'] _span_1 = ['nuo']

View File

@ -522,7 +522,7 @@ class DateParser:
def _parse_calendar(self, text, regex1, regex2, mmap, check=None): def _parse_calendar(self, text, regex1, regex2, mmap, check=None):
match = regex1.match(text.lower()) match = regex1.match(text.lower())
if match: # user typed in month-name day year if match: # user typed in 'month-name day year' or 'month-name year'
groups = match.groups() groups = match.groups()
if groups[0] is None: if groups[0] is None:
m = 0 m = 0
@ -535,10 +535,10 @@ class DateParser:
s = False s = False
else: else:
d = self._get_int(groups[1]) d = self._get_int(groups[1])
if groups[4] is not None: # slash year "/80" if groups[4] is not None:
y = int(groups[3]) + 1 # fullyear + 1 y = int(groups[3]) + 1 # fullyear + 1
s = True s = True # slash year
else: # regular, non-slash date else: # regular year
y = int(groups[3]) y = int(groups[3])
s = False s = False
value = (d, m, y, s) value = (d, m, y, s)
@ -561,10 +561,10 @@ class DateParser:
y = None y = None
s = False s = False
else: else:
if groups[2] is not None: # slash year digit if groups[2] is not None:
y = int(groups[1]) + 1 # fullyear + 1 y = int(groups[1]) + 1 # fullyear + 1
s = True s = True # slash year
else: # regular, non-slash year else: # regular year
y = int(groups[1]) y = int(groups[1])
s = False s = False
else: else:
@ -577,10 +577,10 @@ class DateParser:
y = None y = None
s = False s = False
else: else:
if groups[4] is not None: # slash year digit if groups[4] is not None:
y = int(groups[3]) + 1 # fullyear + 1 y = int(groups[3]) + 1 # fullyear + 1
s = True s = True # slash year
else: # regular, non-slash year else: # regular year
y = int(groups[3]) y = int(groups[3])
s = False s = False
value = (d, m, y, s) value = (d, m, y, s)
@ -621,8 +621,8 @@ class DateParser:
y = self._get_int(groups[0]) y = self._get_int(groups[0])
m = self._get_int(groups[3]) m = self._get_int(groups[3])
d = self._get_int(groups[4]) d = self._get_int(groups[4])
if groups[2] and julian_valid((d, m, y + 1)): # slash year digit if groups[2] and julian_valid((d, m, y + 1)):
return (d, m, y + 1, True) return (d, m, y + 1, True) # slash year
if check is None or check((d, m, y)): if check is None or check((d, m, y)):
return (d, m, y, False) return (d, m, y, False)
return Date.EMPTY return Date.EMPTY