Last change
on this file since 30 was
29,
checked in by landauf, 17 years ago
|
updated boost from 1_33_1 to 1_34_1
|
File size:
1.3 KB
|
Line | |
---|
1 | // ---- time_string: thin wrapper around std::strftime -------- // |
---|
2 | // |
---|
3 | // Copyright Gennaro Prota 2006 |
---|
4 | // |
---|
5 | // Distributed under the Boost Software License, Version 1.0. |
---|
6 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | // |
---|
9 | // ------------------------------------------------------------------ |
---|
10 | // |
---|
11 | // $Id: time_string.hpp,v 1.1.2.1 2006/09/13 17:25:52 grafik Exp $ |
---|
12 | |
---|
13 | #ifndef BOOST_TIME_STRING_HPP_GP_20060731 |
---|
14 | #define BOOST_TIME_STRING_HPP_GP_20060731 |
---|
15 | |
---|
16 | #include <string> |
---|
17 | #include <ctime> |
---|
18 | |
---|
19 | namespace boost { |
---|
20 | |
---|
21 | // Many of the boost tools just need a quick way to obtain |
---|
22 | // a formatted "run date" string or similar. This is one. |
---|
23 | // |
---|
24 | // In case of failure false is returned and result is |
---|
25 | // unchanged. |
---|
26 | // |
---|
27 | inline |
---|
28 | bool time_string(std::string & result |
---|
29 | , const std::string & format = "%X UTC, %A %d %B %Y") |
---|
30 | { |
---|
31 | // give up qualifying names and using std::size_t, |
---|
32 | // to avoid including "config.hpp" |
---|
33 | using namespace std; |
---|
34 | |
---|
35 | const int sz = 256; |
---|
36 | char buffer [ sz ] = { 0 }; |
---|
37 | const time_t no_cal_time ( -1 ); |
---|
38 | time_t tod; |
---|
39 | |
---|
40 | const bool ok = |
---|
41 | time ( &tod ) != no_cal_time |
---|
42 | && strftime( buffer, sz, format.c_str(), gmtime( &tod ) ) != 0 |
---|
43 | ; |
---|
44 | |
---|
45 | if (ok) |
---|
46 | result = buffer; |
---|
47 | |
---|
48 | return ok; |
---|
49 | } |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | #endif // include guard |
---|
Note: See
TracBrowser
for help on using the repository browser.