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

Use current timezone instead of default #114

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

rwlogel
Copy link
Contributor

@rwlogel rwlogel commented Feb 7, 2024

If the timezone is set using this approach from the Django docs then it should be using the current timezone not the default one.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b4f6c29) 87.45% compared to head (94a5570) 87.45%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #114   +/-   ##
=======================================
  Coverage   87.45%   87.45%           
=======================================
  Files           9        9           
  Lines         606      606           
=======================================
  Hits          530      530           
  Misses         76       76           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@silentsokolov
Copy link
Owner

Are you sure that it works correct for the django-admin <-> model time fields?

@rwlogel
Copy link
Contributor Author

rwlogel commented Feb 8, 2024

I verified it in our project which has implemented the admin timezone switching feature as outlined in the Django documentation which I linked in the description.

A simple way to see it in action would be to use a middleware that locks the timezone:

class AdminTimezoneMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        if request.path.startswith('/admin/'):
            with timezone.override(ZoneInfo('America/New_York')):
                return self.get_response(request)

        return self.get_response(request)

With this middleware all the datetimes shown use the wrapped timezone, except the ones generated by the filter which are always UTC because that is the default timezone, not the active one.

@silentsokolov
Copy link
Owner

Checked.
Thanks you

@silentsokolov silentsokolov merged commit daf0a5b into silentsokolov:master Feb 8, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants