Skip to content

Commit

Permalink
Fix inconsistency between timestamp and strftime
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarys committed Jun 27, 2020
1 parent a57f61f commit 7df9a78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ def fake_strftime(format, time_to_format=None):
if time_to_format is None:
return real_strftime(format)
else:
y, m, d, hh, mm, ss = time_to_format[:6]
shifted_time = datetime.datetime(y, m, d, hh, mm, ss) \
- datetime.timedelta(seconds=time.timezone)
time_to_format = shifted_time.utctimetuple()
return real_strftime(format, time_to_format)

if real_clock is not None:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,13 @@ def test_datetime_in_timezone(monkeypatch):
assert datetime.datetime.now() == datetime.datetime(1970, 1, 1, 1, 0, 0)
finally:
time.tzset() # set the timezone back to what is was before


@pytest.mark.parametrize('test_date', [(2010, 10, 10), (2010, 6, 1)])
def test_compare_timestamp_and_strftime(test_date):
with freeze_time("1970-01-01 00:00"):

freeze_timestamp = datetime.datetime(*test_date).timestamp()
freeze_strftime = datetime.datetime(*test_date).strftime('%s')

assert freeze_timestamp == int(freeze_strftime)

0 comments on commit 7df9a78

Please sign in to comment.