def _parse_date(date_els):
if len(date_els) == 2:
# assumed to be year-month or month-year
a, b = date_els
if _is_year(a):
date_vals = a, b, 1 # 1st of month assumed
elif _is_year(b):
date_vals = b, a, 1 # 1st of month assumed
else:
date_vals = arrow.now().year, a, b # assumed M/D of this year
elif len(date_els) == 3:
# assumed to be year-month-day or month-day-year
a, b, c = date_els
if _is_year(a):
date_vals = a, b, c
elif _is_year(c):
date_vals = c, a, b
else:
raise ValueError("Date '{}' can't be understood".format(date_els))
else:
raise ValueError("Date '{}' can't be understood".format(date_els))
return map(int, date_vals)
评论列表
文章目录