Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistency between timestamp and strftime #356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)