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

Aware Datetime Support #487

Open
henrycjc opened this issue Jan 24, 2023 · 0 comments
Open

Aware Datetime Support #487

henrycjc opened this issue Jan 24, 2023 · 0 comments

Comments

@henrycjc
Copy link

Feature request I suppose, but also looking for guidance. Consider this snippet below where the first test is failing.

I would have expected freezegun to interpret the timezone stored in the datetime object and apply this as a 'tz_offset'.
This is not the case.

If it would be acceptable, I'd happily update the documentation with a pull request that this is not intended behaviour, and users should provide the tz_offset kwarg to achieve this. Alternatively, could this feature be added?

I am using pytest:

import pytz
import datetime as dt

TZ = pytz.timezone("Australia/Brisbane")
DT = dt.datetime(2019, 12, 25)


class TestFreezeGun:
    @freezegun.freeze_time(TZ.localize(dt.datetime(2019, 12, 25)))
    def test_freezegun_no_offset_TEST_FAILS(self):
        assert TZ.localize(dt.datetime.now()) == TZ.localize(dt.datetime(2019, 12, 25)) # fails

    @freezegun.freeze_time(TZ.localize(dt.datetime(2019, 12, 25)), tz_offset=10)  # Australia/Brisbane is +10
    def test_freezegun_with_offset(self):
        assert TZ.localize(dt.datetime.now()) == TZ.localize(dt.datetime(2019, 12, 25))
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