Skip to content

Could have some problem with Django with TIME_ZONE setting #545

@JimmyHaveAHamster

Description

@JimmyHaveAHamster

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions