HomePhabricator

time: add runtime sanity check

Description

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

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11789

Details

Provenance
Cory Fields <cory-nospam-@coryfields.com>Authored on Jan 16 2017, 20:01
PiRKCommitted on Jul 22 2022, 09:55
PiRKPushed on Jul 22 2022, 09:55
Reviewer
Restricted Project
Differential Revision
D11789: time: add runtime sanity check
Parents
rABCdb165ec2c333: [Chronik] Add lint macro to prevent having to repeat common lints in every crate
Branches
Unknown
Tags
Unknown