Browse files

fix datetime now tz arg to work with tz_offset

  • Loading branch information...
1 parent 6697dc7 commit 7236d4cb3eb6c26d9c4be0bee84b068a559d663a @spulec committed Mar 24, 2013
Showing with 8 additions and 1 deletion.
  1. +1 −1 freezegun/api.py
  2. +7 −0 tests/test_operations.py
View
2 freezegun/api.py
@@ -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)
View
7 tests/test_operations.py
@@ -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.