Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2276 #2277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
3 changes: 2 additions & 1 deletion judge/jinja2/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.templatetags.tz import localtime
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils import timezone
from django.utils.timezone import utc
from django.utils.translation import gettext as _

Expand All @@ -26,7 +27,7 @@ def wrapper(datetime, *args, **kwargs):

@registry.function
def relative_time(time, **kwargs):
abs_time = date(time, kwargs.get('format', _('N j, Y, g:i a')))
abs_time = date(time.astimezone(timezone.get_current_timezone()), kwargs.get('format', _('N j, Y, g:i a')))
Copy link
Member

Choose a reason for hiding this comment

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

Does this work when the user is logged out? Ideally, we should use the browser's timezone when they are logged out.

Copy link
Author

@61izzy 61izzy Aug 23, 2023

Choose a reason for hiding this comment

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

Yeah, seems to work when I run it locally.

Edit: Nvm, seems to use DEFAULT_USER_TIME_ZONE in settings.py

Copy link
Author

Choose a reason for hiding this comment

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

I think that might have to be fixed separately in timezone.py

Copy link
Author

Choose a reason for hiding this comment

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

Is there a way for timezone.py to access the value of Intl.DateTimeFormat().resolvedOptions().timeZone? I've tried making a few changes other in timezone.py, but nothing worked.

return mark_safe(f'<span data-iso="{time.astimezone(utc).isoformat()}" class="time-with-rel"'
f' title="{escape(abs_time)}" data-format="{escape(kwargs.get("rel", _("{time}")))}">'
f'{escape(kwargs.get("abs", _("on {time}")).replace("{time}", abs_time))}</span>')