From 5fd979a8a3bc13aaf20c2833fe513df192d82fb1 Mon Sep 17 00:00:00 2001 From: Wouter Klouwen Date: Wed, 15 Nov 2017 18:00:09 +0000 Subject: CTest: adopt std::chrono::system_clock After the refactor to make CTest use std::chrono::steady_clock for the keeping of time for test duration, there are still references to cmSystemTools::GetTime() left. To further adopt std::chrono for time related activities, this commit changes those remaining references to std::chrono::system_clock::now() calls and alters the storage from either unsigned int or double to std::chrono::system_clock::time_point. For ease of conversion, a converter method is added to cmXMLWriter that converts from a std::chrono::system_clock::time_point to the number of seconds since the UN*X epoch as that is expected behaviour. This means no more casts as required. Functionally should be no difference as the system_clock is implemented in the same terms. --- Source/cmXMLWriter.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Source/cmXMLWriter.h') diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index 981255d415..c890acf782 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -7,6 +7,8 @@ #include "cmXMLSafe.h" +#include +#include #include #include #include @@ -99,6 +101,22 @@ private: return cmXMLSafe(value).Quotes(false); } + /* + * Convert a std::chrono::system::time_point to the number of seconds since + * the UN*X epoch. + * + * It would be tempting to convert a time_point to number of seconds by + * using time_since_epoch(). Unfortunately the C++11 standard does not + * specify what the epoch of the system_clock must be. + * Therefore we must assume it is an arbitary point in time. Instead of this + * method, it is recommended to convert it by means of the to_time_t method. + */ + static std::time_t SafeContent( + std::chrono::system_clock::time_point const& value) + { + return std::chrono::system_clock::to_time_t(value); + } + template static T SafeContent(T value) { -- cgit v1.2.1