Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:34

0001 #ifndef GREGORIAN_FORMATTERS_HPP___
0002 #define GREGORIAN_FORMATTERS_HPP___
0003 
0004 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 #include "boost/date_time/compiler_config.hpp"
0013 #include "boost/date_time/gregorian/gregorian_types.hpp"
0014 #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
0015 #include "boost/date_time/date_formatting_limited.hpp"
0016 #else
0017 #include "boost/date_time/date_formatting.hpp"
0018 #endif
0019 #include "boost/date_time/iso_format.hpp"
0020 #include "boost/date_time/date_format_simple.hpp"
0021 
0022 /* NOTE: "to_*_string" code for older compilers, ones that define 
0023  * BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS, is located in 
0024  * formatters_limited.hpp
0025  */
0026 
0027 namespace boost {
0028 namespace gregorian {
0029 
0030   // wrapper function for to_simple_(w)string(date)
0031   template<class charT>
0032   inline 
0033   std::basic_string<charT> to_simple_string_type(const date& d) {
0034     return date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d);
0035   }
0036   //! To YYYY-mmm-DD string where mmm 3 char month name. Example:  2002-Jan-01
0037   /*!\ingroup date_format
0038    */
0039   inline std::string to_simple_string(const date& d) {
0040     return to_simple_string_type<char>(d);
0041   }
0042 
0043 
0044   // wrapper function for to_simple_(w)string(date_period)
0045   template<class charT>
0046   inline std::basic_string<charT> to_simple_string_type(const date_period& d) {
0047     typedef std::basic_string<charT> string_type;
0048     charT b = '[', m = '/', e=']';
0049 
0050     string_type d1(date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d.begin()));
0051     string_type d2(date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d.last()));
0052     return string_type(b + d1 + m + d2 + e);
0053   }
0054   //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02]
0055   /*!\ingroup date_format
0056    */
0057   inline std::string to_simple_string(const date_period& d) {
0058     return to_simple_string_type<char>(d);
0059   }
0060 
0061   // wrapper function for to_iso_(w)string(date_period)
0062   template<class charT>
0063   inline std::basic_string<charT> to_iso_string_type(const date_period& d) {
0064     charT sep = '/';
0065     std::basic_string<charT> s(date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d.begin()));
0066     return s + sep + date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d.last());
0067   }
0068   //! Date period to ISO 8601 standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231
0069   /*!\ingroup date_format
0070    */
0071   inline std::string to_iso_string(const date_period& d) {
0072     return to_iso_string_type<char>(d);
0073   }
0074 
0075 
0076   // wrapper function for to_iso_extended_(w)string(date)
0077   template<class charT>
0078   inline std::basic_string<charT> to_iso_extended_string_type(const date& d) {
0079     return date_time::date_formatter<date,date_time::iso_extended_format<charT>,charT>::date_to_string(d);
0080   }
0081   //! Convert to ISO 8601 extended format string CCYY-MM-DD. Example 2002-12-31
0082   /*!\ingroup date_format
0083    */
0084   inline std::string to_iso_extended_string(const date& d) {
0085     return to_iso_extended_string_type<char>(d);
0086   }
0087 
0088   // wrapper function for to_iso_(w)string(date)
0089   template<class charT>
0090   inline std::basic_string<charT> to_iso_string_type(const date& d) {
0091     return date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d);
0092   }
0093   //! Convert to ISO 8601 standard string YYYYMMDD. Example: 20021231
0094   /*!\ingroup date_format
0095    */
0096   inline std::string to_iso_string(const date& d) {
0097     return to_iso_string_type<char>(d);
0098   }
0099 
0100   
0101   
0102 
0103   // wrapper function for to_sql_(w)string(date)
0104   template<class charT>
0105   inline std::basic_string<charT> to_sql_string_type(const date& d) 
0106   {
0107     date::ymd_type ymd = d.year_month_day();
0108     std::basic_ostringstream<charT> ss;
0109     ss << ymd.year << "-"
0110        << std::setw(2) << std::setfill(ss.widen('0')) 
0111        << ymd.month.as_number() //solves problem with gcc 3.1 hanging
0112        << "-"
0113        << std::setw(2) << std::setfill(ss.widen('0')) 
0114        << ymd.day;
0115     return ss.str();
0116   }
0117   inline std::string to_sql_string(const date& d) {
0118     return to_sql_string_type<char>(d);
0119   }
0120 
0121 
0122 #if !defined(BOOST_NO_STD_WSTRING)
0123   //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02]
0124   /*!\ingroup date_format
0125    */
0126   inline std::wstring to_simple_wstring(const date_period& d) {
0127     return to_simple_string_type<wchar_t>(d);
0128   }
0129   //! To YYYY-mmm-DD string where mmm 3 char month name. Example:  2002-Jan-01
0130   /*!\ingroup date_format
0131    */
0132   inline std::wstring to_simple_wstring(const date& d) {
0133     return to_simple_string_type<wchar_t>(d);
0134   }
0135   //! Date period to iso standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231
0136   /*!\ingroup date_format
0137    */
0138   inline std::wstring to_iso_wstring(const date_period& d) {
0139     return to_iso_string_type<wchar_t>(d);
0140   }
0141   //! Convert to iso extended format string CCYY-MM-DD. Example 2002-12-31
0142   /*!\ingroup date_format
0143    */
0144   inline std::wstring to_iso_extended_wstring(const date& d) {
0145     return to_iso_extended_string_type<wchar_t>(d);
0146   }
0147   //! Convert to iso standard string YYYYMMDD. Example: 20021231
0148   /*!\ingroup date_format
0149    */
0150   inline std::wstring to_iso_wstring(const date& d) {
0151     return to_iso_string_type<wchar_t>(d);
0152   }
0153   inline std::wstring to_sql_wstring(const date& d) {
0154     return to_sql_string_type<wchar_t>(d);
0155   }
0156 #endif // BOOST_NO_STD_WSTRING
0157 
0158 } } //namespace gregorian
0159 
0160 
0161 #endif
0162