Page MenuHomePhabricator

time: add runtime sanity check
ClosedPublic

Authored by PiRK on Jul 22 2022, 08:09.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC7ba2b08340f9: time: add runtime sanity check
Summary

std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed to use the Unix epoch timestamp, but in practice they almost certainly will. Any differing behavior will be assumed to be an error, unless certain platforms prove to consistently deviate, at which point we'll cope with it by adding offsets.

Do a quick runtime check to verify that time_t(0) == std::chrono::system_clock's epoch time == unix epoch.

Co-authored-by: Anthony Towns <aj@erisian.com.au>

This is a backport of core#21110 [1/2]
https://github.com/bitcoin/bitcoin/pull/21110/commits/3c2e16be22ae04bf56663ee5ec1554d0d569741b

Note: see D5448 for usage of #ifdef _WIN32 to determine gmtime_s availability. It this turns out to not work in the future, we can try to backport core#18358

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable