From 97264ac3ffad554d1169efad643675b9eb83566f Mon Sep 17 00:00:00 2001 From: Andy Byers Date: Tue, 31 Mar 2026 14:08:24 +0100 Subject: [PATCH] fix: auto-detect browser timezone for admin users and show active timezone on accept form (#3392) --- src/repository/tests/test_views.py | 30 +++++++++++++++++++ src/templates/admin/core/base.html | 2 ++ .../elements/repository/accept_preprint.html | 2 ++ 3 files changed, 34 insertions(+) diff --git a/src/repository/tests/test_views.py b/src/repository/tests/test_views.py index b3f88c0fc7..e8ee7b31ac 100644 --- a/src/repository/tests/test_views.py +++ b/src/repository/tests/test_views.py @@ -305,6 +305,36 @@ def test_accept_preprint(self): FROZEN_DATETIME.timestamp(), ) + @override_settings(URL_CONFIG="domain") + @freeze_time(FROZEN_DATETIME) + def test_accept_preprint_with_user_timezone(self): + # Regression for #3392: when a user's preferred_timezone is set, + # date_published should be correctly converted to UTC and not end up + # in the future relative to the server. + self.preprint_one.make_new_version(self.preprint_one.submission_file) + path = reverse( + "repository_manager_article", + kwargs={"preprint_id": self.preprint_one.pk}, + ) + self.client.force_login(self.repo_manager) + # User is in Asia/Karachi (UTC+5). FROZEN_DATETIME is 15:00 UTC, + # so their local time is 20:00. They submit their local time with + # their correct timezone — date_published should equal FROZEN_DATETIME. + self.client.post( + path, + data={ + "accept": "", + "datetime": "2024-03-25T20:00", + "timezone": "Asia/Karachi", + }, + SERVER_NAME=self.server_name, + ) + preprint = rm.Preprint.objects.get(pk=self.preprint_one.pk) + self.assertEqual( + preprint.date_published.timestamp(), + FROZEN_DATETIME.timestamp(), + ) + @override_settings(URL_CONFIG="domain") @freeze_time(FROZEN_DATETIME, tz_offset=5) def test_accept_preprint_bad_date(self): diff --git a/src/templates/admin/core/base.html b/src/templates/admin/core/base.html index 1ce4e10982..5bea4abac4 100644 --- a/src/templates/admin/core/base.html +++ b/src/templates/admin/core/base.html @@ -120,6 +120,8 @@

{% block title-section %}{% endblock %}

{% endblock toastr %} {% include "admin/core/partials/htmx_messages.html" %} {% include "admin/core/partials/htmx_spinner.html" %} + +{% if not request.timezone %}{% endif %} {% block js %}{% endblock %} diff --git a/src/templates/admin/elements/repository/accept_preprint.html b/src/templates/admin/elements/repository/accept_preprint.html index d16a55a36c..0c37aedf87 100644 --- a/src/templates/admin/elements/repository/accept_preprint.html +++ b/src/templates/admin/elements/repository/accept_preprint.html @@ -25,6 +25,8 @@

{% get_current_timezone as TIME_ZONE %} +

Your Janeway timezone is set to {{ TIME_ZONE }}. + {% if not request.user.preferred_timezone %}You can set your preferred timezone in your profile.{% endif %}