static std::chrono::time_point<std::chrono::system_clock, std::common_type_t<Duration, date::days>> to_sys(std::chrono::time_point<mil_clock, Duration> const& tp) { ++conversions; return epoch + tp.time_since_epoch(); }
static std::chrono::time_point<s2s_clock, Duration> from_sys(std::chrono::time_point<std::chrono::system_clock, Duration> const& tp) { ++conversions; return std::chrono::time_point<s2s_clock, Duration>(tp.time_since_epoch()); }
static int64_t convert( const std::chrono::time_point<std::chrono::system_clock>& x) { return std::chrono::duration_cast< std::chrono::duration<int64_t, std::micro>>( x.time_since_epoch()-std::chrono::seconds(946684800)).count(); }
std::chrono::time_point<mil_clock, std::common_type_t<Duration, date::days>> operator()(std::chrono::time_point<s2s_clock, Duration> const& tp) { ++conversions; using res = std::chrono::time_point<mil_clock, std::common_type_t<Duration, date::days>>; return res(tp.time_since_epoch() - mil_clock::epoch.time_since_epoch()); }
int main() { typedef std::chrono::system_clock Clock; typedef std::chrono::milliseconds Duration; { std::chrono::time_point<Clock, Duration> t(Duration(3)); assert(t.time_since_epoch() == Duration(3)); } { std::chrono::time_point<Clock, Duration> t(std::chrono::seconds(3)); assert(t.time_since_epoch() == Duration(3000)); } #if TEST_STD_VER > 11 { constexpr std::chrono::time_point<Clock, Duration> t(Duration(3)); static_assert(t.time_since_epoch() == Duration(3), ""); } { constexpr std::chrono::time_point<Clock, Duration> t(std::chrono::seconds(3)); static_assert(t.time_since_epoch() == Duration(3000), ""); } #endif }
timespec timepoint_to_timespec(const std::chrono::time_point<Clock, Duration> &timepoint) { timespec ts; auto rel_duration = timepoint.time_since_epoch(); const auto sec = std::chrono::duration_cast<std::chrono::seconds>(rel_duration); ts.tv_sec = sec.count(); ts.tv_nsec = static_cast<long>( std::chrono::duration_cast<std::chrono::nanoseconds>( rel_duration - sec) .count()); return ts; }
void printTimePoint(const std::chrono::time_point<Clock, Duration>& tp) { std::cout << std::fixed << tp.time_since_epoch().count() << std::endl; }
inline void CEREAL_SAVE_FUNCTION_NAME(Archive &ar, std::chrono::time_point<C, D> const &dur) { ar(CEREAL_NVP_("time_since_epoch", dur.time_since_epoch())); }
static inline void TimePointToLargeInteger(std::chrono::time_point<_Clock, _Rep>& tp, LARGE_INTEGER* ft) { using namespace std::chrono; winDuration t = duration_cast<winDuration>(tp.time_since_epoch()); ft->QuadPart = t.count() + 116444736000000000; }
std::chrono::time_point<steady_based_clock, Duration> operator()(std::chrono::time_point<std::chrono::steady_clock, Duration> const& tp) const { using res = std::chrono::time_point<steady_based_clock, Duration>; return res(tp.time_since_epoch()); }