Skip to content

Commit 85e4632

Browse files
committed
Fix review remarks: remove useless comment and skip setting TZ environment variable on Windows
1 parent 8a301ec commit 85e4632

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

include/pybind11/chrono.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,9 @@ template <typename Duration> class type_caster<std::chrono::time_point<std::chro
150150
// Lazy initialise the PyDateTime import
151151
if (!PyDateTimeAPI) { PyDateTime_IMPORT; }
152152

153-
// Declare these special duration types so the conversions happen with the correct primitive types (int)
154-
using us_t = duration<int, std::micro>;
155-
156153
// Get out microseconds, and make sure they are positive, to avoid bug in eastern hemisphere time zones
157154
// (cfr. https://github.com/pybind/pybind11/issues/2417)
155+
using us_t = duration<int, std::micro>;
158156
auto us = duration_cast<us_t>(src.time_since_epoch() % seconds(1));
159157
if (us.count() < 0)
160158
us += seconds(1);

tests/test_chrono.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ def test_chrono_system_clock_roundtrip_date():
7171
assert time2.microsecond == 0
7272

7373

74+
SKIP_TZ_ENV_ON_WIN = pytest.mark.skipif(
75+
"env.WIN", reason="TZ environment variable only supported on POSIX"
76+
)
77+
78+
7479
@pytest.mark.parametrize("time1", [
7580
datetime.datetime.today().time(),
7681
datetime.time(0, 0, 0),
@@ -82,12 +87,14 @@ def test_chrono_system_clock_roundtrip_date():
8287
datetime.time(5, 59, 59, 1),
8388
])
8489
@pytest.mark.parametrize("tz", [
85-
"Europe/Brussels",
86-
"Asia/Pyongyang",
87-
"America/New_York",
90+
None,
91+
pytest.param("Europe/Brussels", marks=SKIP_TZ_ENV_ON_WIN),
92+
pytest.param("Asia/Pyongyang", marks=SKIP_TZ_ENV_ON_WIN),
93+
pytest.param("America/New_York", marks=SKIP_TZ_ENV_ON_WIN),
8894
])
8995
def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch):
90-
monkeypatch.setenv("TZ", "/usr/share/zoneinfo/{}".format(tz))
96+
if tz is not None:
97+
monkeypatch.setenv("TZ", "/usr/share/zoneinfo/{}".format(tz))
9198

9299
# Roundtrip the time
93100
datetime2 = m.test_chrono2(time1)

0 commit comments

Comments
 (0)