1 from __future__
import annotations
8 from pybind11_tests
import chrono
as m
13 date0 = datetime.datetime.today()
14 date1 = m.test_chrono1()
15 date2 = datetime.datetime.today()
21 diff_python =
abs(date2 - date0)
22 diff =
abs(date1 - date2)
29 assert diff.seconds <= diff_python.seconds
33 date1 = datetime.datetime.today()
36 date2 = m.test_chrono2(date1)
42 diff =
abs(date1 - date2)
43 assert diff == datetime.timedelta(0)
47 date1 = datetime.date.today()
50 datetime2 = m.test_chrono2(date1)
51 date2 = datetime2.date()
52 time2 = datetime2.time()
55 assert isinstance(datetime2, datetime.datetime)
60 diff =
abs(date1 - date2)
62 assert diff.seconds == 0
63 assert diff.microseconds == 0
69 assert time2.hour == 0
70 assert time2.minute == 0
71 assert time2.second == 0
72 assert time2.microsecond == 0
75 SKIP_TZ_ENV_ON_WIN = pytest.mark.skipif(
76 "env.WIN", reason=
"TZ environment variable only supported on POSIX"
80 @pytest.mark.parametrize(
83 datetime.datetime.today().
time(),
84 datetime.time(0, 0, 0),
85 datetime.time(0, 0, 0, 1),
86 datetime.time(0, 28, 45, 109827),
87 datetime.time(0, 59, 59, 999999),
88 datetime.time(1, 0, 0),
89 datetime.time(5, 59, 59, 0),
90 datetime.time(5, 59, 59, 1),
93 @pytest.mark.parametrize(
97 pytest.param(
"Europe/Brussels", marks=SKIP_TZ_ENV_ON_WIN),
98 pytest.param(
"Asia/Pyongyang", marks=SKIP_TZ_ENV_ON_WIN),
99 pytest.param(
"America/New_York", marks=SKIP_TZ_ENV_ON_WIN),
104 monkeypatch.setenv(
"TZ", f
"/usr/share/zoneinfo/{tz}")
107 datetime2 = m.test_chrono2(time1)
108 date2 = datetime2.date()
109 time2 = datetime2.time()
112 assert isinstance(datetime2, datetime.datetime)
117 assert time1 == time2
120 assert date2.year == 1970
121 assert date2.month == 1
122 assert date2.day == 1
127 date1 = datetime.datetime.today()
128 date2 = datetime.datetime.today()
134 cpp_diff = m.test_chrono3(diff)
136 assert cpp_diff == diff
139 diff = datetime.timedelta(microseconds=-1)
140 cpp_diff = m.test_chrono3(diff)
142 assert cpp_diff == diff
146 date1 = datetime.datetime.today()
147 date2 = datetime.datetime.today()
150 cpp_diff = m.test_chrono4(date2, date1)
152 assert cpp_diff == diff
156 date1 = datetime.date.today()
157 date2 = datetime.date.today()
160 cpp_diff = m.test_chrono4(date2, date1)
162 assert cpp_diff == diff
166 time1 = m.test_chrono5()
171 time1 = datetime.timedelta(days=10, seconds=10, microseconds=100)
172 time2 = m.test_chrono6(time1)
177 assert time1 == time2
182 time = m.test_chrono7(35.525123)
186 assert time.seconds == 35
187 assert 525122 <= time.microseconds <= 525123
189 diff = m.test_chrono_float_diff(43.789012, 1.123456)
190 assert diff.seconds == 42
191 assert 665556 <= diff.microseconds <= 665557
195 time = datetime.datetime.now()
196 time1 = m.test_nano_timepoint(time, datetime.timedelta(seconds=60))
197 assert time1 == time + datetime.timedelta(seconds=60)
201 resolutions = m.different_resolutions()
202 time = datetime.datetime.now()
203 resolutions.timestamp_h = time
204 resolutions.timestamp_m = time
205 resolutions.timestamp_s = time
206 resolutions.timestamp_ms = time
207 resolutions.timestamp_us = time