123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #ifndef GREGORIAN_FORMATTERS_HPP___
- #define GREGORIAN_FORMATTERS_HPP___
- #include "boost/date_time/compiler_config.hpp"
- #include "boost/date_time/gregorian/gregorian_types.hpp"
- #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
- #include "boost/date_time/date_formatting_limited.hpp"
- #else
- #include "boost/date_time/date_formatting.hpp"
- #endif
- #include "boost/date_time/iso_format.hpp"
- #include "boost/date_time/date_format_simple.hpp"
- namespace boost {
- namespace gregorian {
-
- template<class charT>
- inline
- std::basic_string<charT> to_simple_string_type(const date& d) {
- return date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d);
- }
-
-
- inline std::string to_simple_string(const date& d) {
- return to_simple_string_type<char>(d);
- }
-
- template<class charT>
- inline std::basic_string<charT> to_simple_string_type(const date_period& d) {
- typedef std::basic_string<charT> string_type;
- charT b = '[', m = '/', e=']';
- string_type d1(date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d.begin()));
- string_type d2(date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d.last()));
- return string_type(b + d1 + m + d2 + e);
- }
-
-
- inline std::string to_simple_string(const date_period& d) {
- return to_simple_string_type<char>(d);
- }
-
- template<class charT>
- inline std::basic_string<charT> to_iso_string_type(const date_period& d) {
- charT sep = '/';
- std::basic_string<charT> s(date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d.begin()));
- return s + sep + date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d.last());
- }
-
-
- inline std::string to_iso_string(const date_period& d) {
- return to_iso_string_type<char>(d);
- }
-
- template<class charT>
- inline std::basic_string<charT> to_iso_extended_string_type(const date& d) {
- return date_time::date_formatter<date,date_time::iso_extended_format<charT>,charT>::date_to_string(d);
- }
-
-
- inline std::string to_iso_extended_string(const date& d) {
- return to_iso_extended_string_type<char>(d);
- }
-
- template<class charT>
- inline std::basic_string<charT> to_iso_string_type(const date& d) {
- return date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d);
- }
-
-
- inline std::string to_iso_string(const date& d) {
- return to_iso_string_type<char>(d);
- }
-
-
-
- template<class charT>
- inline std::basic_string<charT> to_sql_string_type(const date& d)
- {
- date::ymd_type ymd = d.year_month_day();
- std::basic_ostringstream<charT> ss;
- ss << ymd.year << "-"
- << std::setw(2) << std::setfill(ss.widen('0'))
- << ymd.month.as_number()
- << "-"
- << std::setw(2) << std::setfill(ss.widen('0'))
- << ymd.day;
- return ss.str();
- }
- inline std::string to_sql_string(const date& d) {
- return to_sql_string_type<char>(d);
- }
- #if !defined(BOOST_NO_STD_WSTRING)
-
-
- inline std::wstring to_simple_wstring(const date_period& d) {
- return to_simple_string_type<wchar_t>(d);
- }
-
-
- inline std::wstring to_simple_wstring(const date& d) {
- return to_simple_string_type<wchar_t>(d);
- }
-
-
- inline std::wstring to_iso_wstring(const date_period& d) {
- return to_iso_string_type<wchar_t>(d);
- }
-
-
- inline std::wstring to_iso_extended_wstring(const date& d) {
- return to_iso_extended_string_type<wchar_t>(d);
- }
-
-
- inline std::wstring to_iso_wstring(const date& d) {
- return to_iso_string_type<wchar_t>(d);
- }
- inline std::wstring to_sql_wstring(const date& d) {
- return to_sql_string_type<wchar_t>(d);
- }
- #endif
- } }
- #endif
|