mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 21:11:16 +00:00
naturalday_partial: simplify/refactor
This commit is contained in:
parent
0d908b594c
commit
4711b3bc19
1 changed files with 6 additions and 14 deletions
|
@ -15,18 +15,10 @@ def naturalday_partial(date, arg=None):
|
||||||
If arg is a Django-defined format such as "DATE_FORMAT", it will be adjusted
|
If arg is a Django-defined format such as "DATE_FORMAT", it will be adjusted
|
||||||
so that the precision of the PartialDate object is honored.
|
so that the precision of the PartialDate object is honored.
|
||||||
"""
|
"""
|
||||||
django_formats = ("DATE_FORMAT", "SHORT_DATE_FORMAT", "YEAR_MONTH_FORMAT")
|
if not isinstance(date, PartialDate) or date.has_day:
|
||||||
if not isinstance(date, PartialDate):
|
|
||||||
return naturalday(date, arg)
|
return naturalday(date, arg)
|
||||||
if arg is None:
|
if not arg or arg == "DATE_FORMAT":
|
||||||
arg = "DATE_FORMAT"
|
arg = "YEAR_MONTH_FORMAT" if date.has_month else "Y"
|
||||||
if date.has_day:
|
elif not date.has_month and arg in ("SHORT_DATE_FORMAT", "YEAR_MONTH_FORMAT"):
|
||||||
fmt = arg
|
arg = "Y"
|
||||||
elif date.has_month:
|
return defaultfilters.date(date, arg)
|
||||||
# there is no SHORT_YEAR_MONTH_FORMAT, so we ignore SHORT_DATE_FORMAT :(
|
|
||||||
fmt = "YEAR_MONTH_FORMAT" if arg == "DATE_FORMAT" else arg
|
|
||||||
else:
|
|
||||||
fmt = "Y" if arg in django_formats else arg
|
|
||||||
if date.has_day:
|
|
||||||
return naturalday(date, fmt)
|
|
||||||
return defaultfilters.date(date, fmt)
|
|
||||||
|
|
Loading…
Reference in a new issue