Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Eastern hemisphere timezones break std::chrono::time_point<std::chrono::system_clock, Duration> caster #2417

Closed
YannickJadoul opened this issue Aug 20, 2020 · 0 comments · Fixed by #2438

Comments

@YannickJadoul
Copy link
Collaborator

test_chrono_system_clock_roundtrip_time fails on my system between midnight and 1 o'clock.
Demonstrated by @henryiii in these tests (when run from a timezone in the eastern hemisphere): master...henryiii:fix/timebug

Further investigation shows that a negative number of microseconds is passed to PyDateTime_FromDateAndTime (in cast), resulting in an C API error that's not handled.

Current hypothesis of what goes wrong:

  • Converting a Python datetime.time to C++ adds 1 January, 1970 as date in a std::tm struct.
  • This is then converted to a <chrono> type through system_clock::from_time_t(std::mktime(...)), turning the clock back an hour to convert to UTC (I'm the CET time zone UTC+01:00 - ignoring summer time) .
  • This results in a "negative" time. When converting back to Python, (duration_cast<us_t>(src.time_since_epoch() % seconds(1))).count() results in a negative number.
YannickJadoul added a commit to YannickJadoul/pybind11 that referenced this issue Aug 26, 2020
YannickJadoul added a commit that referenced this issue Aug 28, 2020
… hemisphere timezones (#2417) (#2438)

* Fix bug roundtripping datetime.time objects after midnight in eastern hemisphere timezones (#2417)

* tests: check more timezones

* Fix review remarks: remove useless comment and skip setting TZ environment variable on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant