MCPcopy Create free account
hub / github.com/HowardHinnant/date / const_clock

Class const_clock

test/clock_cast_test/constexpr.pass.cpp:27–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include <type_traits>
26
27struct const_clock {
28 using duration =
29 typename std::common_type<std::chrono::system_clock::duration,
30 date::days>::type;
31 using rep = duration::rep;
32 using period = duration::period;
33 using time_point = std::chrono::time_point<const_clock, duration>;
34
35 static constexpr date::sys_days epoch { date::days { 1000 } };
36
37 template <typename Duration>
38 static std::chrono::time_point<std::chrono::system_clock,
39 typename std::common_type<Duration, date::days>::type>
40 CONSTCD11 to_sys(std::chrono::time_point<const_clock, Duration> const& tp)
41 {
42 return epoch + tp.time_since_epoch();
43 }
44
45 template <typename Duration>
46 static std::chrono::time_point<const_clock,
47 typename std::common_type<Duration, date::days>::type>
48 CONSTCD11 from_sys(
49 std::chrono::time_point<std::chrono::system_clock, Duration> const&
50 tp)
51 {
52 using res = std::chrono::time_point<const_clock,
53 typename std::common_type<Duration, date::days>::type>;
54 return res(tp - epoch);
55 }
56};
57
58int main()
59{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected