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

Could have some problem with Django with TIME_ZONE setting #545

Open
holisHsu opened this issue Apr 24, 2024 · 0 comments
Open

Could have some problem with Django with TIME_ZONE setting #545

holisHsu opened this issue Apr 24, 2024 · 0 comments

Comments

@holisHsu
Copy link

holisHsu commented Apr 24, 2024

For Django porject which TIME_ZONE is not UTC (Ex: In my case "Asia/Taipei")

freeze_time would face problem in some scenario

CleanShot 2024-04-24 at 11 09 57@2x

Case 1: @freeze_time(datetime(2024, 1, 1))

We will get timezone.now() == datetime(2024, 1, 1, 1, tzinfo=timezone.utc)
But timezone.now() return UTC time so I should get 2023/12/31 instead

Case 2: @freeze_time(datetime(2024, 1, 1, 0, 0, 0, tzinfo=pytz.timezone("Asia/Taipei")))

We will get datetime.now() == datetime(2023, 12, 31, 15, 54)
But datetime.now() return "Asia/Taipei" in this case so we should get 2024/01/01 instead

It may not the problem can be solve in freeze_gun

I think the case might happen if freeze_gun have no way to know django is going to change the
TIME_ZONE or impose something to datetime, in this case we might consider to close the issue directly, many thanks !

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

No branches or pull requests

1 participant