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

astimezone doesn't look to take the given timezone #330

Open
svaningelgem opened this issue Feb 25, 2023 · 0 comments
Open

astimezone doesn't look to take the given timezone #330

svaningelgem opened this issue Feb 25, 2023 · 0 comments

Comments

@svaningelgem
Copy link

Python Version

3.9.13

pytest Version

7.1.2

Package Version

2.9.0

Description

from datetime import date, datetime, time, timezone

import time_machine


with time_machine.travel(datetime(2023, 2, 16, 7, 44, 0, tzinfo=timezone.utc)):
    now = datetime.combine(date.today(), time.min)  # For example 2023-02-16 00:00:00, but no timezone yet
    now = now.astimezone()  # Local timezone
    now_utc = now.astimezone(timezone.utc)
    assert now_utc.timestamp() == 1676505600, f'TS is said to be {now_utc.timestamp()}'

In this example on my computer (GMT+1) this fails.
I think the reason is because astimezone will bypass the time-machine and go to the system time to get the current timezone information. Instead of taking that from the mock?

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