2 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)
43 assert diff.seconds == 0
44 assert diff.microseconds == 0
48 date1 = datetime.date.today()
51 datetime2 = m.test_chrono2(date1)
52 date2 = datetime2.date()
53 time2 = datetime2.time()
56 assert isinstance(datetime2, datetime.datetime)
61 diff =
abs(date1 - date2)
63 assert diff.seconds == 0
64 assert diff.microseconds == 0
67 assert date1.year == date2.year
68 assert date1.month == date2.month
69 assert date1.day == date2.day
72 assert time2.hour == 0
73 assert time2.minute == 0
74 assert time2.second == 0
75 assert time2.microsecond == 0
78 SKIP_TZ_ENV_ON_WIN = pytest.mark.skipif(
79 "env.WIN", reason=
"TZ environment variable only supported on POSIX" 83 @pytest.mark.parametrize(
"time1", [
84 datetime.datetime.today().
time(),
85 datetime.time(0, 0, 0),
86 datetime.time(0, 0, 0, 1),
87 datetime.time(0, 28, 45, 109827),
88 datetime.time(0, 59, 59, 999999),
89 datetime.time(1, 0, 0),
90 datetime.time(5, 59, 59, 0),
91 datetime.time(5, 59, 59, 1),
93 @pytest.mark.parametrize(
"tz", [
95 pytest.param(
"Europe/Brussels", marks=SKIP_TZ_ENV_ON_WIN),
96 pytest.param(
"Asia/Pyongyang", marks=SKIP_TZ_ENV_ON_WIN),
97 pytest.param(
"America/New_York", marks=SKIP_TZ_ENV_ON_WIN),
101 monkeypatch.setenv(
"TZ",
"/usr/share/zoneinfo/{}".format(tz))
104 datetime2 = m.test_chrono2(time1)
105 date2 = datetime2.date()
106 time2 = datetime2.time()
109 assert isinstance(datetime2, datetime.datetime)
114 assert time1.hour == time2.hour
115 assert time1.minute == time2.minute
116 assert time1.second == time2.second
117 assert time1.microsecond == time2.microsecond
120 assert date2.year == 1970
121 assert date2.month == 1
122 assert date2.day == 1
128 date1 = datetime.datetime.today()
129 date2 = datetime.datetime.today()
135 cpp_diff = m.test_chrono3(diff)
137 assert cpp_diff.days == diff.days
138 assert cpp_diff.seconds == diff.seconds
139 assert cpp_diff.microseconds == diff.microseconds
144 date1 = datetime.datetime.today()
145 date2 = datetime.datetime.today()
148 cpp_diff = m.test_chrono4(date2, date1)
150 assert cpp_diff.days == diff.days
151 assert cpp_diff.seconds == diff.seconds
152 assert cpp_diff.microseconds == diff.microseconds
157 date1 = datetime.date.today()
158 date2 = datetime.date.today()
161 cpp_diff = m.test_chrono4(date2, date1)
163 assert cpp_diff.days == diff.days
164 assert cpp_diff.seconds == diff.seconds
165 assert cpp_diff.microseconds == diff.microseconds
169 time1 = m.test_chrono5()
174 time1 = datetime.timedelta(days=10, seconds=10, microseconds=100)
175 time2 = m.test_chrono6(time1)
180 assert time1.days == time2.days
181 assert time1.seconds == time2.seconds
182 assert time1.microseconds == time2.microseconds
187 time = m.test_chrono7(35.525123)
191 assert time.seconds == 35
192 assert 525122 <= time.microseconds <= 525123
194 diff = m.test_chrono_float_diff(43.789012, 1.123456)
195 assert diff.seconds == 42
196 assert 665556 <= diff.microseconds <= 665557
200 time = datetime.datetime.now()
201 time1 = m.test_nano_timepoint(time, datetime.timedelta(seconds=60))
202 assert(time1 == time + datetime.timedelta(seconds=60))
206 resolutions = m.different_resolutions()
207 time = datetime.datetime.now()
208 resolutions.timestamp_h = time
209 resolutions.timestamp_m = time
210 resolutions.timestamp_s = time
211 resolutions.timestamp_ms = time
212 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()