Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef GREGORIAN_FORMATTERS_LIMITED_HPP___
0002 #define GREGORIAN_FORMATTERS_LIMITED_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/gregorian/gregorian_types.hpp"
0013 #include "boost/date_time/date_formatting_limited.hpp"
0014 #include "boost/date_time/iso_format.hpp"
0015 #include "boost/date_time/date_format_simple.hpp"
0016 #include "boost/date_time/compiler_config.hpp"
0017 
0018 namespace boost {
0019 namespace gregorian {
0020 
0021   //! To YYYY-mmm-DD string where mmm 3 char month name. Example:  2002-Jan-01
0022   /*!\ingroup date_format
0023    */
0024   inline std::string to_simple_string(const date& d) {
0025     return date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d);
0026   }
0027 
0028   //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02]
0029   /*!\ingroup date_format
0030    */
0031   inline std::string to_simple_string(const date_period& d) {
0032     std::string s("[");
0033     std::string d1(date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d.begin()));
0034     std::string d2(date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d.last()));
0035     return std::string("[" + d1 + "/" + d2 + "]");
0036   }
0037 
0038   //! Date period to ISO 8601 standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231
0039   /*!\ingroup date_format
0040    */
0041   inline std::string to_iso_string(const date_period& d) {
0042     std::string s(date_time::date_formatter<date,date_time::iso_format<char> >::date_to_string(d.begin()));
0043     return s + "/" + date_time::date_formatter<date,date_time::iso_format<char> >::date_to_string(d.last());
0044   }
0045 
0046 
0047   //! Convert to ISO 8601 extended format string CCYY-MM-DD. Example 2002-12-31
0048   /*!\ingroup date_format
0049    */
0050   inline std::string to_iso_extended_string(const date& d) {
0051     return date_time::date_formatter<date,date_time::iso_extended_format<char> >::date_to_string(d);
0052   }
0053 
0054   //! Convert to ISO 8601 standard string YYYYMMDD. Example: 20021231
0055   /*!\ingroup date_format
0056    */
0057   inline std::string to_iso_string(const date& d) {
0058     return date_time::date_formatter<date,date_time::iso_format<char> >::date_to_string(d);
0059   }
0060   
0061   
0062 
0063   inline std::string to_sql_string(const date& d) 
0064   {
0065     date::ymd_type ymd = d.year_month_day();
0066     std::ostringstream ss;
0067     ss << ymd.year << "-"
0068        << std::setw(2) << std::setfill('0') 
0069        << ymd.month.as_number() //solves problem with gcc 3.1 hanging
0070        << "-"
0071        << std::setw(2) << std::setfill('0') 
0072        << ymd.day;
0073     return ss.str();
0074   }
0075 
0076 
0077 } } //namespace gregorian
0078 
0079 
0080 #endif
0081