Files
pretix_cgo/src/pretix/helpers/daterange.py
scabux 1b2895b0ca Fixed bugs and added test for date range rendering (#488)
* fixed bug for same dates, added unit check for daterange

* fixed local language override in unit test
2017-05-07 10:40:36 +02:00

26 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.template.defaultfilters import date as _date
from django.utils.translation import get_language, ugettext_lazy as _
def daterange(df, dt):
lng = get_language()
if lng.startswith("de"):
if df.year == dt.year and df.month == dt.month and df.day == dt.day:
return "{}".format(_date(df, "j. F Y"))
elif df.year == dt.year and df.month == dt.month:
return "{}.{}".format(_date(df, "j"), _date(dt, "j. F Y"))
elif df.year == dt.year:
return "{} {}".format(_date(df, "j. F"), _date(dt, "j. F Y"))
elif lng.startswith("en"):
if df.year == dt.year and df.month == dt.month and df.day == dt.day:
return "{}".format(_date(df, "N jS, Y"))
elif df.year == dt.year and df.month == dt.month:
return "{} {}".format(_date(df, "N jS"), _date(dt, "jS, Y"))
elif df.year == dt.year:
return "{} {}".format(_date(df, "N jS"), _date(dt, "N jS, Y"))
return _("{date_from} {date_to}").format(
date_from=_date(df, "DATE_FORMAT"), date_to=_date(dt, "DATE_FORMAT")
)