Manually strf birthdays so years are not .strip("0")ed

This commit is contained in:
jesopo 2019-06-19 11:06:26 +01:00
parent 938e1db963
commit 9407e083bd

View file

@ -18,9 +18,18 @@ def _parse(s):
return True, datetime.datetime.strptime(s, DATE_YEAR_FORMAT) return True, datetime.datetime.strptime(s, DATE_YEAR_FORMAT)
except ValueError: except ValueError:
return None return None
def _format_year(dt):
return "%s-%s-%s" % (str(dt.year).zfill(4), str(dt.month).zfill(2),
str(dt.day).zfill(2))
def _format_noyear(dt):
return datetime.datetime.strftime(dt, DATE_FORMAT)
def _format(years, dt): def _format(years, dt):
return datetime.datetime.strftime(dt, if years:
DATE_YEAR_FORMAT if years else DATE_FORMAT) return _format_year(dt)
else:
return _format_noyear(dt)
def _check(s): def _check(s):
parsed = _parse(s) parsed = _parse(s)
if parsed: if parsed: