Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62669 - branches/release/boost/date_time
From: andrey.semashev_at_[hidden]
Date: 2010-06-09 12:39:31


Author: andysem
Date: 2010-06-09 12:39:31 EDT (Wed, 09 Jun 2010)
New Revision: 62669
URL: http://svn.boost.org/trac/boost/changeset/62669

Log:
Merged changes from trunk (rev. 62450). Fixes #3876.

Text files modified:
   branches/release/boost/date_time/time_facet.hpp | 45 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 42 insertions(+), 3 deletions(-)

Modified: branches/release/boost/date_time/time_facet.hpp
==============================================================================
--- branches/release/boost/date_time/time_facet.hpp (original)
+++ branches/release/boost/date_time/time_facet.hpp 2010-06-09 12:39:31 EDT (Wed, 09 Jun 2010)
@@ -21,6 +21,7 @@
 #include <boost/assert.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/throw_exception.hpp>
+#include <boost/range/as_literal.hpp>
 #include <boost/algorithm/string/erase.hpp>
 #include <boost/algorithm/string/replace.hpp>
 #include <boost/date_time/compiler_config.hpp>
@@ -42,6 +43,10 @@
       static const char_type seconds_format[3]; // S
       static const char_type hours_format[3]; // H
       static const char_type unrestricted_hours_format[3]; // O
+ static const char_type full_24_hour_time_format[3]; // T
+ static const char_type full_24_hour_time_expanded_format[9]; // HH:MM:SS
+ static const char_type short_24_hour_time_format[3]; // R
+ static const char_type short_24_hour_time_expanded_format[6]; // HH:MM
       static const char_type standard_format[9]; // x X
       static const char_type zone_abbrev_format[3]; // z
       static const char_type zone_name_format[3]; // Z
@@ -73,8 +78,7 @@
 
   template <class CharT>
   const typename time_formats<CharT>::char_type
- time_formats<CharT>::seconds_with_fractional_seconds_format[3] =
- {'%','s'};
+ time_formats<CharT>::seconds_with_fractional_seconds_format[3] = {'%','s'};
 
   template <class CharT>
   const typename time_formats<CharT>::char_type
@@ -90,6 +94,24 @@
 
   template <class CharT>
   const typename time_formats<CharT>::char_type
+ time_formats<CharT>::full_24_hour_time_format[3] = {'%','T'};
+
+ template <class CharT>
+ const typename time_formats<CharT>::char_type
+ time_formats<CharT>::full_24_hour_time_expanded_format[9] =
+ {'%','H',':','%','M',':','%','S'};
+
+ template <class CharT>
+ const typename time_formats<CharT>::char_type
+ time_formats<CharT>::short_24_hour_time_format[3] = {'%','R'};
+
+ template <class CharT>
+ const typename time_formats<CharT>::char_type
+ time_formats<CharT>::short_24_hour_time_expanded_format[6] =
+ {'%','H',':','%','M'};
+
+ template <class CharT>
+ const typename time_formats<CharT>::char_type
   //time_formats<CharT>::standard_format[5] = {'%','c',' ','%','z'};
   time_formats<CharT>::standard_format[9] = {'%','x',' ','%','X',' ','%','z'};
 
@@ -180,6 +202,7 @@
             class OutItrT = std::ostreambuf_iterator<CharT, std::char_traits<CharT> > >
   class time_facet :
     public boost::date_time::date_facet<typename time_type::date_type , CharT, OutItrT> {
+ typedef time_formats< CharT > formats_type;
    public:
     typedef typename time_type::date_type date_type;
     typedef typename time_type::time_duration_type time_duration_type;
@@ -266,6 +289,14 @@
       }
       string_type format(this->m_format);
 
+ // %T and %R have to be replaced here since they are not standard
+ boost::algorithm::replace_all(format,
+ boost::as_literal(formats_type::full_24_hour_time_format),
+ boost::as_literal(formats_type::full_24_hour_time_expanded_format));
+ boost::algorithm::replace_all(format,
+ boost::as_literal(formats_type::short_24_hour_time_format),
+ boost::as_literal(formats_type::short_24_hour_time_expanded_format));
+
       string_type frac_str;
       if (format.find(seconds_with_fractional_seconds_format) != string_type::npos) {
         // replace %s with %S.nnn
@@ -366,7 +397,7 @@
       }
       if (format.find(fractional_seconds_format) != string_type::npos) {
         // replace %f with nnnnnnn
- if (!frac_str.size()) {
+ if (frac_str.empty()) {
           frac_str = fractional_seconds_as_string(a_time.time_of_day(), false);
         }
         boost::algorithm::replace_all(format,
@@ -428,6 +459,14 @@
                                       positive_sign);
       }
 
+ // %T and %R have to be replaced here since they are not standard
+ boost::algorithm::replace_all(format,
+ boost::as_literal(formats_type::full_24_hour_time_format),
+ boost::as_literal(formats_type::full_24_hour_time_expanded_format));
+ boost::algorithm::replace_all(format,
+ boost::as_literal(formats_type::short_24_hour_time_format),
+ boost::as_literal(formats_type::short_24_hour_time_expanded_format));
+
       /*
        * It is possible for a time duration to span more then 24 hours.
        * Standard time_put::put is obliged to behave the same as strftime


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk