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

FakeDatetime's timestamp() is not consistent with datetime().timestamp() #548

Open
BielStela opened this issue May 17, 2024 · 1 comment

Comments

@BielStela
Copy link

the result of timestamp() on a FakeDatetime is not the same result as in a datetime.datetime.

I would expect this to succed:

t = datetime.datetime(2024, 1, 1, 12, 0, 0)
with freeze_time(t):
    assert datetime.datetime.now().timestamp() == t.timestamp()

but it fails with:

AssertionError: assert 1704110400.0 == 1704106800.0
@BielStela
Copy link
Author

it works it I set a tz_info t = datetime.datetime(2024, 1, 1, 12, 0, tzinfo=datetime.UTC). No real clue what is going on but maybe it is because naive timestamp have to be computed manually and the implementation of the original timestamp doesn't look nice at all: https://github.com/python/cpython/blob/31a28cbae0989f57ad01b428c007dade24d9593a/Lib/_pydatetime.py#L1893

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