Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62450 - in trunk: boost/date_time libs/date_time/test/posix_time libs/date_time/xmldoc
From: andrey.semashev_at_[hidden]
Date: 2010-06-05 13:09:40


Author: andysem
Date: 2010-06-05 13:09:37 EDT (Sat, 05 Jun 2010)
New Revision: 62450
URL: http://svn.boost.org/trac/boost/changeset/62450

Log:
Refs #3876. Made format flags %T and %R to be processed by the library in order to support them on more platforms. Also marked some flags that are known to have similar problems in the docs.
Text files modified:
   trunk/boost/date_time/time_facet.hpp | 45 +++++++++++++
   trunk/libs/date_time/test/posix_time/testtime_facet.cpp | 19 ++++++
   trunk/libs/date_time/xmldoc/changes.xml | 24 +++++++
   trunk/libs/date_time/xmldoc/format_flags.xml | 122 ++++++++++++++++++++++-----------------
   4 files changed, 153 insertions(+), 57 deletions(-)

Modified: trunk/boost/date_time/time_facet.hpp
==============================================================================
--- trunk/boost/date_time/time_facet.hpp (original)
+++ trunk/boost/date_time/time_facet.hpp 2010-06-05 13:09:37 EDT (Sat, 05 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

Modified: trunk/libs/date_time/test/posix_time/testtime_facet.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime_facet.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime_facet.cpp 2010-06-05 13:09:37 EDT (Sat, 05 Jun 2010)
@@ -108,6 +108,25 @@
       ss << long_td;
       check("Long time durations", ss.str() == std::string("300:02:01"));
       ss.str("");
+
+ // Short-hand format specifiers
+ f->format("%T");
+ f->time_duration_format("%T");
+ ss << t;
+ check("Short-hand '%T' in time format", ss.str() == std::string("18:01:56"));
+ ss.str("");
+ ss << td;
+ check("Short-hand '%T' in time_duration format", ss.str() == std::string("03:02:01"));
+ ss.str("");
+
+ f->format("%R");
+ f->time_duration_format("%R");
+ ss << t;
+ check("Short-hand '%R' in time format", ss.str() == std::string("18:01"));
+ ss.str("");
+ ss << td;
+ check("Short-hand '%R' in time_duration format", ss.str() == std::string("03:02"));
+ ss.str("");
     }
     { // negative time_duration tests
       std::string result;

Modified: trunk/libs/date_time/xmldoc/changes.xml
==============================================================================
--- trunk/libs/date_time/xmldoc/changes.xml (original)
+++ trunk/libs/date_time/xmldoc/changes.xml 2010-06-05 13:09:37 EDT (Sat, 05 Jun 2010)
@@ -12,6 +12,30 @@
 
   <!-- if each new change tgroup has a "Bug Fix" as the first "Type", the columns will line up nicely -->
 
+ <bridgehead renderas="sect3">Changes from Boost 1.41 to 1.44 (date_time 1.08 to 1.09)</bridgehead>
+ <informaltable frame="all">
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+
+ <row>
+ <entry>Bug fix</entry>
+ <entry>
+ The "%T" and "%R" format specifiers are now processed by the library rather than underlying standard facet.
+ This fixes the cases when the placeholders are not supported by the facet
+ (<ulink url="https://svn.boost.org/trac/boost/ticket/3876">#3876</ulink>).
+ </entry>
+ </row>
+
+ </tbody>
+ </tgroup>
+ </informaltable>
+
   <bridgehead renderas="sect3">Changes from Boost 1.40 to 1.41 (date_time 1.07 to 1.08)</bridgehead>
   <informaltable frame="all">
     <tgroup cols="2">

Modified: trunk/libs/date_time/xmldoc/format_flags.xml
==============================================================================
--- trunk/libs/date_time/xmldoc/format_flags.xml (original)
+++ trunk/libs/date_time/xmldoc/format_flags.xml 2010-06-05 13:09:37 EDT (Sat, 05 Jun 2010)
@@ -11,10 +11,10 @@
   <title>Format Flags</title>
 
   <para>Many of the format flags this new system uses for output are those used by <code>strftime(...)</code>, but not all. Some new flags have been added, and others overridden. The input system supports only specific flags, therefore, not all flags that work for output will work with input (we are currently working to correct this situation).</para>
-
- <para>The following tables list the all the flags available for both date_time IO as well as strftime. Format flags marked with a single asterisk (*) have a behavior unique to date_time. Those flags marked with an exclamation point (!) are not usable for input (at this time). The first table is for dates, and the second table is for times.
+
+ <para>The following tables list the all the flags available for both date_time IO as well as strftime. Format flags marked with a single asterisk (*) have a behavior unique to date_time. Those flags marked with an exclamation point (!) are not usable for input (at this time). The flags marked with a hash sign (#) are implemented by system locale and are known to be missing on some platforms. The first table is for dates, and the second table is for times.
   </para>
-
+
   <para>
     <anchor id="date_time_io.date_format_flags" />
     Date Facet Format Flags
@@ -71,7 +71,7 @@
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%C !</screen></entry>
+ <entry valign="top" morerows="1"><screen>%C !#</screen></entry>
             <entry>The century number (year/100) as a 2-digit integer.</entry>
           </row>
           <row>
@@ -87,15 +87,15 @@
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%D !</screen></entry>
+ <entry valign="top" morerows="1"><screen>%D !#</screen></entry>
             <entry>Equivalent to %m/%d/%y</entry>
           </row>
           <row>
             <entry><screen></screen></entry>
           </row>
-
+
           <row>
- <entry valign="top" morerows="1"><screen>%e</screen></entry>
+ <entry valign="top" morerows="1"><screen>%e #</screen></entry>
             <entry>Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space</entry>
           </row>
           <row>
@@ -119,7 +119,7 @@
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%h !</screen></entry>
+ <entry valign="top" morerows="1"><screen>%h !#</screen></entry>
             <entry> Equivalent to %b</entry>
           </row>
           <row>
@@ -156,14 +156,14 @@
           </row>
           <row>
             <entry><screen>date d(2005, Jan, 1); // Saturday
- // with format %U
- ss &lt;&lt; d; // "00"
- d += day(1); // Sunday
- ss &lt;&lt; d; // "01" beginning of week 1</screen></entry>
+// with format %U
+ss &lt;&lt; d; // "00"
+d += day(1); // Sunday
+ss &lt;&lt; d; // "01" beginning of week 1</screen></entry>
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%V !</screen></entry>
+ <entry valign="top" morerows="1"><screen>%V !#</screen></entry>
             <entry>The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.</entry>
           </row>
           <row>
@@ -184,10 +184,10 @@
           </row>
           <row>
             <entry><screen>date d(2005, Jan, 2); // Sunday
- // with format %W
- ss &lt;&lt; d; // "00"
- d += day(1); // Monday
- ss &lt;&lt; d; // "01" beginning of week 1</screen></entry>
+// with format %W
+ss &lt;&lt; d; // "00"
+d += day(1); // Monday
+ss &lt;&lt; d; // "01" beginning of week 1</screen></entry>
           </row>
 
           <row>
@@ -196,15 +196,15 @@
           </row>
           <row>
             <entry><screen>date d(2005,Oct,31);
- date_facet* f = new date_facet("%x");
-
- locale loc = locale(locale("en_US"), f);
- cout.imbue(loc);
- cout &lt;&lt; d; // "10/31/2005"
-
- loc = locale(locale("de_DE"), f);
- cout.imbue(loc);
- cout &lt;&lt; d; // "31.10.2005"</screen></entry>
+date_facet* f = new date_facet("%x");
+
+locale loc = locale(locale("en_US"), f);
+cout.imbue(loc);
+cout &lt;&lt; d; // "10/31/2005"
+
+loc = locale(locale("de_DE"), f);
+cout.imbue(loc);
+cout &lt;&lt; d; // "31.10.2005"</screen></entry>
           </row>
 
           <row>
@@ -296,21 +296,20 @@
           </row>
           <row>
             <entry><screen>"13:15:16"
- "05:04:03.001234"
- </screen></entry>
+"05:04:03.001234"</screen></entry>
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%O</screen></entry>
- <entry>The number of hours in a time duration as a decimal number (range 0 to max. representable duration); single digits are preceded by a zero.</entry>
+ <entry valign="top" morerows="1"><screen>%H</screen></entry>
+ <entry>The hour as a decimal number using a 24-hour clock (range 00 to 23).</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
             <entry valign="top" morerows="1"><screen>%I !</screen></entry>
- <entry>The hour as a decimal number using a 12-hour clock</entry>
+ <entry>The hour as a decimal number using a 12-hour clock (range 01 to 12).</entry>
           </row>
           <row>
             <entry></entry>
@@ -321,7 +320,7 @@
             <entry>The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
@@ -329,7 +328,23 @@
             <entry>The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
+ </row>
+
+ <row>
+ <entry valign="top" morerows="1"><screen>%M</screen></entry>
+ <entry>The minute as a decimal number (range 00 to 59).</entry>
+ </row>
+ <row>
+ <entry></entry>
+ </row>
+
+ <row>
+ <entry valign="top" morerows="1"><screen>%O</screen></entry>
+ <entry>The number of hours in a time duration as a decimal number (range 0 to max. representable duration); single digits are preceded by a zero.</entry>
+ </row>
+ <row>
+ <entry></entry>
           </row>
 
           <row>
@@ -337,23 +352,23 @@
             <entry>Either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale.</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%P !</screen></entry>
+ <entry valign="top" morerows="1"><screen>%P !#</screen></entry>
             <entry>Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
- <entry valign="top" morerows="1"><screen>%r !</screen></entry>
+ <entry valign="top" morerows="1"><screen>%r !#</screen></entry>
             <entry>The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to `%I:%M:%S %p'</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
@@ -361,7 +376,7 @@
             <entry>The time in 24-hour notation (%H:%M)</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
@@ -385,7 +400,7 @@
             <entry>The time in 24-hour notation (%H:%M:%S)</entry>
           </row>
           <row>
- <entry><screen></screen></entry>
+ <entry></entry>
           </row>
 
           <row>
@@ -434,16 +449,16 @@
           </row>
           <row>
             <entry><screen>date d(2005,Oct,31);
- ptime pt(d, hours(20));
- time_facet* f = new time_facet("%x %X");
-
- locale loc = locale(locale("en_US"), f);
- cout.imbue(loc);
- cout &lt;&lt; pt; // "10/31/2005 08:00:00 PM"
-
- loc = locale(locale("de_DE"), f);
- cout.imbue(loc);
- cout &lt;&lt; pt; // "31.10.2005 20:00:00"</screen></entry>
+ptime pt(d, hours(20));
+time_facet* f = new time_facet("%x %X");
+
+locale loc = locale(locale("en_US"), f);
+cout.imbue(loc);
+cout &lt;&lt; pt; // "10/31/2005 08:00:00 PM"
+
+loc = locale(locale("de_DE"), f);
+cout.imbue(loc);
+cout &lt;&lt; pt; // "31.10.2005 20:00:00"</screen></entry>
           </row>
 
           <row>
@@ -451,9 +466,7 @@
             <entry>ISO format</entry>
           </row>
           <row>
- <entry><screen>"20051015T131211-0700"
- // Oct 15, 2005 13:12:11 MST
- </screen></entry>
+ <entry><screen>"20051015T131211-0700" // Oct 15, 2005 13:12:11 MST</screen></entry>
           </row>
 
           <row>
@@ -501,5 +514,6 @@
     </informaltable>
   </para>
   <para>* Signifies flags that have a behavior unique to <code>date_time</code>.</para>
+ <para># Signifies flags that have a platform-dependent behavior. These may not be supported everywhere.</para>
   <para>! Signifies flags that currently do not work for input.</para>
 </section>


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