|
4 | 4 |
|
5 | 5 | from pendulum import DateTime |
6 | 6 | from pendulum.tz import timezone |
| 7 | +from pendulum.utils._compat import _HAS_FOLD |
7 | 8 |
|
8 | 9 | from ..conftest import assert_date, assert_time |
9 | 10 |
|
@@ -92,6 +93,29 @@ def test_int_timestamp_accuracy(): |
92 | 93 | assert d.int_timestamp == 32527311790 |
93 | 94 |
|
94 | 95 |
|
| 96 | +def test_timestamp_with_transition(): |
| 97 | + d_pre = pendulum.datetime( |
| 98 | + 2012, 10, 28, 2, 0, tz="Europe/Warsaw", dst_rule=pendulum.PRE_TRANSITION |
| 99 | + ) |
| 100 | + d_post = pendulum.datetime( |
| 101 | + 2012, 10, 28, 2, 0, tz="Europe/Warsaw", dst_rule=pendulum.POST_TRANSITION |
| 102 | + ) |
| 103 | + |
| 104 | + if _HAS_FOLD: |
| 105 | + # the difference between the timestamps before and after is equal to one hour |
| 106 | + assert d_post.timestamp() - d_pre.timestamp() == pendulum.SECONDS_PER_HOUR |
| 107 | + assert d_post.float_timestamp - d_pre.float_timestamp == ( |
| 108 | + pendulum.SECONDS_PER_HOUR |
| 109 | + ) |
| 110 | + assert d_post.int_timestamp - d_pre.int_timestamp == pendulum.SECONDS_PER_HOUR |
| 111 | + else: |
| 112 | + # when the transition is not recognizable |
| 113 | + # then the difference should be equal to zero hours |
| 114 | + assert d_post.timestamp() - d_pre.timestamp() == 0 |
| 115 | + assert d_post.float_timestamp - d_pre.float_timestamp == 0 |
| 116 | + assert d_post.int_timestamp - d_pre.int_timestamp == 0 |
| 117 | + |
| 118 | + |
95 | 119 | def test_age(): |
96 | 120 | d = pendulum.now() |
97 | 121 | assert d.age == 0 |
|
0 commit comments