Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix datetime now tz arg to work with tz_offset

  • Loading branch information...
commit 7236d4cb3eb6c26d9c4be0bee84b068a559d663a 1 parent 6697dc7
Steve Pulec authored
Showing with 8 additions and 1 deletion.
  1. +1 −1  freezegun/api.py
  2. +7 −0 tests/test_operations.py
2  freezegun/api.py
View
@@ -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)
7 tests/test_operations.py
View
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.