// file : butl/timestamp -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef BUTL_TIMESTAMP #define BUTL_TIMESTAMP #include #include #include namespace butl { // On all three main platforms that we target (GNU/Linux, Windows (both // VC++ and GCC/MinGW64), and MacOS X) with recent C++ runtimes, // system_clock has nanoseconds resolution and counts from the UNIX // epoch. The latter is important since struct stat also returns times // based on UNIX epoch. // // The underlying type for nanoseconds duration is signed integer type // of at least 64 bits (currently int64_t). Because it is signed, we // will overflow in year 2262 but by then the underlying type will // most likely have changed to something larger than 64-bit. // // So to support other platforms that could possibly use a different // system_clock resolutions (e.g., microseconds), we actually not going // to assume anywhere (except perhaps timestamp.cxx) that we are dealing // with nanoseconds or the 64-bit underlying type. // using std::chrono::system_clock; // Note that uninitialized timestamp has the timestamp_nonexistent // value. // using timestamp = system_clock::time_point; using duration = system_clock::duration; // Generally-useful special values. // const timestamp timestamp_unknown {duration {-1}}; const timestamp timestamp_nonexistent {duration {0}}; // Human-readable representation. Note that these operators // may throw std::system_error. // std::ostream& operator<< (std::ostream&, const timestamp&); std::ostream& operator<< (std::ostream&, const duration&); }; #endif // BUTL_TIMESTAMP