|
3 | 3 | from datetime import datetime |
4 | 4 |
|
5 | 5 | from dateutil import tz |
| 6 | +from freezegun import freeze_time |
6 | 7 |
|
7 | 8 | import pendulum |
8 | 9 | import pytest |
9 | 10 | import pytz |
10 | 11 |
|
11 | 12 | from pendulum import DateTime |
12 | 13 | from pendulum.tz import timezone |
| 14 | +from pendulum.utils._compat import PY36 |
13 | 15 |
|
14 | 16 | from ..conftest import assert_datetime |
15 | 17 |
|
@@ -102,6 +104,50 @@ def test_now(): |
102 | 104 | assert now.hour != in_paris.hour |
103 | 105 |
|
104 | 106 |
|
| 107 | +@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+") |
| 108 | +@freeze_time("2016-03-27 00:30:00") |
| 109 | +def test_now_dst_off(): |
| 110 | + utc = pendulum.now("UTC") |
| 111 | + in_paris = pendulum.now("Europe/Paris") |
| 112 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 113 | + assert in_paris.hour == 1 |
| 114 | + assert not in_paris.is_dst() |
| 115 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 116 | + |
| 117 | + |
| 118 | +@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+") |
| 119 | +@freeze_time("2016-03-27 01:30:00") |
| 120 | +def test_now_dst_transitioning_on(): |
| 121 | + utc = pendulum.now("UTC") |
| 122 | + in_paris = pendulum.now("Europe/Paris") |
| 123 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 124 | + assert in_paris.hour == 3 |
| 125 | + assert in_paris.is_dst() |
| 126 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 127 | + |
| 128 | + |
| 129 | +@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+") |
| 130 | +@freeze_time("2016-10-30 00:30:00") |
| 131 | +def test_now_dst_on(): |
| 132 | + utc = pendulum.now("UTC") |
| 133 | + in_paris = pendulum.now("Europe/Paris") |
| 134 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 135 | + assert in_paris.hour == 2 |
| 136 | + assert in_paris.is_dst() |
| 137 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 138 | + |
| 139 | + |
| 140 | +@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+") |
| 141 | +@freeze_time("2016-10-30 01:30:00") |
| 142 | +def test_now_dst_transitioning_off(): |
| 143 | + utc = pendulum.now("UTC") |
| 144 | + in_paris = pendulum.now("Europe/Paris") |
| 145 | + in_paris_from_utc = utc.in_tz("Europe/Paris") |
| 146 | + assert in_paris.hour == 2 |
| 147 | + assert not in_paris.is_dst() |
| 148 | + assert in_paris.isoformat() == in_paris_from_utc.isoformat() |
| 149 | + |
| 150 | + |
105 | 151 | def test_now_with_fixed_offset(): |
106 | 152 | now = pendulum.now(6) |
107 | 153 |
|
|
0 commit comments