Skip to content

Commit

Permalink
Merge pull request #189 from thomasleveil/midnight_in_paris
Browse files Browse the repository at this point in the history
WIP: Midnight in paris - is this a bug ?
  • Loading branch information
kennethreitz authored Jul 19, 2024
2 parents bcc4885 + 882a6ae commit 9766619
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import datetime

import pytz
from freezegun import freeze_time
import pytest

Expand All @@ -23,3 +26,73 @@ def frozen_now(request):
now_string, tz_offset = request.param
with freeze_time(now_string, tz_offset=tz_offset):
yield


@pytest.fixture(params=[
datetime.datetime(2020, 8, 10, 22, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 10, 23, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 0, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 1, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 2, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 3, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 4, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 5, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 6, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 7, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 8, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 9, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 10, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 11, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 12, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 13, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 14, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 15, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 16, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 17, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 18, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 19, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 20, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 8, 11, 21, 2, 0, tzinfo=pytz.timezone('UTC')),
], ids=str)
def frozen_2020_08_11_in_paris(request):
"""
fixture setting datetime.now() to every hour of the 11th of august 2020 in Paris
(summer time, GMT+2)
"""
with freeze_time(request.param):
yield


@pytest.fixture(params=[
datetime.datetime(2020, 2, 10, 23, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 0, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 1, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 2, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 3, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 4, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 5, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 6, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 7, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 8, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 9, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 10, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 11, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 12, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 13, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 14, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 15, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 16, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 17, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 18, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 19, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 20, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 21, 2, 0, tzinfo=pytz.timezone('UTC')),
datetime.datetime(2020, 2, 11, 22, 2, 0, tzinfo=pytz.timezone('UTC')),
], ids=str)
def frozen_2020_02_11_in_paris(request):
"""
fixture setting datetime.now() to every hour of the 11th of february 2020 in Paris
(winter time, GMT+1)
"""
with freeze_time(request.param):
yield
36 changes: 36 additions & 0 deletions tests/test_maya.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,42 @@ def test_human_when():
assert (r2.day - r1.day) in (1, -30, -29, -28, -27)


@pytest.mark.usefixtures("frozen_2020_08_11_in_paris")
def test_human_when_today_with_timezone_summer_time():
d = maya.when("today", timezone='Europe/Paris')
assert str(d.datetime(to_timezone="Europe/Paris").date()) == '2020-08-11'


@pytest.mark.usefixtures("frozen_2020_02_11_in_paris")
def test_human_when_today_with_timezone_winter_time():
d = maya.when("today", timezone='Europe/Paris')
assert str(d.datetime(to_timezone="Europe/Paris").date()) == '2020-02-11'


@pytest.mark.usefixtures("frozen_2020_08_11_in_paris")
def test_human_when_yesterday_with_timezone_summer_time():
d = maya.when("yesterday", timezone='Europe/Paris')
assert str(d.datetime(to_timezone="Europe/Paris").date()) == '2020-08-10'


@pytest.mark.usefixtures("frozen_2020_02_11_in_paris")
def test_human_when_yesterday_with_timezone_winter_time():
d = maya.when("yesterday", timezone='Europe/Paris')
assert str(d.datetime(to_timezone="Europe/Paris").date()) == '2020-02-10'


@pytest.mark.usefixtures("frozen_2020_08_11_in_paris")
def test_human_when_midnight_with_timezone_summer_time():
d = maya.when("midnight", timezone='Europe/Paris')
assert str(d.datetime(to_timezone="Europe/Paris")) == '2020-08-11 00:00:00+02:00'


@pytest.mark.usefixtures("frozen_2020_02_11_in_paris")
def test_human_when_midnight_with_timezone_winter_time():
d = maya.when("midnight", timezone='Europe/Paris')
assert str(d.datetime(to_timezone="Europe/Paris")) == '2020-02-11 00:00:00+01:00'


def test_machine_parse():
r1 = maya.parse("August 14, 2015")
assert r1.day == 14
Expand Down

0 comments on commit 9766619

Please sign in to comment.