6 from pybind11_tests
import chrono
as m
12 date0 = datetime.datetime.today()
13 date1 = m.test_chrono1()
14 date2 = datetime.datetime.today()
20 diff_python =
abs(date2 - date0)
21 diff =
abs(date1 - date2)
28 assert diff.seconds <= diff_python.seconds
32 date1 = datetime.datetime.today()
35 date2 = m.test_chrono2(date1)
41 diff =
abs(date1 - date2)
42 assert diff == datetime.timedelta(0)
46 date1 = datetime.date.today()
49 datetime2 = m.test_chrono2(date1)
50 date2 = datetime2.date()
51 time2 = datetime2.time()
54 assert isinstance(datetime2, datetime.datetime)
59 diff =
abs(date1 - date2)
61 assert diff.seconds == 0
62 assert diff.microseconds == 0
68 assert time2.hour == 0
69 assert time2.minute == 0
70 assert time2.second == 0
71 assert time2.microsecond == 0
74 SKIP_TZ_ENV_ON_WIN = pytest.mark.skipif(
75 "env.WIN", reason=
"TZ environment variable only supported on POSIX" 79 @pytest.mark.parametrize(
82 datetime.datetime.today().
time(),
83 datetime.time(0, 0, 0),
84 datetime.time(0, 0, 0, 1),
85 datetime.time(0, 28, 45, 109827),
86 datetime.time(0, 59, 59, 999999),
87 datetime.time(1, 0, 0),
88 datetime.time(5, 59, 59, 0),
89 datetime.time(5, 59, 59, 1),
92 @pytest.mark.parametrize(
96 pytest.param(
"Europe/Brussels", marks=SKIP_TZ_ENV_ON_WIN),
97 pytest.param(
"Asia/Pyongyang", marks=SKIP_TZ_ENV_ON_WIN),
98 pytest.param(
"America/New_York", marks=SKIP_TZ_ENV_ON_WIN),
103 monkeypatch.setenv(
"TZ", f
"/usr/share/zoneinfo/{tz}")
106 datetime2 = m.test_chrono2(time1)
107 date2 = datetime2.date()
108 time2 = datetime2.time()
111 assert isinstance(datetime2, datetime.datetime)
116 assert time1 == time2
119 assert date2.year == 1970
120 assert date2.month == 1
121 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
147 date1 = datetime.datetime.today()
148 date2 = datetime.datetime.today()
151 cpp_diff = m.test_chrono4(date2, date1)
153 assert cpp_diff == diff
158 date1 = datetime.date.today()
159 date2 = datetime.date.today()
162 cpp_diff = m.test_chrono4(date2, date1)
164 assert cpp_diff == diff
168 time1 = m.test_chrono5()
173 time1 = datetime.timedelta(days=10, seconds=10, microseconds=100)
174 time2 = m.test_chrono6(time1)
179 assert time1 == time2
184 time = m.test_chrono7(35.525123)
188 assert time.seconds == 35
189 assert 525122 <= time.microseconds <= 525123
191 diff = m.test_chrono_float_diff(43.789012, 1.123456)
192 assert diff.seconds == 42
193 assert 665556 <= diff.microseconds <= 665557
197 time = datetime.datetime.now()
198 time1 = m.test_nano_timepoint(time, datetime.timedelta(seconds=60))
199 assert time1 == time + datetime.timedelta(seconds=60)
203 resolutions = m.different_resolutions()
204 time = datetime.datetime.now()
205 resolutions.timestamp_h = time
206 resolutions.timestamp_m = time
207 resolutions.timestamp_s = time
208 resolutions.timestamp_ms = time
209 resolutions.timestamp_us = time
def test_chrono_system_clock_roundtrip_date()
def test_chrono_duration_subtraction_equivalence()
bool isinstance(handle obj)
def test_chrono_duration_roundtrip()
def test_chrono_system_clock()
def test_chrono_steady_clock()
def test_nano_timepoint()
def test_chrono_different_resolutions()
def test_chrono_system_clock_roundtrip()
def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch)
def test_chrono_duration_subtraction_equivalence_date()
def test_chrono_steady_clock_roundtrip()
def test_floating_point_duration()