Move time_string.h so that it's available in RC branch.

[SVN r35091]
This commit is contained in:
Rene Rivera 2006-09-13 17:20:12 +00:00
parent b2dc655a59
commit d8527d16bf
2 changed files with 54 additions and 1 deletions

View File

@ -25,7 +25,7 @@
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/fstream.hpp"
#include "../common/time_string.hpp"
#include "time_string.hpp"
#include "inspector.hpp"

53
time_string.hpp Normal file
View File

@ -0,0 +1,53 @@
// ---- 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>
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