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

UTC datetime timestamp not correct #181

Closed
bitdivision opened this issue May 11, 2017 · 2 comments
Closed

UTC datetime timestamp not correct #181

bitdivision opened this issue May 11, 2017 · 2 comments

Comments

@bitdivision
Copy link

Python 3

Code:

import datetime
from freezegun import freeze_time

freezer_ts = 1400000000
freezer_time = datetime.datetime.utcfromtimestamp(freezer_ts)
freezer_string = freezer_time.isoformat()
print(freezer_string)

with freeze_time(freezer_string):
    print(datetime.datetime.utcnow().timestamp())
    print(datetime.datetime.utcnow())

Output:

2014-05-13T16:53:20
1399996400.0
2014-05-13 16:53:20

Expected:

2014-05-13T16:53:20
140000000.0
2014-05-13 16:53:20

The datetime object seems correct but the timestamp is not?

@spulec
Copy link
Owner

spulec commented May 13, 2017

I believe this is a duplicate of #89

Let me know if you don't think that is the case.

@spulec spulec closed this as completed May 13, 2017
@kyrias
Copy link

kyrias commented Sep 26, 2019

@spulec While it might be the same cause, I don't think it's really the same issue.

Let's say you do freeze_time("2019-01-30T12:00:00+00:00"). I think it's entirely reasonable to then get FakeDatetime(2019, 1, 30, 12, 0) when calling both now() and utcnow(), which is what that issue is complaining about.

The problem here is that when my computer is in UTC+1, calling utcnow().timestamp() will get you the 1548846000.0, which is actually the timestamp for 2019-01-30T11:00:00+00:00:00, meaning that the timestamp generated is an hour off from what it should be.

Meanwhile datetime.utcfromtimestamp(datetime.utcnow().timestamp()) will actually give you FakeDatetime(2019, 1, 30, 11, 0) as it should.

This means that datetime.utcnow() is NOT equal to datetime.utcfromtimestamp(datetime.utcnow().timestamp()), which is rather broken behaviour.

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

3 participants