1 #ifndef DATE_TIME_DATE_FORMATTING_LIMITED_HPP___
2 #define DATE_TIME_DATE_FORMATTING_LIMITED_HPP___
4 /* Copyright (c) 2002-2004 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/iso_format.hpp"
13 #include "boost/date_time/compiler_config.hpp"
22 //! Formats a month as as string into an ostream
23 template<class month_type
, class format_type
>
27 //! Formats a month as as string into an ostream
28 /*! This function demands that month_type provide
29 * functions for converting to short and long strings
30 * if that capability is used.
32 static std::ostream
& format_month(const month_type
& month
,
35 switch (format_type::month_format())
37 case month_as_short_string
:
39 os
<< month
.as_short_string();
42 case month_as_long_string
:
44 os
<< month
.as_long_string();
47 case month_as_integer
:
49 os
<< std::setw(2) << std::setfill('0') << month
.as_number();
59 //! Convert ymd to a standard string formatting policies
60 template<class ymd_type
, class format_type
>
64 //! Convert ymd to a standard string formatting policies
65 /*! This is standard code for handling date formatting with
66 * year-month-day based date information. This function
67 * uses the format_type to control whether the string will
68 * contain separator characters, and if so what the character
69 * will be. In addtion, it can format the month as either
70 * an integer or a string as controled by the formatting
73 static std::string
ymd_to_string(ymd_type ymd
)
75 typedef typename
ymd_type::month_type month_type
;
76 std::ostringstream ss
;
78 if (format_type::has_date_sep_chars()) {
79 ss
<< format_type::month_sep_char();
81 //this name is a bit ugly, oh well....
82 month_formatter
<month_type
,format_type
>::format_month(ymd
.month
, ss
);
83 if (format_type::has_date_sep_chars()) {
84 ss
<< format_type::day_sep_char();
86 ss
<< std::setw(2) << std::setfill('0')
93 //! Convert a date to string using format policies
94 template<class date_type
, class format_type
>
98 //! Convert to a date to standard string using format policies
99 static std::string
date_to_string(date_type d
)
101 typedef typename
date_type::ymd_type ymd_type
;
102 if (d
.is_not_a_date()) {
103 return format_type::not_a_date();
105 if (d
.is_neg_infinity()) {
106 return format_type::neg_infinity();
108 if (d
.is_pos_infinity()) {
109 return format_type::pos_infinity();
111 ymd_type ymd
= d
.year_month_day();
112 return ymd_formatter
<ymd_type
, format_type
>::ymd_to_string(ymd
);
117 } } //namespace date_time