-
Notifications
You must be signed in to change notification settings - Fork 37
Add TIME_ZONE
as .env variable
#6817
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for configuring the Django TIME_ZONE
via an environment variable, with a fallback default.
- Read
TIME_ZONE
from the environment insettings/__init__.py
. - Expose
TIME_ZONE
in the generatedlocal_specify_settings.py
via the Dockerfile.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
specifyweb/settings/init.py | Changed TIME_ZONE to be loaded from os.environ.get |
Dockerfile | Added TIME_ZONE assignment in local_specify_settings.py |
Comments suppressed due to low confidence (2)
specifyweb/settings/init.py:87
- Consider updating the comment above this line to note that
TIME_ZONE
is now configurable via theTIME_ZONE
environment variable.
TIME_ZONE = os.environ.get('TIME_ZONE', 'America/Chicago')
specifyweb/settings/init.py:87
- Add a test to verify that
settings.TIME_ZONE
correctly reflects theTIME_ZONE
environment variable to prevent regression.
TIME_ZONE = os.environ.get('TIME_ZONE', 'America/Chicago')
Co-authored-by: Copilot <[email protected]>
TIME_ZONE
as env variableTIME_ZONE
as .env variable
I spoke to @CarolineDenis while she was testing this: There is currently some confusion between the time zones displayed in the application:
I'll look at solving this within this PR, but might need to be a new issue. |
In response to the earlier issues:
I found that I could simply adjust the Before: "Thursday, December 2, 2021 at 1:24:40 PM CDT" (shows browser timezone)
As for the other points, we might want to expose the time zone set in the environment to the
|
Triggered by 07bb2a8 on branch refs/heads/issue-641-time
Before: "Thursday, December 2, 2021 at 1:24:40 PM CDT" (shows browser timezone) After: "Thursday, December 2, 2021 at 1:24:40 PM" (no timezone shown)
…into issue-641-time
Fixes #641
This approach does not set
USE_TZ
toTrue
(docs), meaning Django will use naive datetimes in local time. See the following behavioral difference:specify@9ce63bab5807:/opt/specify7$ ve/bin/python manage.py shell -c "from django.conf import settings; print(settings.USE_TZ)" False
timezone.now()
This means we are assuming all data and users will be in the same timezone. However, we still face challenges with daylight saving time (DST) and cross-zone consistency. Since we have set the timezone to
America/Chicago
for all users and it is uncommon to have users from different time zones, this is a first step toward improving timezone support.In the future, we should support
USE_TZ
, but this should be done first to give users more choice for now. The reason I am not using this approach here is because of some roadblocks that require further development to resolve. @melton-jason describes the issue with his fix in this comment: #641 (comment), see his branch hereTODO: See #6818
Testing instructions
TIME_ZONE
variable in the.env
file to one from this list: https://en.wikipedia.org/wiki/List_of_tz_zones_by_nameTimestampCreated
andTimestampModified
for various records, such as