1 #ifndef GREGORIAN_FORMATTERS_LIMITED_HPP___
2 #define GREGORIAN_FORMATTERS_LIMITED_HPP___
4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
12 #include "boost/date_time/gregorian/gregorian_types.hpp"
13 #include "boost/date_time/date_formatting_limited.hpp"
14 #include "boost/date_time/iso_format.hpp"
15 #include "boost/date_time/date_format_simple.hpp"
16 #include "boost/date_time/compiler_config.hpp"
21 //! To YYYY-mmm-DD string where mmm 3 char month name. Example: 2002-Jan-01
22 /*!\ingroup date_format
24 inline std::string
to_simple_string(const date
& d
) {
25 return date_time::date_formatter
<date
,date_time::simple_format
<char> >::date_to_string(d
);
28 //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02]
29 /*!\ingroup date_format
31 inline std::string
to_simple_string(const date_period
& d
) {
33 std::string
d1(date_time::date_formatter
<date
,date_time::simple_format
<char> >::date_to_string(d
.begin()));
34 std::string
d2(date_time::date_formatter
<date
,date_time::simple_format
<char> >::date_to_string(d
.last()));
35 return std::string("[" + d1
+ "/" + d2
+ "]");
38 //! Date period to iso standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231
39 /*!\ingroup date_format
41 inline std::string
to_iso_string(const date_period
& d
) {
42 std::string
s(date_time::date_formatter
<date
,date_time::iso_format
<char> >::date_to_string(d
.begin()));
43 return s
+ "/" + date_time::date_formatter
<date
,date_time::iso_format
<char> >::date_to_string(d
.last());
47 //! Convert to iso extended format string CCYY-MM-DD. Example 2002-12-31
48 /*!\ingroup date_format
50 inline std::string
to_iso_extended_string(const date
& d
) {
51 return date_time::date_formatter
<date
,date_time::iso_extended_format
<char> >::date_to_string(d
);
54 //! Convert to iso standard string YYYYMMDD. Example: 20021231
55 /*!\ingroup date_format
57 inline std::string
to_iso_string(const date
& d
) {
58 return date_time::date_formatter
<date
,date_time::iso_format
<char> >::date_to_string(d
);
63 inline std::string
to_sql_string(const date
& d
)
65 date::ymd_type ymd
= d
.year_month_day();
66 std::ostringstream ss
;
68 << std::setw(2) << std::setfill('0')
69 << ymd
.month
.as_number() //solves problem with gcc 3.1 hanging
71 << std::setw(2) << std::setfill('0')
77 } } //namespace gregorian