Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pytimeparse/timeparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import re

SIGN = r'(?P<sign>[+|-])?'
#YEARS = r'(?P<years>\d+)\s*(?:ys?|yrs?.?|years?)'
#MONTHS = r'(?P<months>\d+)\s*(?:mos?.?|mths?.?|months?)'
YEARS = r'(?P<years>\d+)\s*(?:ys?|yrs?.?|years?)'
MONTHS = r'(?P<months>\d+)\s*(?:mos?.?|mths?.?|months?)'
WEEKS = r'(?P<weeks>[\d.]+)\s*(?:w|wks?|weeks?)'
DAYS = r'(?P<days>[\d.]+)\s*(?:d|dys?|days?)'
HOURS = r'(?P<hours>[\d.]+)\s*(?:h|hrs?|hours?)'
Expand All @@ -54,8 +54,8 @@

TIMEFORMATS = [
r'{WEEKS}\s*{DAYS}\s*{HOURS}\s*{MINS}\s*{SECS}'.format(
#YEARS=OPTSEP(YEARS),
#MONTHS=OPTSEP(MONTHS),
YEARS=OPTSEP(YEARS),
MONTHS=OPTSEP(MONTHS),
WEEKS=OPTSEP(WEEKS),
DAYS=OPTSEP(DAYS),
HOURS=OPTSEP(HOURS),
Expand All @@ -71,19 +71,19 @@
DAYCLOCK=DAYCLOCK),
r'{SECCLOCK}'.format(
SECCLOCK=SECCLOCK),
#r'{YEARS}'.format(
#YEARS=YEARS),
#r'{MONTHS}'.format(
#MONTHS=MONTHS),
r'{YEARS}'.format(
YEARS=YEARS),
r'{MONTHS}'.format(
MONTHS=MONTHS),
]

COMPILED_SIGN = re.compile(r'\s*' + SIGN + r'\s*(?P<unsigned>.*)$')
COMPILED_TIMEFORMATS = [re.compile(r'\s*' + timefmt + r'\s*$', re.I)
for timefmt in TIMEFORMATS]

MULTIPLIERS = dict([
#('years', 60 * 60 * 24 * 365),
#('months', 60 * 60 * 24 * 30),
('years', 60 * 60 * 24 * 365),
('months', 60 * 60 * 24 * 30),
('weeks', 60 * 60 * 24 * 7),
('days', 60 * 60 * 24),
('hours', 60 * 60),
Expand All @@ -106,8 +106,8 @@ def _interpret_as_minutes(sval, mdict):
and (('hours' not in mdict) or (mdict['hours'] is None))
and (('days' not in mdict) or (mdict['days'] is None))
and (('weeks' not in mdict) or (mdict['weeks'] is None))
#and (('months' not in mdict) or (mdict['months'] is None))
#and (('years' not in mdict) or (mdict['years'] is None))
and (('months' not in mdict) or (mdict['months'] is None))
and (('years' not in mdict) or (mdict['years'] is None))
):
mdict['hours'] = mdict['mins']
mdict['mins'] = mdict['secs']
Expand Down