Skip to content

Commit

Permalink
fix datetime now tz arg to work with tz_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
spulec committed Mar 24, 2013
1 parent 6697dc7 commit 7236d4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __sub__(self, other):
@classmethod
def now(cls, tz=None):
if tz:
result = tz.fromutc(cls.time_to_freeze.replace(tzinfo=tz))
result = tz.fromutc(cls.time_to_freeze.replace(tzinfo=tz)) + datetime.timedelta(hours=cls.tz_offset)
else:
result = cls.time_to_freeze + datetime.timedelta(hours=cls.tz_offset)
return datetime_to_fakedatetime(result)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ def test_datetime_timezone_real():
now = datetime.datetime.now(tz=GMT5())
now.should.equal(datetime.datetime(2012, 1, 14, 7, tzinfo=GMT5()))
now.utcoffset().should.equal(timedelta(0, 60 * 60 * 5))


@freeze_time("2012-01-14 2:00:00", tz_offset=-4)
def test_datetime_timezone_real_with_offset():
now = datetime.datetime.now(tz=GMT5())
now.should.equal(datetime.datetime(2012, 1, 14, 3, tzinfo=GMT5()))
now.utcoffset().should.equal(timedelta(0, 60 * 60 * 5))

0 comments on commit 7236d4c

Please sign in to comment.