diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/tools/inspect/time_string.hpp | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/tools/inspect/time_string.hpp')
-rw-r--r-- | src/boost/tools/inspect/time_string.hpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/boost/tools/inspect/time_string.hpp b/src/boost/tools/inspect/time_string.hpp new file mode 100644 index 000000000..72ca43968 --- /dev/null +++ b/src/boost/tools/inspect/time_string.hpp @@ -0,0 +1,55 @@ +// ---- time_string: thin wrapper around std::strftime -------- // +// +// Copyright Gennaro Prota 2006 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// ------------------------------------------------------------------ +// +// $Id$ + +#ifndef BOOST_TIME_STRING_HPP_GP_20060731 +#define BOOST_TIME_STRING_HPP_GP_20060731 + +#include <string> +#include <ctime> + +#include <boost/config/warning_disable.hpp> + +namespace boost { + +// Many of the boost tools just need a quick way to obtain +// a formatted "run date" string or similar. This is one. +// +// In case of failure false is returned and result is +// unchanged. +// +inline +bool time_string(std::string & result + , const std::string & format = "%X UTC, %A %d %B %Y") +{ + // give up qualifying names and using std::size_t, + // to avoid including "config.hpp" + using namespace std; + + const int sz = 256; + char buffer [ sz ] = { 0 }; + const time_t no_cal_time ( -1 ); + time_t tod; + + const bool ok = + time ( &tod ) != no_cal_time + && strftime( buffer, sz, format.c_str(), gmtime( &tod ) ) != 0 + ; + + if (ok) + result = buffer; + + return ok; +} + +} + +#endif // include guard |