Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef POSIXTIME_FORMATTERS_LIMITED_HPP___
0002 #define POSIXTIME_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.hpp>
0013 #include <boost/date_time/compiler_config.hpp>
0014 #include <boost/date_time/iso_format.hpp>
0015 #include <boost/date_time/date_format_simple.hpp>
0016 #include <boost/date_time/posix_time/posix_time_types.hpp>
0017 #include <boost/date_time/time_formatting_streams.hpp>
0018 #include <boost/date_time/time_resolution_traits.hpp> // absolute_value
0019 
0020 namespace boost {
0021 
0022 namespace posix_time {
0023 
0024   //! Time duration to string -hh::mm::ss.fffffff. Example: 10:09:03.0123456
0025   /*!\ingroup time_format
0026    */
0027   inline std::string to_simple_string(time_duration td) {
0028     std::ostringstream ss;
0029     if(td.is_special()) {
0030       /* simply using 'ss << td.get_rep()' won't work on compilers
0031        * that don't support locales. This way does. */
0032       // switch copied from date_names_put.hpp
0033       switch(td.get_rep().as_special())
0034       {
0035       case not_a_date_time:
0036         //ss << "not-a-number";
0037         ss << "not-a-date-time";
0038         break;
0039       case pos_infin:
0040         ss << "+infinity";
0041         break;
0042       case neg_infin:
0043         ss << "-infinity";
0044         break;
0045       default:
0046         ss << "";
0047       }
0048     }
0049     else {
0050       if(td.is_negative()) {
0051         ss << '-';
0052       }
0053       ss  << std::setw(2) << std::setfill('0')
0054           << date_time::absolute_value(td.hours()) << ":";
0055       ss  << std::setw(2) << std::setfill('0')
0056           << date_time::absolute_value(td.minutes()) << ":";
0057       ss  << std::setw(2) << std::setfill('0')
0058           << date_time::absolute_value(td.seconds());
0059       //TODO the following is totally non-generic, yelling FIXME
0060 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
0061       boost::int64_t frac_sec =
0062         date_time::absolute_value(td.fractional_seconds());
0063       // JDG [7/6/02 VC++ compatibility]
0064       char buff[32];
0065       _i64toa(frac_sec, buff, 10);
0066 #else
0067       time_duration::fractional_seconds_type frac_sec =
0068         date_time::absolute_value(td.fractional_seconds());
0069 #endif
0070       if (frac_sec != 0) {
0071         ss  << "." << std::setw(time_duration::num_fractional_digits())
0072             << std::setfill('0')
0073 
0074           // JDG [7/6/02 VC++ compatibility]
0075 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
0076             << buff;
0077 #else
0078         << frac_sec;
0079 #endif
0080       }
0081     }// else
0082     return ss.str();
0083   }
0084 
0085   //! Time duration in ISO 8601 format -hhmmss.fffffff. Example: 10:09:03.0123456
0086   /*!\ingroup time_format
0087    */
0088   inline
0089   std::string
0090   to_iso_string(time_duration td)
0091   {
0092     std::ostringstream ss;
0093     if(td.is_special()) {
0094       /* simply using 'ss << td.get_rep()' won't work on compilers
0095        * that don't support locales. This way does. */
0096       // switch copied from date_names_put.hpp
0097       switch(td.get_rep().as_special()) {
0098       case not_a_date_time:
0099         //ss << "not-a-number";
0100         ss << "not-a-date-time";
0101         break;
0102       case pos_infin:
0103         ss << "+infinity";
0104         break;
0105       case neg_infin:
0106         ss << "-infinity";
0107         break;
0108       default:
0109         ss << "";
0110       }
0111     }
0112     else {
0113       if(td.is_negative()) {
0114         ss << '-';
0115       }
0116       ss  << std::setw(2) << std::setfill('0')
0117           << date_time::absolute_value(td.hours());
0118       ss  << std::setw(2) << std::setfill('0')
0119           << date_time::absolute_value(td.minutes());
0120       ss  << std::setw(2) << std::setfill('0')
0121           << date_time::absolute_value(td.seconds());
0122       //TODO the following is totally non-generic, yelling FIXME
0123 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
0124       boost::int64_t frac_sec =
0125         date_time::absolute_value(td.fractional_seconds());
0126       // JDG [7/6/02 VC++ compatibility]
0127       char buff[32];
0128       _i64toa(frac_sec, buff, 10);
0129 #else
0130       time_duration::fractional_seconds_type frac_sec =
0131         date_time::absolute_value(td.fractional_seconds());
0132 #endif
0133       if (frac_sec != 0) {
0134         ss  << "." << std::setw(time_duration::num_fractional_digits())
0135             << std::setfill('0')
0136 
0137           // JDG [7/6/02 VC++ compatibility]
0138 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
0139             << buff;
0140 #else
0141         << frac_sec;
0142 #endif
0143       }
0144     }// else
0145     return ss.str();
0146   }
0147 
0148   //! Time to simple format CCYY-mmm-dd hh:mm:ss.fffffff
0149   /*!\ingroup time_format
0150    */
0151   inline
0152   std::string
0153   to_simple_string(ptime t)
0154   {
0155     std::string ts = gregorian::to_simple_string(t.date());// + " ";
0156     if(!t.time_of_day().is_special()) {
0157       return ts + " " + to_simple_string(t.time_of_day());
0158     }
0159     else {
0160       return ts;
0161     }
0162   }
0163 
0164   //! Convert to string of form [YYYY-mmm-DD HH:MM::SS.ffffff/YYYY-mmm-DD HH:MM::SS.fffffff]
0165   /*!\ingroup time_format
0166    */
0167   inline
0168   std::string
0169   to_simple_string(time_period tp)
0170   {
0171     std::string d1(to_simple_string(tp.begin()));
0172     std::string d2(to_simple_string(tp.last()));
0173     return std::string("[" + d1 + "/" + d2 +"]");
0174   }
0175 
0176   //! Convert ISO 8601 short form YYYYMMDDTHHMMSS where T is the date-time separator
0177   /*!\ingroup time_format
0178    */
0179   inline
0180   std::string to_iso_string(ptime t)
0181   {
0182     std::string ts = gregorian::to_iso_string(t.date());// + "T";
0183     if(!t.time_of_day().is_special()) {
0184       return ts + "T" + to_iso_string(t.time_of_day());
0185     }
0186     else {
0187       return ts;
0188     }
0189   }
0190 
0191   //! Convert to form YYYY-MM-DDTHH:MM:SS where T is the date-time separator
0192   /*!\ingroup time_format
0193    */
0194   inline
0195   std::string
0196   to_iso_extended_string(ptime t)
0197   {
0198     std::string ts = gregorian::to_iso_extended_string(t.date());// + "T";
0199     if(!t.time_of_day().is_special()) {
0200       return ts + "T" + to_simple_string(t.time_of_day());
0201     }
0202     else {
0203       return ts;
0204     }
0205   }
0206 
0207 
0208 } } //namespace posix_time
0209 
0210 
0211 #endif
0212