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

Fix now(tz) #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix now(tz) #406

wants to merge 1 commit into from

Conversation

mkenigs
Copy link

@mkenigs mkenigs commented Jul 23, 2021

now(tz) should return the same time utcnow returns adjusted by whatever
offset is contained by tz. Currently, the offset to freeze_time is also
added, which is removed by this change

Closes #405

@emontnemery
Copy link

It seems the current behavior is intentional, this PR breaks the tests.

@boxed
Copy link
Contributor

boxed commented Nov 2, 2021

I think it might be a bit much to say it's intentional just because the tests actually check it :P The tests could have been black box tests and then they just set in stone what the current behavior is.

@emontnemery
Copy link

Sure, but this PR does not adjust the tests.

@mkenigs mkenigs force-pushed the fix-now-tz branch 2 times, most recently from ae4a10a to 36aa6e9 Compare November 3, 2021 22:40
now(tz) should return the same time utcnow returns adjusted by whatever
offset is contained by tz. Currently, the offset to freeze_time is also
added, which is removed by this change

The current unit test is wrong because the UTC time is 2:00:00, so GMT5
should be 7:00:00, not 3:00:00

Closes spulec#405
@mkenigs
Copy link
Author

mkenigs commented Nov 3, 2021

I fixed the unit test. There's still 2 broken but those appear to be broken on master. Explanation from commit message:

The current unit test is wrong because the UTC time is 2:00:00, so GMT5
should be 7:00:00, not 3:00:00

I'm not sure if there's more documentation, but I'm basing my understanding of tz_offset on the readme:

@freeze_time("2012-01-14 03:21:34", tz_offset=-4)
def test():
    assert datetime.datetime.utcnow() == datetime.datetime(2012, 1, 14, 3, 21, 34)
    assert datetime.datetime.now() == datetime.datetime(2012, 1, 13, 23, 21, 34)

    # datetime.date.today() uses local time
    assert datetime.date.today() == datetime.date(2012, 1, 13)

The first argument to freeze_time is the UTC time, and adding the offset gives the local time. So in the unit test the UTC time is 2:00:00

@mkenigs
Copy link
Author

mkenigs commented Dec 6, 2021

@boxed @emontnemery does this look okay now that I fixed the test?

@codejedi365
Copy link

@mkenigs, well done! this is the fix I needed as well because I was magically a double timezone offset away. @spulec, please merge & release when you can.

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

Successfully merging this pull request may close these issues.

tz_offset doesn't work with dateutil.tz
4 participants