Skip to content

Commit

Permalink
Fix now(tz)
Browse files Browse the repository at this point in the history
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 #405
  • Loading branch information
mkenigs committed Nov 3, 2021
1 parent 8994558 commit 5c5f1b1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def timestamp(self):
def now(cls, tz=None):
now = cls._time_to_freeze() or real_datetime.now()
if tz:
result = tz.fromutc(now.replace(tzinfo=tz)) + cls._tz_offset()
result = tz.fromutc(now.replace(tzinfo=tz))
else:
result = now + cls._tz_offset()
return datetime_to_fakedatetime(result)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_datetime_timezone_real():
@freeze_time("2012-01-14 2:00:00", tz_offset=-4)
def test_datetime_timezone_real_with_offset():
now = datetime.datetime.now(tz=GMT5())
assert now == datetime.datetime(2012, 1, 14, 3, tzinfo=GMT5())
assert now == datetime.datetime(2012, 1, 14, 7, tzinfo=GMT5())
assert now.utcoffset() == timedelta(0, 60 * 60 * 5)


Expand Down

0 comments on commit 5c5f1b1

Please sign in to comment.