Skip to content
Open
Changes from 2 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
63 changes: 35 additions & 28 deletions kitsune/sumo/templatetags/jinja_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,34 +278,41 @@ def datetimeformat(context, value, format="shortdatetime", use_naturaltime=False
if use_naturaltime and (django_now().astimezone(convert_tzinfo) - convert_value).days < 30:
return naturaltime(convert_value)

if format == "shortdatetime" or format == "shortdate":
# Check if the date is today
today = datetime.datetime.now(tz=convert_tzinfo).toordinal()
kwargs = {"format": "short", "tzinfo": convert_tzinfo, "locale": locale}
if convert_value.toordinal() == today:
formatted = _lazy("Today at %s") % format_time(convert_value, **kwargs)
elif format == "shortdatetime":
formatted = format_datetime(convert_value, **kwargs)
else:
del kwargs["tzinfo"]
formatted = format_date(convert_value, **kwargs)
elif format == "longdatetime":
formatted = format_datetime(
convert_value, format="long", tzinfo=convert_tzinfo, locale=locale
)
elif format == "date":
formatted = format_date(convert_value, locale=locale)
elif format == "time":
formatted = format_time(convert_value, tzinfo=convert_tzinfo, locale=locale)
elif format == "datetime":
formatted = format_datetime(convert_value, tzinfo=convert_tzinfo, locale=locale)
elif format == "year":
formatted = format_datetime(
convert_value, format="yyyy", tzinfo=convert_tzinfo, locale=locale
)
else:
# Unknown format
raise DateTimeFormatError
match format:
case "shortdatetime" | "shortdate":
# Check if the date is today
today = datetime.datetime.now(tz=convert_tzinfo).toordinal()
kwargs = {"format": "short", "tzinfo": convert_tzinfo, "locale": locale}
if convert_value.toordinal() == today:
formatted = _lazy("Today at %s") % format_time(convert_value, **kwargs)
elif format == "shortdatetime":
formatted = format_datetime(convert_value, **kwargs)
else:
del kwargs["tzinfo"]
formatted = format_date(convert_value, **kwargs)

case "longdatetime":
formatted = format_datetime(
convert_value, format="long", tzinfo=convert_tzinfo, locale=locale
)

case "date":
formatted = format_date(convert_value, locale=locale)

case "time":
formatted = format_time(convert_value, tzinfo=convert_tzinfo, locale=locale)

case "datetime":
formatted = format_datetime(convert_value, tzinfo=convert_tzinfo, locale=locale)

case "year":
formatted = format_datetime(
convert_value, format="yyyy", tzinfo=convert_tzinfo, locale=locale
)
case _:
# Unknown format
raise DateTimeFormatError


Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line added. While not a functional issue, this adds unnecessary whitespace. Consider removing this blank line to maintain consistency with the other case branches (lines 298, 301, 304, 307) which don't have trailing blank lines.

Suggested change

Copilot uses AI. Check for mistakes.
return Markup('<time datetime="{}">{}</time>'.format(convert_value.isoformat(), formatted))

Expand Down
Loading