Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49505 - in trunk/boost/date_time: . gregorian local_time posix_time
From: andrey.semashev_at_[hidden]
Date: 2008-11-01 06:34:08


Author: andysem
Date: 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
New Revision: 49505
URL: http://svn.boost.org/trac/boost/changeset/49505

Log:
Fixed various issues, including missing includes, missing IO operators
for local time, windows.h inclusion on Windows, compilation failure on
GCC 4.3, a number of warnings on GCC and MSVC. Added a new format
specifier %O to format and read more than 99 hours in time durations.
All exception throwing moved to boost::throw_exception in order to
support builds with exceptions disabled.

Text files modified:
   trunk/boost/date_time/c_local_time_adjustor.hpp | 8
   trunk/boost/date_time/c_time.hpp | 19 ++
   trunk/boost/date_time/compiler_config.hpp | 28 ++++
   trunk/boost/date_time/constrained_value.hpp | 47 +++++--
   trunk/boost/date_time/date_duration.hpp | 25 ++--
   trunk/boost/date_time/date_facet.hpp | 25 ++-
   trunk/boost/date_time/date_generator_parser.hpp | 101 ++++++++--------
   trunk/boost/date_time/date_generators.hpp | 24 ++--
   trunk/boost/date_time/date_parsing.hpp | 56 ++++----
   trunk/boost/date_time/filetime_functions.hpp | 149 +++++++++++++++++++-----
   trunk/boost/date_time/format_date_parser.hpp | 20 ++
   trunk/boost/date_time/gregorian/conversion.hpp | 25 ++-
   trunk/boost/date_time/gregorian/greg_date.hpp | 11 +
   trunk/boost/date_time/gregorian/greg_duration.hpp | 114 +++++++++++++++++-
   trunk/boost/date_time/gregorian/greg_duration_types.hpp | 21 ++-
   trunk/boost/date_time/gregorian/greg_facet.hpp | 19 +-
   trunk/boost/date_time/gregorian/greg_serialize.hpp | 4
   trunk/boost/date_time/gregorian/gregorian_io.hpp | 13 +
   trunk/boost/date_time/int_adapter.hpp | 4
   trunk/boost/date_time/local_time/local_date_time.hpp | 52 ++++----
   trunk/boost/date_time/local_time/local_time_io.hpp | 83 ++++++++++++-
   trunk/boost/date_time/local_time/posix_time_zone.hpp | 49 ++++---
   trunk/boost/date_time/local_time_adjustor.hpp | 27 ++-
   trunk/boost/date_time/microsec_time_clock.hpp | 149 +++++-------------------
   trunk/boost/date_time/period_parser.hpp | 8
   trunk/boost/date_time/posix_time/conversion.hpp | 12 +
   trunk/boost/date_time/posix_time/posix_time_io.hpp | 22 +--
   trunk/boost/date_time/time.hpp | 7
   trunk/boost/date_time/time_defs.hpp | 12 +
   trunk/boost/date_time/time_facet.hpp | 236 +++++++++++++++++++++++++--------------
   trunk/boost/date_time/time_formatting_streams.hpp | 11 +
   trunk/boost/date_time/time_system_split.hpp | 16 -
   trunk/boost/date_time/tz_db_base.hpp | 34 +++--
   trunk/boost/date_time/wrapping_int.hpp | 34 +++--
   34 files changed, 910 insertions(+), 555 deletions(-)

Modified: trunk/boost/date_time/c_local_time_adjustor.hpp
==============================================================================
--- trunk/boost/date_time/c_local_time_adjustor.hpp (original)
+++ trunk/boost/date_time/c_local_time_adjustor.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -14,7 +14,9 @@
 */
 
 #include <stdexcept>
-#include "boost/date_time/c_time.hpp"
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/c_time.hpp>
 
 namespace boost {
 namespace date_time {
@@ -35,14 +37,14 @@
       date_type time_t_start_day(1970,1,1);
       time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0));
       if (t < time_t_start_time) {
- throw std::out_of_range("Cannot convert dates prior to Jan 1, 1970");
+ boost::throw_exception(std::out_of_range("Cannot convert dates prior to Jan 1, 1970"));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_t_start_time); // should never reach
       }
       date_duration_type dd = t.date() - time_t_start_day;
       time_duration_type td = t.time_of_day();
       std::time_t t2 = dd.days()*86400 + td.hours()*3600 + td.minutes()*60 + td.seconds();
       std::tm tms, *tms_ptr;
       tms_ptr = c_time::localtime(&t2, &tms);
- //tms_ptr = std::localtime(&t2);
       date_type d(static_cast<unsigned short>(tms_ptr->tm_year + 1900),
                   static_cast<unsigned short>(tms_ptr->tm_mon + 1),
                   static_cast<unsigned short>(tms_ptr->tm_mday));

Modified: trunk/boost/date_time/c_time.hpp
==============================================================================
--- trunk/boost/date_time/c_time.hpp (original)
+++ trunk/boost/date_time/c_time.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -14,10 +14,12 @@
   Provide workarounds related to the ctime header
 */
 
-#include "boost/date_time/compiler_config.hpp"
 #include <ctime>
-//Work around libraries that don't put time_t and time in namespace std
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/compiler_config.hpp>
 
+//Work around libraries that don't put time_t and time in namespace std
 #ifdef BOOST_NO_STDC_NAMESPACE
 namespace std { using ::time_t; using ::time; using ::localtime;
                 using ::tm; using ::gmtime; }
@@ -40,7 +42,10 @@
    * user created std::tm struct whereas the regular functions use a
    * staticly created struct and return a pointer to that. These wrapper
    * functions require the user to create a std::tm struct and send in a
- * pointer to it. A pointer to the user created struct will be returned. */
+ * pointer to it. A pointer to the user created struct will be returned.
+ * All functions do proper checking of the C function results and throw
+ * exceptions on error. Therefore the functions will never return NULL.
+ */
   struct c_time {
     public:
 #if defined(BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS)
@@ -50,6 +55,8 @@
       {
         // localtime_r() not in namespace std???
         result = localtime_r(t, result);
+ if (!result)
+ boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
         return result;
       }
       //! requires a pointer to a user created std::tm struct
@@ -58,6 +65,8 @@
       {
         // gmtime_r() not in namespace std???
         result = gmtime_r(t, result);
+ if (!result)
+ boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
         return result;
       }
 #else // BOOST_HAS_THREADS
@@ -71,6 +80,8 @@
       static std::tm* localtime(const std::time_t* t, std::tm* result)
       {
         result = std::localtime(t);
+ if (!result)
+ boost::throw_exception(std::runtime_error("could not convert calendar time to local time"));
         return result;
       }
       //! requires a pointer to a user created std::tm struct
@@ -78,6 +89,8 @@
       static std::tm* gmtime(const std::time_t* t, std::tm* result)
       {
         result = std::gmtime(t);
+ if (!result)
+ boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
         return result;
       }
 #if (defined(_MSC_VER) && (_MSC_VER >= 1400))

Modified: trunk/boost/date_time/compiler_config.hpp
==============================================================================
--- trunk/boost/date_time/compiler_config.hpp (original)
+++ trunk/boost/date_time/compiler_config.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -8,7 +8,9 @@
  * $Date$
  */
 
- #include "boost/detail/workaround.hpp"
+#include <cstdlib>
+#include <boost/config.hpp>
+#include <boost/detail/workaround.hpp>
 
 // With boost release 1.33, date_time will be using a different,
 // more flexible, IO system. This new system is not compatible with
@@ -26,7 +28,7 @@
 
 // This file performs some local compiler configurations
 
-#include "boost/date_time/locale_config.hpp" //set up locale configurations
+#include <boost/date_time/locale_config.hpp> //set up locale configurations
 
 //Set up a configuration parameter for platforms that have
 //GetTimeOfDay
@@ -49,7 +51,7 @@
 #endif
 
 // include these types before we try to re-define them
-#include "boost/cstdint.hpp"
+#include <boost/cstdint.hpp>
 
 //Define INT64_C for compilers that don't have it
 #if (!defined(INT64_C))
@@ -85,6 +87,26 @@
 #define BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS
 #endif
 
+// The macro marks up places where compiler complains for missing return statement or
+// uninitialized variables after calling to boost::throw_exception.
+// BOOST_UNREACHABLE_RETURN doesn't work since even compilers that support
+// unreachable statements detection emit such warnings.
+#if defined(_MSC_VER)
+// Use special MSVC extension to markup unreachable code
+# define BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(x) __assume(false)
+#elif !defined(BOOST_NO_UNREACHABLE_RETURN_DETECTION)
+// Call to a non-returning function should suppress the warning
+# if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std {
+ using ::abort;
+}
+# endif // defined(BOOST_NO_STDC_NAMESPACE)
+# define BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(x) std::abort()
+#else
+// For other poor compilers the specified expression is compiled. Usually, this would be a return statement.
+# define BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(x) x
+#endif
+
 /* The following handles the definition of the necessary macros
  * for dll building on Win32 platforms.
  *

Modified: trunk/boost/date_time/constrained_value.hpp
==============================================================================
--- trunk/boost/date_time/constrained_value.hpp (original)
+++ trunk/boost/date_time/constrained_value.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,7 +9,12 @@
  * $Date$
  */
 
+#include <exception>
+#include <stdexcept>
 #include <boost/config.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/is_base_of.hpp>
 
 namespace boost {
 
@@ -38,21 +43,21 @@
   public:
     typedef typename value_policies::value_type value_type;
     // typedef except_type exception_type;
- constrained_value(value_type value)
+ constrained_value(value_type value) : value_((min)())
     {
       assign(value);
- };
- constrained_value& operator=(value_type v)
- {
+ }
+ constrained_value& operator=(value_type v)
+ {
       assign(v);
       return *this;
- }
+ }
     //! Return the max allowed value (traits method)
- static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::max)();};
+ static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::max)();}
     //! Return the min allowed value (traits method)
- static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::min)();};
+ static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::min)();}
     //! Coerce into the representation type
- operator value_type() const {return value_;};
+ operator value_type() const {return value_;}
   protected:
     value_type value_;
   private:
@@ -69,7 +74,6 @@
         return;
       }
       value_ = value;
-
     }
 };
 
@@ -78,13 +82,32 @@
            rep_type max_value, class exception_type>
   class simple_exception_policy
   {
+ struct exception_wrapper : public exception_type
+ {
+ // In order to support throw_exception mechanism in the BOOST_NO_EXCEPTIONS mode,
+ // we'll have to provide a way to acquire std::exception from the exception being thrown.
+ // However, we cannot derive from it, since it would make it interceptable by this class,
+ // which might not be what the user wanted.
+ operator std::out_of_range () const
+ {
+ // TODO: Make the message more descriptive by using arguments to on_error
+ return std::out_of_range("constrained value boundary has been violated");
+ }
+ };
+
+ typedef typename mpl::if_<
+ is_base_of< std::exception, exception_type >,
+ exception_type,
+ exception_wrapper
+ >::type actual_exception_type;
+
   public:
     typedef rep_type value_type;
- static rep_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return min_value; };
- static rep_type max BOOST_PREVENT_MACRO_SUBSTITUTION () { return max_value;};
+ static rep_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return min_value; }
+ static rep_type max BOOST_PREVENT_MACRO_SUBSTITUTION () { return max_value; }
     static void on_error(rep_type, rep_type, violation_enum)
     {
- throw exception_type();
+ boost::throw_exception(actual_exception_type());
     }
   };
 

Modified: trunk/boost/date_time/date_duration.hpp
==============================================================================
--- trunk/boost/date_time/date_duration.hpp (original)
+++ trunk/boost/date_time/date_duration.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -11,6 +11,7 @@
 
 
 #include <boost/operators.hpp>
+#include <boost/date_time/special_defs.hpp>
 
 namespace boost {
 namespace date_time {
@@ -19,11 +20,12 @@
   //! Duration type with date level resolution
   template<class duration_rep_traits>
   class date_duration : private
- boost::less_than_comparable<date_duration< duration_rep_traits>
- , boost::equality_comparable< date_duration< duration_rep_traits>
- , boost::addable< date_duration< duration_rep_traits>
- , boost::subtractable< date_duration< duration_rep_traits>
- > > > >
+ boost::less_than_comparable1< date_duration< duration_rep_traits >
+ , boost::equality_comparable1< date_duration< duration_rep_traits >
+ , boost::addable1< date_duration< duration_rep_traits >
+ , boost::subtractable1< date_duration< duration_rep_traits >
+ , boost::dividable2< date_duration< duration_rep_traits >, int
+ > > > > >
   {
   public:
     typedef typename duration_rep_traits::int_type duration_rep_type;
@@ -80,40 +82,37 @@
      * so this will not compile */
 
     //! Subtract another duration -- result is signed
- date_duration operator-=(const date_duration& rhs)
+ date_duration& operator-=(const date_duration& rhs)
     {
         //days_ -= rhs.days_;
         days_ = days_ - rhs.days_;
         return *this;
     }
     //! Add a duration -- result is signed
- date_duration operator+=(const date_duration& rhs)
+ date_duration& operator+=(const date_duration& rhs)
     {
         days_ = days_ + rhs.days_;
         return *this;
     }
 
     //! unary- Allows for dd = -date_duration(2); -> dd == -2
- date_duration operator-()const
+ date_duration operator-() const
     {
         return date_duration<duration_rep_traits>(get_rep() * (-1));
     }
     //! Division operations on a duration with an integer.
- date_duration<duration_rep_traits> operator/=(int divisor)
+ date_duration& operator/=(int divisor)
     {
         days_ = days_ / divisor;
         return *this;
     }
- date_duration<duration_rep_traits> operator/(int divisor)
- {
- return date_duration<duration_rep_traits>(days_ / divisor);
- }
 
     //! return sign information
     bool is_negative() const
     {
         return days_ < 0;
     }
+
   private:
     duration_rep days_;
   };

Modified: trunk/boost/date_time/date_facet.hpp
==============================================================================
--- trunk/boost/date_time/date_facet.hpp (original)
+++ trunk/boost/date_time/date_facet.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,17 +9,21 @@
  * $Date$
  */
 
-
-#include "boost/algorithm/string/replace.hpp"
-#include "boost/date_time/period.hpp"
-#include "boost/date_time/special_values_formatter.hpp"
-#include "boost/date_time/period_formatter.hpp"
-#include "boost/date_time/period_parser.hpp"
-#include "boost/date_time/date_generator_formatter.hpp"
-#include "boost/date_time/date_generator_parser.hpp"
-#include "boost/date_time/format_date_parser.hpp"
+#include <locale>
 #include <string>
 #include <vector>
+#include <iterator> // ostreambuf_iterator
+#include <boost/throw_exception.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/period.hpp>
+#include <boost/date_time/special_defs.hpp>
+#include <boost/date_time/special_values_formatter.hpp>
+#include <boost/date_time/period_formatter.hpp>
+#include <boost/date_time/period_parser.hpp>
+#include <boost/date_time/date_generator_formatter.hpp>
+#include <boost/date_time/date_generator_parser.hpp>
+#include <boost/date_time/format_date_parser.hpp>
 
 namespace boost { namespace date_time {
 
@@ -638,7 +642,8 @@
         }
         m_sv_parser.match(from, to, mr);
         if(mr.current_match == match_results::PARSE_ERROR) {
- throw std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'");
+ boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return from); // should never reach
         }
         dd = duration_type(static_cast<special_values>(mr.current_match));
       }

Modified: trunk/boost/date_time/date_generator_parser.hpp
==============================================================================
--- trunk/boost/date_time/date_generator_parser.hpp (original)
+++ trunk/boost/date_time/date_generator_parser.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -10,12 +10,14 @@
  * $Date$
  */
 
-
-#include "boost/date_time/string_parse_tree.hpp"
-#include "boost/date_time/date_generators.hpp"
-#include "boost/date_time/format_date_parser.hpp"
 #include <string>
 #include <vector>
+#include <iterator> // istreambuf_iterator
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/string_parse_tree.hpp>
+#include <boost/date_time/date_generators.hpp>
+#include <boost/date_time/format_date_parser.hpp>
 
 namespace boost { namespace date_time {
 
@@ -66,10 +68,10 @@
     static const char_type last_string[5];
     static const char_type before_string[8];
     static const char_type after_string[6];
- static const char_type of_string[3];
-
+ static const char_type of_string[3];
+
     enum phrase_elements {first=0, second, third, fourth, fifth, last,
- before, after, of, number_of_phrase_elements};
+ before, after, of, number_of_phrase_elements};
 
     //! Creates a date_generator_parser with the default set of "element_strings"
     date_generator_parser()
@@ -96,7 +98,7 @@
                           const string_type& after_str,
                           const string_type& of_str)
     {
- element_strings(first_str, second_str, third_str, fourth_str, fifth_str,
+ element_strings(first_str, second_str, third_str, fourth_str, fifth_str,
                       last_str, before_str, after_str, of_str);
     }
 
@@ -128,19 +130,18 @@
     {
       m_element_strings = parse_tree_type(col, this->first); // enum first
     }
-
 
     //! returns partial_date parsed from stream
     template<class facet_type>
     partial_date_type
- get_partial_date_type(stream_itr_type& sitr,
+ get_partial_date_type(stream_itr_type& sitr,
                           stream_itr_type& stream_end,
- std::ios_base& a_ios,
+ std::ios_base& a_ios,
                           const facet_type& facet) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
-
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+
       day_type d(1);
       month_type m(1);
       facet.get(sitr, stream_end, a_ios, d);
@@ -152,18 +153,18 @@
     //! returns nth_kday_of_week parsed from stream
     template<class facet_type>
     nth_kday_type
- get_nth_kday_type(stream_itr_type& sitr,
+ get_nth_kday_type(stream_itr_type& sitr,
                       stream_itr_type& stream_end,
- std::ios_base& a_ios,
+ std::ios_base& a_ios,
                       const facet_type& facet) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
-
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+
       typename nth_kday_type::week_num wn;
       day_of_week_type wd(0); // no default constructor
       month_type m(1); // no default constructor
-
+
       match_results mr = m_element_strings.match(sitr, stream_end);
       switch(mr.current_match) {
         case first : { wn = nth_kday_type::first; break; }
@@ -173,98 +174,98 @@
         case fifth : { wn = nth_kday_type::fifth; break; }
         default:
         {
- throw std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'");
- break;
+ boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(wn = nth_kday_type::first);
         }
       } // week num
       facet.get(sitr, stream_end, a_ios, wd); // day_of_week
       extract_element(sitr, stream_end, of); // "of" element
       facet.get(sitr, stream_end, a_ios, m); // month
-
+
       return nth_kday_type(wn, wd, m);
     }
 
     //! returns first_kday_of_week parsed from stream
     template<class facet_type>
     first_kday_type
- get_first_kday_type(stream_itr_type& sitr,
+ get_first_kday_type(stream_itr_type& sitr,
                         stream_itr_type& stream_end,
- std::ios_base& a_ios,
+ std::ios_base& a_ios,
                         const facet_type& facet) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
-
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+
       day_of_week_type wd(0); // no default constructor
       month_type m(1); // no default constructor
-
+
       extract_element(sitr, stream_end, first); // "first" element
       facet.get(sitr, stream_end, a_ios, wd); // day_of_week
       extract_element(sitr, stream_end, of); // "of" element
       facet.get(sitr, stream_end, a_ios, m); // month
-
-
+
+
       return first_kday_type(wd, m);
     }
 
     //! returns last_kday_of_week parsed from stream
     template<class facet_type>
     last_kday_type
- get_last_kday_type(stream_itr_type& sitr,
+ get_last_kday_type(stream_itr_type& sitr,
                        stream_itr_type& stream_end,
- std::ios_base& a_ios,
+ std::ios_base& a_ios,
                        const facet_type& facet) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
-
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+
       day_of_week_type wd(0); // no default constructor
       month_type m(1); // no default constructor
-
+
       extract_element(sitr, stream_end, last); // "last" element
       facet.get(sitr, stream_end, a_ios, wd); // day_of_week
       extract_element(sitr, stream_end, of); // "of" element
       facet.get(sitr, stream_end, a_ios, m); // month
-
-
+
+
       return last_kday_type(wd, m);
     }
 
     //! returns first_kday_of_week parsed from stream
     template<class facet_type>
     kday_before_type
- get_kday_before_type(stream_itr_type& sitr,
+ get_kday_before_type(stream_itr_type& sitr,
                          stream_itr_type& stream_end,
- std::ios_base& a_ios,
+ std::ios_base& a_ios,
                          const facet_type& facet) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
-
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+
       day_of_week_type wd(0); // no default constructor
-
+
       facet.get(sitr, stream_end, a_ios, wd); // day_of_week
       extract_element(sitr, stream_end, before);// "before" element
-
+
       return kday_before_type(wd);
     }
 
     //! returns first_kday_of_week parsed from stream
     template<class facet_type>
     kday_after_type
- get_kday_after_type(stream_itr_type& sitr,
+ get_kday_after_type(stream_itr_type& sitr,
                         stream_itr_type& stream_end,
- std::ios_base& a_ios,
+ std::ios_base& a_ios,
                         const facet_type& facet) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
-
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+
       day_of_week_type wd(0); // no default constructor
-
+
       facet.get(sitr, stream_end, a_ios, wd); // day_of_week
       extract_element(sitr, stream_end, after); // "after" element
-
+
       return kday_after_type(wd);
     }
 
@@ -277,13 +278,13 @@
                          typename date_generator_parser::phrase_elements ele) const
     {
       // skip leading whitespace
- while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
+ while(std::isspace(*sitr) && sitr != stream_end) { ++sitr; }
       match_results mr = m_element_strings.match(sitr, stream_end);
       if(mr.current_match != ele) {
- throw std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'");
+ boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
       }
     }
-
+
   };
 
   template<class date_type, class CharT>

Modified: trunk/boost/date_time/date_generators.hpp
==============================================================================
--- trunk/boost/date_time/date_generators.hpp (original)
+++ trunk/boost/date_time/date_generators.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -12,10 +12,12 @@
 /*! @file date_generators.hpp
   Definition and implementation of date algorithm templates
 */
+
 #include <stdexcept>
 #include <sstream>
-#include "boost/date_time/date.hpp"
-#include "boost/date_time/compiler_config.hpp"
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/date.hpp>
+#include <boost/date_time/compiler_config.hpp>
 
 namespace boost {
 namespace date_time {
@@ -99,13 +101,11 @@
    date_type get_date(year_type y) const
    {
      if((day_ == 29) && (month_ == 2) && !(calendar_type::is_leap_year(y))) {
- std::stringstream ss("");
+ std::ostringstream ss;
        ss << "No Feb 29th in given year of " << y << ".";
- throw std::invalid_argument(ss.str());
- //return date_type(1,1,1); // should never reach
- } else {
- return date_type(y, month_, day_);
+ boost::throw_exception(std::invalid_argument(ss.str()));
      }
+ return date_type(y, month_, day_);
    }
    date_type operator()(year_type y) const
    {
@@ -141,7 +141,7 @@
     * Dec-31 == "365" */
    virtual std::string to_string() const
    {
- std::stringstream ss;
+ std::ostringstream ss;
      date_type d(2004, month_, day_);
      unsigned short c = d.day_of_year();
      c--; // numbered 0-365 while day_of_year is 1 based...
@@ -229,7 +229,7 @@
     /*! Returns a string formatted as "M4.3.0" ==> 3rd Sunday in April. */
     virtual std::string to_string() const
     {
- std::stringstream ss;
+ std::ostringstream ss;
      ss << 'M'
        << static_cast<int>(month_) << '.'
        << static_cast<int>(wn_) << '.'
@@ -275,7 +275,7 @@
         d = d + one_day;
       }
       return d;
- }
+ }
     // added for streaming
     month_type month() const
     {
@@ -289,7 +289,7 @@
     /*! Returns a string formatted as "M4.1.0" ==> 1st Sunday in April. */
     virtual std::string to_string() const
     {
- std::stringstream ss;
+ std::ostringstream ss;
      ss << 'M'
        << static_cast<int>(month_) << '.'
        << 1 << '.'
@@ -350,7 +350,7 @@
     /*! Returns a string formatted as "M4.5.0" ==> last Sunday in April. */
     virtual std::string to_string() const
     {
- std::stringstream ss;
+ std::ostringstream ss;
       ss << 'M'
          << static_cast<int>(month_) << '.'
          << 5 << '.'

Modified: trunk/boost/date_time/date_parsing.hpp
==============================================================================
--- trunk/boost/date_time/date_parsing.hpp (original)
+++ trunk/boost/date_time/date_parsing.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,15 +9,15 @@
  * $Date$
  */
 
-#include "boost/tokenizer.hpp"
-#include "boost/lexical_cast.hpp"
-#include "boost/date_time/compiler_config.hpp"
-#include "boost/date_time/parse_format_base.hpp"
 #include <string>
 #include <iterator>
 #include <algorithm>
+#include <boost/tokenizer.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/parse_format_base.hpp>
 
-#if defined(BOOST_NO_STD_LOCALE)
+#if defined(BOOST_DATE_TIME_NO_LOCALE)
 #include <cctype> // ::tolower(int)
 #else
 #include <locale> // std::tolower(char, locale)
@@ -34,38 +34,38 @@
    */
   inline
   std::string
- convert_to_lower(const std::string& inp) {
- std::string tmp;
- unsigned i = 0;
-#if defined(BOOST_NO_STD_LOCALE)
- while(i < inp.length()) {
- tmp += static_cast<char>(std::tolower(inp.at(i++)));
+ convert_to_lower(std::string inp)
+ {
+#if !defined(BOOST_DATE_TIME_NO_LOCALE)
+ const std::locale loc(std::locale::classic());
+#endif
+ std::string::size_type i = 0, n = inp.length();
+ for (; i < n; ++i) {
+ inp[i] =
+#if defined(BOOST_DATE_TIME_NO_LOCALE)
+ static_cast<char>(std::tolower(inp[i]));
 #else
- static const std::locale loc(std::locale::classic());
- while(i < inp.length()) {
         // tolower and others were brought in to std for borland >= v564
         // in compiler_config.hpp
- std::string::value_type c(inp.at(i++));
- tmp += std::tolower(c, loc);
+ std::tolower(inp[i], loc);
 #endif
-
- }
- return tmp;
     }
-
+ return inp;
+ }
+
     //! Helper function for parse_date.
     /* Used by-value parameter because we change the string and may
      * want to preserve the original argument */
     template<class month_type>
- unsigned short
- month_str_to_ushort(std::string s) {
+ inline unsigned short
+ month_str_to_ushort(std::string const& s) {
       if((s.at(0) >= '0') && (s.at(0) <= '9')) {
         return boost::lexical_cast<unsigned short>(s);
       }
       else {
- s = convert_to_lower(s);
+ std::string str = convert_to_lower(s);
         typename month_type::month_map_ptr_type ptr = month_type::get_month_map_ptr();
- typename month_type::month_map_type::iterator iter = ptr->find(s);
+ typename month_type::month_map_type::iterator iter = ptr->find(str);
         if(iter != ptr->end()) { // required for STLport
           return iter->second;
         }
@@ -101,7 +101,7 @@
     template<class date_type>
     date_type
     parse_date(const std::string& s, int order_spec = ymd_order_iso) {
- std::string spec_str("");
+ std::string spec_str;
       if(order_spec == ymd_order_iso) {
         spec_str = "ymd";
       }
@@ -196,7 +196,7 @@
                      iterator_type& end,
                      char)
     {
- std::stringstream ss("");
+ std::ostringstream ss;
       while(beg != end) {
         ss << *beg++;
       }
@@ -228,7 +228,7 @@
                                iterator_type& end,
                                wchar_t)
     {
- std::stringstream ss("");
+ std::ostringstream ss;
       while(beg != end) {
 #if !defined(BOOST_DATE_TIME_NO_LOCALE)
         ss << std::use_facet<std::ctype<wchar_t> >(std::locale()).narrow(*beg++, 'X'); // 'X' will cause exception to be thrown
@@ -249,7 +249,7 @@
                      iterator_type& end,
                      std::wstring) {
       std::wstring ws = *beg;
- std::stringstream ss("");
+ std::ostringstream ss;
       std::wstring::iterator wsb = ws.begin(), wse = ws.end();
       while(wsb != wse) {
 #if !defined(BOOST_DATE_TIME_NO_LOCALE)
@@ -289,7 +289,7 @@
       return period<date_type, typename date_type::duration_type>(d1, d2);
     }
 #endif
-
+
 } } //namespace date_time
 
 

Modified: trunk/boost/date_time/filetime_functions.hpp
==============================================================================
--- trunk/boost/date_time/filetime_functions.hpp (original)
+++ trunk/boost/date_time/filetime_functions.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -16,59 +16,138 @@
  */
 
 #include <boost/date_time/compiler_config.hpp>
+
 #if defined(BOOST_HAS_FTIME) // skip this file if no FILETIME
-#include <windows.h>
+
+#if defined(BOOST_USE_WINDOWS_H)
+# include <windows.h>
+#endif
+
 #include <boost/cstdint.hpp>
 #include <boost/date_time/time.hpp>
 
-
 namespace boost {
 namespace date_time {
 
+namespace winapi {
+
+#if !defined(BOOST_USE_WINDOWS_H)
+
+extern "C" {
+
+ struct FILETIME
+ {
+ boost::uint32_t dwLowDateTime;
+ boost::uint32_t dwHighDateTime;
+ };
+ struct SYSTEMTIME
+ {
+ boost::uint16_t wYear;
+ boost::uint16_t wMonth;
+ boost::uint16_t wDayOfWeek;
+ boost::uint16_t wDay;
+ boost::uint16_t wHour;
+ boost::uint16_t wMinute;
+ boost::uint16_t wSecond;
+ boost::uint16_t wMilliseconds;
+ };
+
+ __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(FILETIME* lpFileTime);
+ __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const FILETIME* lpFileTime, FILETIME* lpLocalFileTime);
+ __declspec(dllimport) void __stdcall GetSystemTime(SYSTEMTIME* lpSystemTime);
+ __declspec(dllimport) int __stdcall SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime, FILETIME* lpFileTime);
+
+} // extern "C"
+
+#endif // defined(BOOST_USE_WINDOWS_H)
+
+ typedef FILETIME file_time;
+ typedef SYSTEMTIME system_time;
+
+ inline void get_system_time_as_file_time(file_time& ft)
+ {
+#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
+ // Some runtime library implementations expect local times as the norm for ctime.
+ file_time ft_utc;
+ GetSystemTimeAsFileTime(&ft_utc);
+ FileTimeToLocalFileTime(&ft_utc, &ft);
+#elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME)
+ system_time st;
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, ftp);
+#else
+ GetSystemTimeAsFileTime(&ft);
+#endif
+ }
+
+ /*!
+ * The function converts file_time into number of nanoseconds elapsed since 1970-Jan-01
+ *
+ * \note The function is templated on the FILETIME type, so that
+ * it can be used with both native FILETIME and the ad-hoc
+ * boost::date_time::winapi::file_time type.
+ */
+ template< typename FileTimeT >
+ inline boost::uint64_t file_time_to_nanoseconds(FileTimeT const& ft)
+ {
+ /* shift is difference between 1970-Jan-01 & 1601-Jan-01
+ * in 100-nanosecond intervals */
+ const uint64_t c1 = 27111902UL;
+ const uint64_t c2 = 3577643008UL; // issues warning without 'UL'
+ const uint64_t shift = (c1 << 32) + c2;
+
+ union {
+ FileTimeT as_file_time;
+ uint64_t as_integer;
+ } caster;
+ caster.as_file_time = ft;
+
+ caster.as_integer -= shift; // filetime is now 100-nanos since 1970-Jan-01
+ return (caster.as_integer * 100); // upscale to nanoseconds
+ }
+
+} // namespace winapi
 
   //! Create a time object from an initialized FILETIME struct.
- /*! Create a time object from an initialized FILETIME struct.
+ /*!
+ * Create a time object from an initialized FILETIME struct.
    * A FILETIME struct holds 100-nanosecond units (0.0000001). When
- * built with microsecond resolution the FILETIME's sub second value
- * will be truncated. Nanosecond resolution has no truncation. */
- template<class time_type>
+ * built with microsecond resolution the file_time's sub second value
+ * will be truncated. Nanosecond resolution has no truncation.
+ *
+ * \note The function is templated on the FILETIME type, so that
+ * it can be used with both native FILETIME and the ad-hoc
+ * boost::date_time::winapi::file_time type.
+ */
+ template< typename TimeT, typename FileTimeT >
   inline
- time_type time_from_ftime(const FILETIME& ft){
- typedef typename time_type::date_type date_type;
- typedef typename time_type::date_duration_type date_duration_type;
- typedef typename time_type::time_duration_type time_duration_type;
-
- /* OFFSET is difference between 1970-Jan-01 & 1601-Jan-01
- * in 100-nanosecond intervals */
- uint64_t c1 = 27111902UL;
- uint64_t c2 = 3577643008UL; // issues warning without 'UL'
- const uint64_t OFFSET = (c1 << 32) + c2;
- const long sec_pr_day = 86400; // seconds per day
-
- uint64_t filetime = ft.dwHighDateTime;
- filetime <<= 32;
- filetime += ft.dwLowDateTime;
- filetime -= OFFSET; // filetime is now 100-nanos since 1970-Jan-01
-
- uint64_t sec = filetime / 10000000;
-#if defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
- uint64_t sub_sec = (filetime % 10000000) * 100; // nanoseconds
-#else
- uint64_t sub_sec = (filetime % 10000000) / 10; // truncate to microseconds
+ TimeT time_from_ftime(const FileTimeT& ft)
+ {
+ typedef typename TimeT::date_type date_type;
+ typedef typename TimeT::date_duration_type date_duration_type;
+ typedef typename TimeT::time_duration_type time_duration_type;
+
+ uint64_t nanos = winapi::file_time_to_nanoseconds(ft);
+
+ uint64_t sec = nanos / 1000000000UL;
+ uint32_t sub_sec = (nanos % 1000000000UL); // nanoseconds since the last second
+#if !defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
+ sub_sec /= 1000; // truncate to microseconds
 #endif
 
     // split sec into usable chunks: days, hours, minutes, & seconds
- long _d = sec / sec_pr_day;
- long tmp = sec % sec_pr_day;
- long _h = tmp / 3600; // sec_pr_hour
+ const uint32_t sec_per_day = 86400; // seconds per day
+ uint32_t days = static_cast< uint32_t >(sec / sec_per_day);
+ uint32_t tmp = static_cast< uint32_t >(sec % sec_per_day);
+ uint32_t hours = tmp / 3600; // sec_per_hour
     tmp %= 3600;
- long _m = tmp / 60; // sec_pr_min
+ uint32_t minutes = tmp / 60; // sec_per_min
     tmp %= 60;
- long _s = tmp; // seconds
+ uint32_t seconds = tmp; // seconds
 
- date_duration_type dd(_d);
+ date_duration_type dd(days);
     date_type d = date_type(1970, Jan, 01) + dd;
- return time_type(d, time_duration_type(_h, _m, _s, sub_sec));
+ return TimeT(d, time_duration_type(hours, minutes, seconds, sub_sec));
   }
 
 }} // boost::date_time

Modified: trunk/boost/date_time/format_date_parser.hpp
==============================================================================
--- trunk/boost/date_time/format_date_parser.hpp (original)
+++ trunk/boost/date_time/format_date_parser.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -17,7 +17,20 @@
 #include "boost/date_time/special_values_parser.hpp"
 #include <string>
 #include <vector>
+#include <sstream>
+#include <iterator>
+#ifndef BOOST_NO_STDC_NAMESPACE
+# include <cctype>
+#else
+# include <ctype.h>
+#endif
 
+#ifdef BOOST_NO_STDC_NAMESPACE
+namespace std {
+ using ::isspace;
+ using ::isdigit;
+}
+#endif
 namespace boost { namespace date_time {
   
 //! Helper function for parsing fixed length strings into integers
@@ -57,7 +70,7 @@
   }
   try {
     i = boost::lexical_cast<int_type>(mr.cache);
- }catch(bad_lexical_cast blc){
+ }catch(bad_lexical_cast&){
     // we want to return -1 if the cast fails so nothing to do here
   }
   return i;
@@ -139,7 +152,7 @@
 {
  public:
   typedef std::basic_string<charT> string_type;
- typedef std::basic_ostringstream<charT> stringstream_type;
+ typedef std::basic_istringstream<charT> stringstream_type;
   typedef std::istreambuf_iterator<charT> stream_itr_type;
   typedef typename string_type::const_iterator const_itr;
   typedef typename date_type::year_type year_type;
@@ -216,8 +229,7 @@
              const string_type& format_str,
              const special_values_parser<date_type,charT>& sv_parser) const
   {
- stringstream_type ss;
- ss << value;
+ stringstream_type ss(value);
     stream_itr_type sitr(ss);
     stream_itr_type stream_end;
     return parse_date(sitr, stream_end, format_str, sv_parser);

Modified: trunk/boost/date_time/gregorian/conversion.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/conversion.hpp (original)
+++ trunk/boost/date_time/gregorian/conversion.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,18 +9,20 @@
  * $Date$
  */
 
-#include <exception>
-#include "boost/date_time/gregorian/gregorian_types.hpp"
-#include "boost/date_time/c_time.hpp"
+#include <string>
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/gregorian/gregorian_types.hpp>
+#include <boost/date_time/c_time.hpp>
 #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
 # if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
-# include "boost/date_time/gregorian/formatters_limited.hpp"
+# include <boost/date_time/gregorian/formatters_limited.hpp>
 # else
-# include "boost/date_time/gregorian/formatters.hpp"
+# include <boost/date_time/gregorian/formatters.hpp>
 # endif // BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS
 #else
 # include <sstream>
-# include "boost/date_time/gregorian/gregorian_io.hpp"
+# include <boost/date_time/gregorian/gregorian_io.hpp>
 #endif // USE_DATE_TIME_PRE_1_33_FACET_IO
 
 namespace boost {
@@ -33,14 +35,15 @@
   std::tm to_tm(const date& d)
   {
     if(d.is_pos_infinity() || d.is_neg_infinity() || d.is_not_a_date()){
+ std::string s = "tm unable to handle date value of ";
 #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
- std::string s("tm unable to handle date value of " + to_simple_string(d));
- throw std::out_of_range(s);
+ s += to_simple_string(d);
 #else
- std::stringstream ss;
- ss << "tm unable to handle date value of " << d;
- throw std::out_of_range(ss.str());
+ std::ostringstream ss;
+ ss << d;
+ s += ss.str();
 #endif // USE_DATE_TIME_PRE_1_33_FACET_IO
+ boost::throw_exception(std::out_of_range(s));
     }
     std::tm datetm;
     boost::gregorian::date::ymd_type ymd = d.year_month_day();

Modified: trunk/boost/date_time/gregorian/greg_date.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/greg_date.hpp (original)
+++ trunk/boost/date_time/gregorian/greg_date.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,10 +9,11 @@
  * $Date$
  */
 
-#include "boost/date_time/date.hpp"
-#include "boost/date_time/special_defs.hpp"
-#include "boost/date_time/gregorian/greg_calendar.hpp"
-#include "boost/date_time/gregorian/greg_duration.hpp"
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/date.hpp>
+#include <boost/date_time/special_defs.hpp>
+#include <boost/date_time/gregorian/greg_calendar.hpp>
+#include <boost/date_time/gregorian/greg_duration.hpp>
 
 namespace boost {
 namespace gregorian {
@@ -55,7 +56,7 @@
       : date_time::date<date, gregorian_calendar, date_duration>(y, m, d)
     {
       if (gregorian_calendar::end_of_month_day(y, m) < d) {
- throw bad_day_of_month(std::string("Day of month is not valid for year"));
+ boost::throw_exception(bad_day_of_month(std::string("Day of month is not valid for year")));
       }
     }
     //! Constructor from a ymd_type structure

Modified: trunk/boost/date_time/gregorian/greg_duration.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/greg_duration.hpp (original)
+++ trunk/boost/date_time/gregorian/greg_duration.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,30 +9,126 @@
  * $Date$
  */
 
-#include "boost/date_time/date_duration.hpp"
-#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
-#include "boost/date_time/date_duration_types.hpp"
-#endif
-#include "boost/date_time/int_adapter.hpp"
-
+#include <boost/date_time/date_duration.hpp>
+#include <boost/date_time/int_adapter.hpp>
+#include <boost/date_time/special_defs.hpp>
 
 namespace boost {
 namespace gregorian {
 
-
   //!An internal date representation that includes infinities, not a date
   typedef boost::date_time::duration_traits_adapted date_duration_rep;
 
   //! Durations in days for gregorian system
   /*! \ingroup date_basics
    */
- typedef date_time::date_duration<date_duration_rep> date_duration;
+ class date_duration :
+ public boost::date_time::date_duration< date_duration_rep >
+ {
+ typedef boost::date_time::date_duration< date_duration_rep > base_type;
+
+ public:
+ typedef base_type::duration_rep duration_rep;
+
+ //! Construct from a day count
+ explicit date_duration(duration_rep day_count = 0) : base_type(day_count) {}
+
+ //! construct from special_values
+ date_duration(date_time::special_values sv) : base_type(sv) {}
+
+ //! Copy constructor
+ date_duration(const date_duration& other) : base_type(static_cast< base_type const& >(other))
+ {}
+
+ //! Construct from another date_duration
+ date_duration(const base_type& other) : base_type(other)
+ {}
+
+ // Relational operators
+ // NOTE: Because of date_time::date_duration< T > design choice we don't use Boost.Operators here,
+ // because we need the class to be a direct base. Either lose EBO, or define operators by hand.
+ // The latter is more effecient.
+ bool operator== (const date_duration& rhs) const
+ {
+ return base_type::operator== (rhs);
+ }
+ bool operator!= (const date_duration& rhs) const
+ {
+ return !operator== (rhs);
+ }
+ bool operator< (const date_duration& rhs) const
+ {
+ return base_type::operator< (rhs);
+ }
+ bool operator> (const date_duration& rhs) const
+ {
+ return !(base_type::operator< (rhs) || base_type::operator== (rhs));
+ }
+ bool operator<= (const date_duration& rhs) const
+ {
+ return (base_type::operator< (rhs) || base_type::operator== (rhs));
+ }
+ bool operator>= (const date_duration& rhs) const
+ {
+ return !base_type::operator< (rhs);
+ }
+
+ //! Subtract another duration -- result is signed
+ date_duration& operator-= (const date_duration& rhs)
+ {
+ base_type::operator-= (rhs);
+ return *this;
+ }
+ friend date_duration operator- (date_duration rhs, date_duration const& lhs)
+ {
+ rhs -= lhs;
+ return rhs;
+ }
+
+ //! Add a duration -- result is signed
+ date_duration& operator+= (const date_duration& rhs)
+ {
+ base_type::operator+= (rhs);
+ return *this;
+ }
+ friend date_duration operator+ (date_duration rhs, date_duration const& lhs)
+ {
+ rhs += lhs;
+ return rhs;
+ }
+
+ //! unary- Allows for dd = -date_duration(2); -> dd == -2
+ date_duration operator- ()const
+ {
+ return date_duration(get_rep() * (-1));
+ }
+
+ //! Division operations on a duration with an integer.
+ date_duration& operator/= (int divisor)
+ {
+ base_type::operator/= (divisor);
+ return *this;
+ }
+ friend date_duration operator/ (date_duration rhs, int lhs)
+ {
+ rhs /= lhs;
+ return rhs;
+ }
+
+ //! Returns the smallest duration -- used by to calculate 'end'
+ static date_duration unit()
+ {
+ return date_duration(base_type::unit().get_rep());
+ }
+ };
 
   //! Shorthand for date_duration
   typedef date_duration days;
 
 } } //namespace gregorian
 
-
+#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
+#include <boost/date_time/date_duration_types.hpp>
+#endif
 
 #endif

Modified: trunk/boost/date_time/gregorian/greg_duration_types.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/greg_duration_types.hpp (original)
+++ trunk/boost/date_time/gregorian/greg_duration_types.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,11 +9,11 @@
  */
 
 
-#include "boost/date_time/gregorian/greg_date.hpp"
-#include "boost/date_time/int_adapter.hpp"
-#include "boost/date_time/adjust_functors.hpp"
-#include "boost/date_time/date_duration.hpp"
-#include "boost/date_time/date_duration_types.hpp"
+#include <boost/date_time/gregorian/greg_date.hpp>
+#include <boost/date_time/int_adapter.hpp>
+#include <boost/date_time/adjust_functors.hpp>
+#include <boost/date_time/date_duration_types.hpp>
+#include <boost/date_time/gregorian/greg_duration.hpp>
 
 namespace boost {
 namespace gregorian {
@@ -27,7 +27,16 @@
 
   typedef date_time::months_duration<greg_durations_config> months;
   typedef date_time::years_duration<greg_durations_config> years;
- typedef date_time::weeks_duration<date_time::duration_traits_adapted> weeks;
+
+ class weeks_duration : public date_duration {
+ public:
+ weeks_duration(duration_rep w)
+ : date_duration(w * 7) {}
+ weeks_duration(date_time::special_values sv)
+ : date_duration(sv) {}
+ };
+
+ typedef weeks_duration weeks;
 
 }} // namespace boost::gregorian
 

Modified: trunk/boost/date_time/gregorian/greg_facet.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/greg_facet.hpp (original)
+++ trunk/boost/date_time/gregorian/greg_facet.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -12,12 +12,15 @@
 #include "boost/date_time/gregorian/gregorian_types.hpp"
 #include "boost/date_time/date_formatting_locales.hpp" // sets BOOST_DATE_TIME_NO_LOCALE
 #include "boost/date_time/gregorian/parsers.hpp"
-#include <string>
-#include <exception>
 
 //This file is basically commented out if locales are not supported
 #ifndef BOOST_DATE_TIME_NO_LOCALE
 
+#include <string>
+#include <memory>
+#include <locale>
+#include <iostream>
+#include <exception>
 
 namespace boost {
 namespace gregorian {
@@ -286,14 +289,12 @@
     /* bad_cast will be thrown if the desired facet is not accessible
      * so we can generate the facet. This has the drawback of using english
      * names as a default. */
- catch(std::bad_cast bc){
- std::cout << "Month exception caught" << std::endl;
+ catch(std::bad_cast&){
       charT a = '\0';
- const facet_def* f = create_facet_def(a);
+ std::auto_ptr< const facet_def > f(create_facet_def(a));
       num = date_time::find_match(f->get_short_month_names(),
                                   f->get_long_month_names(),
                                   (greg_month::max)(), s);
- delete(f);
     }
     
     num += 1; // months numbered 1-12
@@ -328,14 +329,12 @@
     /* bad_cast will be thrown if the desired facet is not accessible
      * so we can generate the facet. This has the drawback of using english
      * names as a default. */
- catch(std::bad_cast bc){
- //std::cout << "Weekday exception caught" << std::endl;
+ catch(std::bad_cast&){
       charT a = '\0';
- const facet_def* f = create_facet_def(a);
+ std::auto_ptr< const facet_def > f(create_facet_def(a));
       num = date_time::find_match(f->get_short_weekday_names(),
                                   f->get_long_weekday_names(),
                                   (greg_weekday::max)(), s);
- delete(f);
     }
    
     wd = greg_weekday(num); // weekdays numbered 0-6

Modified: trunk/boost/date_time/gregorian/greg_serialize.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/greg_serialize.hpp (original)
+++ trunk/boost/date_time/gregorian/greg_serialize.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -72,10 +72,10 @@
   ar & make_nvp("date", ds);
   try{
     d = ::boost::gregorian::from_undelimited_string(ds);
- }catch(bad_lexical_cast be) {
+ }catch(bad_lexical_cast&) {
     gregorian::special_values sv = gregorian::special_value_from_string(ds);
     if(sv == gregorian::not_special) {
- throw(be); // no match found, rethrow original exception
+ throw; // no match found, rethrow original exception
     }
     else {
       d = gregorian::date(sv);

Modified: trunk/boost/date_time/gregorian/gregorian_io.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/gregorian_io.hpp (original)
+++ trunk/boost/date_time/gregorian/gregorian_io.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,10 +9,17 @@
  * $Date$
  */
 
-#include "boost/date_time/date_facet.hpp"
-#include "boost/io/ios_state.hpp"
-#include <iostream>
 #include <locale>
+#include <iostream>
+#include <iterator> // i/ostreambuf_iterator
+#include <boost/io/ios_state.hpp>
+#include <boost/date_time/date_facet.hpp>
+#include <boost/date_time/period_parser.hpp>
+#include <boost/date_time/period_formatter.hpp>
+#include <boost/date_time/special_values_parser.hpp>
+#include <boost/date_time/special_values_formatter.hpp>
+#include <boost/date_time/gregorian/gregorian_types.hpp>
+#include <boost/date_time/gregorian/conversion.hpp> // to_tm will be needed in the facets
 
 namespace boost {
 namespace gregorian {

Modified: trunk/boost/date_time/int_adapter.hpp
==============================================================================
--- trunk/boost/date_time/int_adapter.hpp (original)
+++ trunk/boost/date_time/int_adapter.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -14,7 +14,9 @@
 #include "boost/limits.hpp" //work around compilers without limits
 #include "boost/date_time/special_defs.hpp"
 #include "boost/date_time/locale_config.hpp"
-#include <iostream>
+#ifndef BOOST_DATE_TIME_NO_LOCALE
+# include <ostream>
+#endif
 
 namespace boost {
 namespace date_time {

Modified: trunk/boost/date_time/local_time/local_date_time.hpp
==============================================================================
--- trunk/boost/date_time/local_time/local_date_time.hpp (original)
+++ trunk/boost/date_time/local_time/local_date_time.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -8,15 +8,17 @@
  * $Date$
  */
 
-
-#include "boost/date_time/time.hpp"
-#include "boost/date_time/posix_time/posix_time.hpp" //todo remove?
-#include "boost/shared_ptr.hpp"
-#include "boost/date_time/dst_rules.hpp"
-#include "boost/date_time/time_zone_base.hpp"
-#include "boost/date_time/special_defs.hpp"
 #include <string>
+#include <iomanip>
 #include <sstream>
+#include <stdexcept>
+#include <boost/shared_ptr.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/time.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp> //todo remove?
+#include <boost/date_time/dst_rules.hpp>
+#include <boost/date_time/time_zone_base.hpp>
+#include <boost/date_time/special_defs.hpp>
 
 namespace boost {
 namespace local_time {
@@ -24,19 +26,19 @@
   //! simple exception for reporting when STD or DST cannot be determined
   struct ambiguous_result : public std::logic_error
   {
- ambiguous_result (std::string _msg="") :
- std::logic_error(std::string("Daylight Savings Results are ambiguous: " + _msg)) {}
+ ambiguous_result (std::string const& msg = std::string()) :
+ std::logic_error(std::string("Daylight Savings Results are ambiguous: " + msg)) {}
   };
   //! simple exception for when time label given cannot exist
   struct time_label_invalid : public std::logic_error
   {
- time_label_invalid (std::string _msg="") :
- std::logic_error(std::string("Time label given is invalid: " + _msg)) {}
+ time_label_invalid (std::string const& msg = std::string()) :
+ std::logic_error(std::string("Time label given is invalid: " + msg)) {}
   };
   struct dst_not_valid: public std::logic_error
   {
- dst_not_valid(std::string _msg="") :
- std::logic_error(std::string("is_dst flag does not match resulting dst for time label given: " + _msg)) {}
+ dst_not_valid(std::string const& msg = std::string()) :
+ std::logic_error(std::string("is_dst flag does not match resulting dst for time label given: " + msg)) {}
   };
 
   //TODO: I think these should be in local_date_time_base and not
@@ -110,17 +112,17 @@
         // ambig occurs at end, invalid at start
         if(result == invalid_time_label){
           // Ex: 2:15am local on trans-in day in nyc, dst_flag irrelevant
- std::stringstream ss;
+ std::ostringstream ss;
           ss << "time given: " << d << ' ' << td;
- throw time_label_invalid(ss.str());
+ boost::throw_exception(time_label_invalid(ss.str()));
         }
         else if(result != ambiguous && in_dst != dst_flag){
           // is dst_flag accurate?
           // Ex: false flag in NYC in June
- std::stringstream ss;
- ss << "flag given: " << (dst_flag ? "dst=true" : "dst=false")
- << ", dst calculated: " << (in_dst ? "dst=true" : "dst=false");
- throw dst_not_valid(ss.str());
+ std::ostringstream ss;
+ ss.setf(std::ios_base::boolalpha);
+ ss << "flag given: dst=" << dst_flag << ", dst calculated: dst=" << in_dst;
+ boost::throw_exception(dst_not_valid(ss.str()));
         }
         
         // everything checks out and conversion to utc already done
@@ -146,9 +148,9 @@
       time_is_dst_result result = check_dst(d, td, tz);
       if(result == ambiguous) {
         if(calc_option == EXCEPTION_ON_ERROR){
- std::stringstream ss;
+ std::ostringstream ss;
           ss << "time given: " << d << ' ' << td;
- throw ambiguous_result(ss.str());
+ boost::throw_exception(ambiguous_result(ss.str()));
         }
         else{ // NADT on error
           this->time_ = posix_time::posix_time_system::get_time_rep(date_type(date_time::not_a_date_time), time_duration_type(date_time::not_a_date_time));
@@ -156,9 +158,9 @@
       }
       else if(result == invalid_time_label){
         if(calc_option == EXCEPTION_ON_ERROR){
- std::stringstream ss;
+ std::ostringstream ss;
           ss << "time given: " << d << ' ' << td;
- throw time_label_invalid(ss.str());
+ boost::throw_exception(time_label_invalid(ss.str()));
         }
         else{ // NADT on error
           this->time_ = posix_time::posix_time_system::get_time_rep(date_type(date_time::not_a_date_time), time_duration_type(date_time::not_a_date_time));
@@ -278,7 +280,7 @@
     std::string to_string() const
     {
       //TODO is this a temporary function ???
- std::stringstream ss;
+ std::ostringstream ss;
       if(this->is_special()){
         ss << utc_time();
         return ss.str();
@@ -497,7 +499,7 @@
     std::string zone_as_offset(const time_duration_type& td,
                                const std::string& separator) const
     {
- std::stringstream ss;
+ std::ostringstream ss;
       if(td.is_negative()) {
         // a negative duration is represented as "-[h]h:mm"
         // we require two digits for the hour. A positive duration

Modified: trunk/boost/date_time/local_time/local_time_io.hpp
==============================================================================
--- trunk/boost/date_time/local_time/local_time_io.hpp (original)
+++ trunk/boost/date_time/local_time/local_time_io.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -8,12 +8,15 @@
  * $Date$
  */
 
+#include <locale>
 #include <iostream>
-#include "boost/date_time/local_time/local_date_time.hpp"
-#include "boost/date_time/local_time/posix_time_zone.hpp"
-#include "boost/date_time/time_facet.hpp"
-#include "boost/date_time/string_convert.hpp"
-#include "boost/io/ios_state.hpp"
+#include <iterator> // i/ostreambuf_iterator
+#include <boost/io/ios_state.hpp>
+#include <boost/date_time/time_facet.hpp>
+#include <boost/date_time/string_convert.hpp>
+#include <boost/date_time/local_time/local_date_time.hpp>
+#include <boost/date_time/local_time/posix_time_zone.hpp>
+#include <boost/date_time/local_time/conversion.hpp> // to_tm will be needed in the facets
 
 namespace boost {
 namespace local_time {
@@ -106,13 +109,79 @@
           // if the user want's to fail quietly, we simply set the failbit
           is.setstate(std::ios_base::failbit);
         }
-
+
+ }
+ }
+ return is;
+ }
+
+ //! output operator for local_time_period
+ template <class CharT, class TraitsT>
+ inline
+ std::basic_ostream<CharT, TraitsT>&
+ operator<<(std::basic_ostream<CharT, TraitsT>& os,
+ const boost::local_time::local_time_period& p) {
+ boost::io::ios_flags_saver iflags(os);
+ typedef boost::date_time::time_facet<local_date_time, CharT> custom_facet;
+ typedef std::time_put<CharT> std_time_facet;
+ std::ostreambuf_iterator<CharT> oitr(os);
+ if (std::has_facet<custom_facet>(os.getloc())) {
+ std::use_facet<custom_facet>(os.getloc()).put(oitr, os, os.fill(), p);
+ }
+ else {
+ //instantiate a custom facet for dealing with periods since the user
+ //has not put one in the stream so far. This is for efficiency
+ //since we would always need to reconstruct for every time period
+ //if the local did not already exist. Of course this will be overridden
+ //if the user imbues as some later point.
+ std::ostreambuf_iterator<CharT> oitr(os);
+ custom_facet* f = new custom_facet();
+ std::locale l = std::locale(os.getloc(), f);
+ os.imbue(l);
+ f->put(oitr, os, os.fill(), p);
+ }
+ return os;
+ }
+
+ //! input operator for local_time_period
+ template <class CharT, class Traits>
+ inline
+ std::basic_istream<CharT, Traits>&
+ operator>>(std::basic_istream<CharT, Traits>& is, boost::local_time::local_time_period& tp)
+ {
+ boost::io::ios_flags_saver iflags(is);
+ typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false);
+ if (strm_sentry) {
+ try {
+ typedef typename date_time::time_input_facet<local_date_time, CharT> time_input_facet;
+
+ std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
+ if(std::has_facet<time_input_facet>(is.getloc())) {
+ std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, tp);
+ }
+ else {
+ time_input_facet* f = new time_input_facet();
+ std::locale l = std::locale(is.getloc(), f);
+ is.imbue(l);
+ f->get(sit, str_end, is, tp);
+ }
+ }
+ catch(...) {
+ std::ios_base::iostate exception_mask = is.exceptions();
+ if(std::ios_base::failbit & exception_mask) {
+ try { is.setstate(std::ios_base::failbit); }
+ catch(std::ios_base::failure&) {}
+ throw; // rethrow original exception
+ }
+ else {
+ is.setstate(std::ios_base::failbit);
+ }
+
       }
     }
     return is;
   }
 
-
 } } // namespaces
 
 #endif // BOOST_DATE_TIME_LOCAL_TIME_IO_HPP__

Modified: trunk/boost/date_time/local_time/posix_time_zone.hpp
==============================================================================
--- trunk/boost/date_time/local_time/posix_time_zone.hpp (original)
+++ trunk/boost/date_time/local_time/posix_time_zone.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -10,15 +10,16 @@
 
 #include <string>
 #include <sstream>
-#include "boost/date_time/gregorian/gregorian.hpp"
-#include "boost/date_time/time_zone_names.hpp"
-#include "boost/date_time/time_zone_base.hpp"
-#include "boost/date_time/local_time/dst_transition_day_rules.hpp"
-#include "boost/date_time/posix_time/posix_time.hpp"
-#include "boost/date_time/string_convert.hpp"
-#include "boost/date_time/time_parsing.hpp"
-#include "boost/tokenizer.hpp"
 #include <stdexcept>
+#include <boost/tokenizer.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/date_time/time_zone_names.hpp>
+#include <boost/date_time/time_zone_base.hpp>
+#include <boost/date_time/local_time/dst_transition_day_rules.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/string_convert.hpp>
+#include <boost/date_time/time_parsing.hpp>
 
 namespace boost{
 namespace local_time{
@@ -26,12 +27,14 @@
   //! simple exception for UTC and Daylight savings start/end offsets
   struct bad_offset : public std::out_of_range
   {
- bad_offset(std::string _msg="") : std::out_of_range(std::string("Offset out of range: " + _msg)) {}
+ bad_offset(std::string const& msg = std::string()) :
+ std::out_of_range(std::string("Offset out of range: " + msg)) {}
   };
   //! simple exception for UTC daylight savings adjustment
   struct bad_adjustment : public std::out_of_range
   {
- bad_adjustment(std::string _msg="") : std::out_of_range(std::string("Adjustment out of range: " + _msg)) {}
+ bad_adjustment(std::string const& msg = std::string()) :
+ std::out_of_range(std::string("Adjustment out of range: " + msg)) {}
   };
   
   typedef boost::date_time::dst_adjustment_offsets<boost::posix_time::time_duration> dst_adjustment_offsets;
@@ -231,7 +234,7 @@
     void calc_zone(const string_type& obj){
       const char_type empty_string[2] = {'\0'};
       stringstream_type ss(empty_string);
- typename string_type::const_iterator sit = obj.begin();
+ typename string_type::const_pointer sit = obj.c_str(), obj_end = sit + obj.size();
       string_type l_std_zone_abbrev, l_dst_zone_abbrev;
 
       // get 'std' name/abbrev
@@ -242,37 +245,37 @@
       ss.str(empty_string);
 
       // get UTC offset
- if(sit != obj.end()){
+ if(sit != obj_end){
         // get duration
- while(sit != obj.end() && !std::isalpha(*sit)){
- ss << *sit++;
+ while(sit != obj_end && !std::isalpha(*sit)){
+ ss << *sit++;
         }
         base_utc_offset_ = date_time::str_from_delimited_time_duration<time_duration_type,char_type>(ss.str());
         ss.str(empty_string);
 
         // base offset must be within range of -12 hours to +12 hours
         if(base_utc_offset_ < time_duration_type(-12,0,0) ||
- base_utc_offset_ > time_duration_type(12,0,0))
+ base_utc_offset_ > time_duration_type(12,0,0))
         {
- throw bad_offset(posix_time::to_simple_string(base_utc_offset_));
+ boost::throw_exception(bad_offset(posix_time::to_simple_string(base_utc_offset_)));
         }
       }
 
       // get DST data if given
- if(sit != obj.end()){
+ if(sit != obj_end){
         has_dst_ = true;
     
         // get 'dst' name/abbrev
- while(sit != obj.end() && std::isalpha(*sit)){
+ while(sit != obj_end && std::isalpha(*sit)){
           ss << *sit++;
         }
         l_dst_zone_abbrev = ss.str();
         ss.str(empty_string);
 
         // get DST offset if given
- if(sit != obj.end()){
+ if(sit != obj_end){
           // get duration
- while(sit != obj.end() && !std::isalpha(*sit)){
+ while(sit != obj_end && !std::isalpha(*sit)){
             ss << *sit++;
           }
           dst_offsets_.dst_adjust_ = date_time::str_from_delimited_time_duration<time_duration_type,char_type>(ss.str());
@@ -286,7 +289,7 @@
         if(dst_offsets_.dst_adjust_ <= time_duration_type(-24,0,0) ||
             dst_offsets_.dst_adjust_ >= time_duration_type(24,0,0))
         {
- throw bad_adjustment(posix_time::to_simple_string(dst_offsets_.dst_adjust_));
+ boost::throw_exception(bad_adjustment(posix_time::to_simple_string(dst_offsets_.dst_adjust_)));
         }
       }
       // full names not extracted so abbrevs used in their place
@@ -328,7 +331,7 @@
       if(dst_offsets_.dst_start_offset_ < time_duration_type(0,0,0) ||
           dst_offsets_.dst_start_offset_ >= time_duration_type(24,0,0))
       {
- throw bad_offset(posix_time::to_simple_string(dst_offsets_.dst_start_offset_));
+ boost::throw_exception(bad_offset(posix_time::to_simple_string(dst_offsets_.dst_start_offset_)));
       }
 
       // ending offset
@@ -343,7 +346,7 @@
       if(dst_offsets_.dst_end_offset_ < time_duration_type(0,0,0) ||
         dst_offsets_.dst_end_offset_ >= time_duration_type(24,0,0))
       {
- throw bad_offset(posix_time::to_simple_string(dst_offsets_.dst_end_offset_));
+ boost::throw_exception(bad_offset(posix_time::to_simple_string(dst_offsets_.dst_end_offset_)));
       }
     }
 

Modified: trunk/boost/date_time/local_time_adjustor.hpp
==============================================================================
--- trunk/boost/date_time/local_time_adjustor.hpp (original)
+++ trunk/boost/date_time/local_time_adjustor.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -13,9 +13,13 @@
   Time adjustment calculations for local times
 */
 
-#include "boost/date_time/date_generators.hpp"
-#include "boost/date_time/dst_rules.hpp"
 #include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/date_generators.hpp>
+#include <boost/date_time/dst_rules.hpp>
+#include <boost/date_time/time_defs.hpp> // boost::date_time::dst_flags
+#include <boost/date_time/special_defs.hpp> // not_a_date_time
 
 namespace boost {
   namespace date_time {
@@ -109,7 +113,7 @@
         time_is_dst_result dst_flag =
           dst_rules::local_is_dst(initial.date(), initial.time_of_day());
         switch(dst_flag) {
- case is_in_dst: return utc_offset_rules::utc_to_local_base_offset() + dst_rules::dst_offset();
+ case is_in_dst: return utc_offset_rules::utc_to_local_base_offset() + dst_rules::dst_offset();
         case is_not_in_dst: return utc_offset_rules::utc_to_local_base_offset();
         case invalid_time_label:return utc_offset_rules::utc_to_local_base_offset() + dst_rules::dst_offset();
         case ambiguous: {
@@ -125,15 +129,15 @@
           }
         }
         }//case
- //TODO better excpetion type
- throw std::out_of_range("Unreachable case");
-
+ //TODO better exception type
+ boost::throw_exception(std::out_of_range("Unreachable case"));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_duration_type(not_a_date_time)); // should never reach
       }
 
       //! Get the offset to UTC given a local time
       static time_duration_type local_to_utc_offset(const time_type& t,
                                                     date_time::dst_flags dst=date_time::calculate)
- {
+ {
         switch (dst) {
         case is_dst:
           return utc_offset_rules::local_to_utc_base_offset() - dst_rules::dst_offset();
@@ -146,13 +150,14 @@
           case is_in_dst: return utc_offset_rules::local_to_utc_base_offset() - dst_rules::dst_offset();
           case is_not_in_dst: return utc_offset_rules::local_to_utc_base_offset();
           case ambiguous: return utc_offset_rules::local_to_utc_base_offset();
- case invalid_time_label: throw std::out_of_range("Time label invalid");
+ case invalid_time_label: break;
           }
- }
- throw std::out_of_range("Time label invalid");
+ }
+ boost::throw_exception(std::out_of_range("Time label invalid"));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_duration_type(not_a_date_time)); // should never reach
       }
 
-
+
     private:
 
     };

Modified: trunk/boost/date_time/microsec_time_clock.hpp
==============================================================================
--- trunk/boost/date_time/microsec_time_clock.hpp (original)
+++ trunk/boost/date_time/microsec_time_clock.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -14,22 +14,19 @@
   This file contains a high resolution time clock implementation.
 */
 
+#include <boost/cstdint.hpp>
+#include <boost/shared_ptr.hpp>
 #include <boost/detail/workaround.hpp>
-#include "boost/date_time/c_time.hpp"
-#include "boost/date_time/time_clock.hpp"
-#include "boost/cstdint.hpp"
-#include "boost/shared_ptr.hpp"
-
-#ifdef BOOST_HAS_FTIME
-#include <windows.h>
-#endif
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/c_time.hpp>
+#include <boost/date_time/time_clock.hpp>
+#include <boost/date_time/filetime_functions.hpp>
 
 #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
 
 namespace boost {
 namespace date_time {
 
-
   //! A clock providing microsecond level resolution
   /*! A high precision clock that measures the local time
    * at a resolution up to microseconds and adjusts to the
@@ -41,6 +38,10 @@
   template<class time_type>
   class microsec_clock
   {
+ private:
+ //! Type for the function used to convert time_t to tm
+ typedef std::tm* (*time_converter)(const std::time_t*, std::tm*);
+
   public:
     typedef typename time_type::date_type date_type;
     typedef typename time_type::time_duration_type time_duration_type;
@@ -49,7 +50,8 @@
     //! return a local time object for the given zone, based on computer clock
     //JKG -- looks like we could rewrite this against universal_time
     template<class time_zone_type>
- static time_type local_time(shared_ptr<time_zone_type> tz_ptr) {
+ static time_type local_time(shared_ptr<time_zone_type> tz_ptr)
+ {
       typedef typename time_type::utc_time_type utc_time_type;
       typedef second_clock<utc_time_type> second_clock;
       // we'll need to know the utc_offset this machine has
@@ -62,118 +64,39 @@
       return time_type(utc_time, tz_ptr);
     }
 
-
- private:
- // we want this enum available for both platforms yet still private
- enum TZ_FOR_CREATE { LOCAL, GMT };
-
- public:
-
-#ifdef BOOST_HAS_GETTIMEOFDAY
- //! Return the local time based on computer clock settings
- static time_type local_time() {
- return create_time(LOCAL);
+ //! Returns the local time based on computer clock settings
+ static time_type local_time()
+ {
+ return create_time(&c_time::localtime);
     }
 
- //! Get the current day in universal date as a ymd_type
+ //! Returns the UTC time based on computer settings
     static time_type universal_time()
     {
- return create_time(GMT);
+ return create_time(&c_time::gmtime);
     }
 
   private:
- static time_type create_time(TZ_FOR_CREATE tz) {
+ static time_type create_time(time_converter converter)
+ {
+#ifdef BOOST_HAS_GETTIMEOFDAY
       timeval tv;
       gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
       std::time_t t = tv.tv_sec;
- boost::uint32_t fs = tv.tv_usec;
- std::tm curr, *curr_ptr = 0;
- if (tz == LOCAL) {
- curr_ptr = c_time::localtime(&t, &curr);
- } else {
- curr_ptr = c_time::gmtime(&t, &curr);
- }
- date_type d(curr_ptr->tm_year + 1900,
- curr_ptr->tm_mon + 1,
- curr_ptr->tm_mday);
- //The following line will adjusts the fractional second tick in terms
- //of the current time system. For example, if the time system
- //doesn't support fractional seconds then res_adjust returns 0
- //and all the fractional seconds return 0.
- int adjust = resolution_traits_type::res_adjust()/1000000;
-
- time_duration_type td(curr_ptr->tm_hour,
- curr_ptr->tm_min,
- curr_ptr->tm_sec,
- fs*adjust);
- return time_type(d,td);
-
- }
-#endif // BOOST_HAS_GETTIMEOFDAY
-
-#ifdef BOOST_HAS_FTIME
- //! Return the local time based on computer clock settings
- static time_type local_time() {
- FILETIME ft;
- #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
- // Some runtime library implementations expect local times as the norm for ctime.
- FILETIME ft_utc;
- GetSystemTimeAsFileTime(&ft_utc);
- FileTimeToLocalFileTime(&ft_utc,&ft);
- #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME)
- SYSTEMTIME st;
- GetSystemTime( &st );
- SystemTimeToFileTime( &st, &ft );
- #else
- GetSystemTimeAsFileTime(&ft);
- #endif
- return create_time(ft, LOCAL);
- }
-
- //! Return the UTC time based on computer settings
- static time_type universal_time() {
- FILETIME ft;
- #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
- // Some runtime library implementations expect local times as the norm for ctime.
- FILETIME ft_utc;
- GetSystemTimeAsFileTime(&ft_utc);
- FileTimeToLocalFileTime(&ft_utc,&ft);
- #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME)
- SYSTEMTIME st;
- GetSystemTime( &st );
- SystemTimeToFileTime( &st, &ft );
- #else
- GetSystemTimeAsFileTime(&ft);
- #endif
- return create_time(ft, GMT);
- }
-
- private:
- static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) {
- // offset is difference (in 100-nanoseconds) from
- // 1970-Jan-01 to 1601-Jan-01
- boost::uint64_t c1 = 27111902;
- boost::uint64_t c2 = 3577643008UL; // 'UL' removes compiler warnings
- const boost::uint64_t OFFSET = (c1 << 32) + c2;
-
- boost::uint64_t filetime = ft.dwHighDateTime;
- filetime = filetime << 32;
- filetime += ft.dwLowDateTime;
- filetime -= OFFSET;
- // filetime now holds 100-nanoseconds since 1970-Jan-01
-
+ boost::uint32_t sub_sec = tv.tv_usec;
+#elif defined(BOOST_HAS_FTIME)
+ winapi::file_time ft;
+ winapi::get_system_time_as_file_time(ft);
+ uint64_t nanos = winapi::file_time_to_nanoseconds(ft);
+ std::time_t t = static_cast<time_t>(nanos / 1000000000UL); // seconds since epoch
       // microseconds -- static casts supress warnings
- boost::uint32_t sub_sec = static_cast<boost::uint32_t>((filetime % 10000000) / 10);
+ boost::uint32_t sub_sec = static_cast<boost::uint32_t>((nanos % 1000000000UL) / 1000UL);
+#else
+#error Internal Boost.DateTime error: BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK is defined, however neither gettimeofday nor FILETIME support is detected.
+#endif
 
- std::time_t t = static_cast<time_t>(filetime / 10000000); // seconds since epoch
-
- std::tm curr, *curr_ptr = 0;
- if (tz == LOCAL) {
- curr_ptr = c_time::localtime(&t, &curr);
- }
- else {
- curr_ptr = c_time::gmtime(&t, &curr);
- }
+ std::tm curr;
+ std::tm* curr_ptr = converter(&t, &curr);
       date_type d(curr_ptr->tm_year + 1900,
                   curr_ptr->tm_mon + 1,
                   curr_ptr->tm_mday);
@@ -182,17 +105,15 @@
       //of the current time system. For example, if the time system
       //doesn't support fractional seconds then res_adjust returns 0
       //and all the fractional seconds return 0.
- int adjust = static_cast<int>(resolution_traits_type::res_adjust()/1000000);
+ int adjust = static_cast< int >(resolution_traits_type::res_adjust() / 1000000);
 
       time_duration_type td(curr_ptr->tm_hour,
                             curr_ptr->tm_min,
                             curr_ptr->tm_sec,
                             sub_sec * adjust);
- //st.wMilliseconds * adjust);
- return time_type(d,td);
 
+ return time_type(d,td);
     }
-#endif // BOOST_HAS_FTIME
   };
 
 

Modified: trunk/boost/date_time/period_parser.hpp
==============================================================================
--- trunk/boost/date_time/period_parser.hpp (original)
+++ trunk/boost/date_time/period_parser.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -10,8 +10,9 @@
  * $Date$
  */
 
-#include "boost/date_time/string_parse_tree.hpp"
-#include "boost/date_time/string_convert.hpp"
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/string_parse_tree.hpp>
+#include <boost/date_time/string_convert.hpp>
 
 
 namespace boost { namespace date_time {
@@ -170,7 +171,8 @@
         ++sitr;
       }
       if(s != delim) {
- throw std::ios_base::failure("Parse failed. Expected '" + convert_string_type<char_type,char>(delim) + "' but found '" + convert_string_type<char_type,char>(s) + "'");
+ boost::throw_exception(std::ios_base::failure("Parse failed. Expected '"
+ + convert_string_type<char_type,char>(delim) + "' but found '" + convert_string_type<char_type,char>(s) + "'"));
       }
     }
   };

Modified: trunk/boost/date_time/posix_time/conversion.hpp
==============================================================================
--- trunk/boost/date_time/posix_time/conversion.hpp (original)
+++ trunk/boost/date_time/posix_time/conversion.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -72,14 +72,18 @@
    * built with microsecond resolution the FILETIME's sub second value
    * will be truncated. Nanosecond resolution has no truncation.
    *
- * Note ftime is part of the Win32 API, so it is not portable to non-windows
+ * \note FILETIME is part of the Win32 API, so it is not portable to non-windows
    * platforms.
+ *
+ * \note The function is templated on the FILETIME type, so that
+ * it can be used with both native FILETIME and the ad-hoc
+ * boost::date_time::winapi::file_time type.
    */
- template<class time_type>
+ template< typename TimeT, typename FileTimeT >
   inline
- time_type from_ftime(const FILETIME& ft)
+ TimeT from_ftime(const FileTimeT& ft)
   {
- return boost::date_time::time_from_ftime<time_type>(ft);
+ return boost::date_time::time_from_ftime<TimeT>(ft);
   }
 
 #endif // BOOST_HAS_FTIME

Modified: trunk/boost/date_time/posix_time/posix_time_io.hpp
==============================================================================
--- trunk/boost/date_time/posix_time/posix_time_io.hpp (original)
+++ trunk/boost/date_time/posix_time/posix_time_io.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,14 +9,16 @@
  * $Date$
  */
 
-#include "boost/date_time/time_facet.hpp"
-#include "boost/date_time/period_formatter.hpp"
-#include "boost/date_time/posix_time/time_period.hpp"
-#include "boost/date_time/posix_time/posix_time_duration.hpp"
-//#include "boost/date_time/gregorian/gregorian_io.hpp"
-#include "boost/io/ios_state.hpp"
-#include <iostream>
 #include <locale>
+#include <iostream>
+#include <iterator> // i/ostreambuf_iterator
+#include <boost/io/ios_state.hpp>
+#include <boost/date_time/time_facet.hpp>
+#include <boost/date_time/period_formatter.hpp>
+#include <boost/date_time/posix_time/ptime.hpp>
+#include <boost/date_time/posix_time/time_period.hpp>
+#include <boost/date_time/posix_time/posix_time_duration.hpp>
+#include <boost/date_time/posix_time/conversion.hpp> // to_tm will be needed in the facets
 
 namespace boost {
 namespace posix_time {
@@ -75,7 +77,6 @@
     if (strm_sentry) {
       try {
         typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet;
-
         std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
         if(std::has_facet<time_input_facet>(is.getloc())) {
           std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, pt);
@@ -101,7 +102,6 @@
           // if the user want's to fail quietly, we simply set the failbit
           is.setstate(std::ios_base::failbit);
         }
-
       }
     }
     return is;
@@ -146,7 +146,6 @@
     if (strm_sentry) {
       try {
         typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet;
-
         std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
         if(std::has_facet<time_input_facet>(is.getloc())) {
           std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, tp);
@@ -168,7 +167,6 @@
         else {
           is.setstate(std::ios_base::failbit);
         }
-
       }
     }
     return is;
@@ -214,7 +212,6 @@
     if (strm_sentry) {
       try {
         typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet;
-
         std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
         if(std::has_facet<time_input_facet>(is.getloc())) {
           std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, td);
@@ -236,7 +233,6 @@
         else {
           is.setstate(std::ios_base::failbit);
         }
-
       }
     }
     return is;

Modified: trunk/boost/date_time/time.hpp
==============================================================================
--- trunk/boost/date_time/time.hpp (original)
+++ trunk/boost/date_time/time.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -13,9 +13,10 @@
 /*! @file time.hpp
   This file contains the interface for the time associated classes.
 */
-#include "boost/date_time/time_defs.hpp"
-#include "boost/operators.hpp"
 #include <string>
+#include <boost/operators.hpp>
+#include <boost/date_time/time_defs.hpp>
+#include <boost/date_time/special_defs.hpp>
 
 namespace boost {
 namespace date_time {
@@ -91,7 +92,7 @@
     //! An empty string is returned for classes that do not use a time_zone
     std::string zone_as_posix_string() const
     {
- return std::string("");
+ return std::string();
     }
 
     //! check to see if date is not a value

Modified: trunk/boost/date_time/time_defs.hpp
==============================================================================
--- trunk/boost/date_time/time_defs.hpp (original)
+++ trunk/boost/date_time/time_defs.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -20,7 +20,17 @@
 namespace date_time {
 
   //!Defines some nice types for handling time level resolutions
- enum time_resolutions {sec, tenth, hundreth, milli, ten_thousandth, micro, nano, NumResolutions };
+ enum time_resolutions {
+ sec,
+ tenth,
+ hundreth, // deprecated misspelled version of hundredth
+ hundredth = hundreth,
+ milli,
+ ten_thousandth,
+ micro,
+ nano,
+ NumResolutions
+ };
 
   //! Flags for daylight savings or summer time
   enum dst_flags {not_dst, is_dst, calculate};

Modified: trunk/boost/date_time/time_facet.hpp
==============================================================================
--- trunk/boost/date_time/time_facet.hpp (original)
+++ trunk/boost/date_time/time_facet.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -10,12 +10,22 @@
  * $Date$
  */
 
-#include "boost/date_time/date_facet.hpp"
-#include "boost/date_time/string_convert.hpp"
-#include "boost/algorithm/string/erase.hpp"
+#include <cctype>
+#include <locale>
+#include <limits>
+#include <string>
 #include <sstream>
 #include <iomanip>
+#include <iterator> // i/ostreambuf_iterator
 #include <exception>
+#include <boost/lexical_cast.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/algorithm/string/erase.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/date_facet.hpp>
+#include <boost/date_time/string_convert.hpp>
+#include <boost/date_time/special_defs.hpp>
 
 namespace boost {
 namespace date_time {
@@ -28,6 +38,8 @@
       static const char_type fractional_seconds_or_none_format[3]; // F
       static const char_type seconds_with_fractional_seconds_format[3]; // s
       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 standard_format[9]; // x X
       static const char_type zone_abbrev_format[3]; // z
       static const char_type zone_name_format[3]; // Z
@@ -62,10 +74,18 @@
   time_formats<CharT>::seconds_with_fractional_seconds_format[3] =
     {'%','s'};
 
- template <class CharT>
+ template <class CharT>
   const typename time_formats<CharT>::char_type
   time_formats<CharT>::seconds_format[3] = {'%','S'};
 
+ template <class CharT>
+ const typename time_formats<CharT>::char_type
+ time_formats<CharT>::hours_format[3] = {'%','H'};
+
+ template <class CharT>
+ const typename time_formats<CharT>::char_type
+ time_formats<CharT>::unrestricted_hours_format[3] = {'%','O'};
+
   template <class CharT>
   const typename time_formats<CharT>::char_type
   //time_formats<CharT>::standard_format[5] = {'%','c',' ','%','z'};
@@ -172,6 +192,8 @@
     static const char_type* fractional_seconds_or_none_format; // %F
     static const char_type* seconds_with_fractional_seconds_format; // %s
     static const char_type* seconds_format; // %S
+ static const char_type* hours_format; // %H
+ static const char_type* unrestricted_hours_format; // %O
     static const char_type* standard_format; // %x X
     static const char_type* zone_abbrev_format; // %z
     static const char_type* zone_name_format; // %Z
@@ -197,9 +219,8 @@
 #endif
 
     //! sets default formats for ptime, local_date_time, and time_duration
- explicit time_facet(::size_t /* a_ref */ = 0)
- //: base_type(standard_format),
- : base_type(default_time_format),
+ explicit time_facet(::size_t a_ref = 0)
+ : base_type(default_time_format, period_formatter_type(), special_values_formatter_type(), date_gen_formatter_type(), a_ref),
         m_time_duration_format(string_type(duration_sign_negative_only) + default_time_duration_format)
     {}
 
@@ -242,6 +263,7 @@
                               a_time.date().as_special());
       }
       string_type format(this->m_format);
+
       string_type frac_str;
       if (format.find(seconds_with_fractional_seconds_format) != string_type::npos) {
         // replace %s with %S.nnn
@@ -263,9 +285,7 @@
         if(a_time.zone_abbrev().empty()) {
           // if zone_abbrev() returns an empty string, we want to
           // erase posix_zone_string_format from format
- boost::algorithm::replace_all(format,
- posix_zone_string_format,
- "");
+ boost::algorithm::erase_all(format, posix_zone_string_format);
         }
         else{
           boost::algorithm::replace_all(format,
@@ -283,9 +303,7 @@
           // erase zone_name_format & one preceeding space
           std::basic_ostringstream<char_type> ss;
           ss << ' ' << zone_name_format;
- boost::algorithm::replace_all(format,
- ss.str(),
- "");
+ boost::algorithm::erase_all(format, ss.str());
         }
         else{
           boost::algorithm::replace_all(format,
@@ -303,9 +321,7 @@
           // erase zone_abbrev_format & one preceeding space
           std::basic_ostringstream<char_type> ss;
           ss << ' ' << zone_abbrev_format;
- boost::algorithm::replace_all(format,
- ss.str(),
- "");
+ boost::algorithm::erase_all(format, ss.str());
         }
         else{
           boost::algorithm::replace_all(format,
@@ -321,9 +337,7 @@
 
           // if zone_name() returns an empty string, we want to
           // erase zone_iso_extended_format from format
- boost::algorithm::replace_all(format,
- zone_iso_extended_format,
- "");
+ boost::algorithm::erase_all(format, zone_iso_extended_format);
         }
         else{
           boost::algorithm::replace_all(format,
@@ -340,9 +354,7 @@
 
           // if zone_abbrev() returns an empty string, we want to
           // erase zone_iso_format from format
- boost::algorithm::replace_all(format,
- zone_iso_format,
- "");
+ boost::algorithm::erase_all(format, zone_iso_format);
         }
         else{
           boost::algorithm::replace_all(format,
@@ -396,24 +408,46 @@
 
       string_type format(m_time_duration_format);
       if (a_time_dur.is_negative()) {
- // replace %- with minus sign. Should we use the numpunct facet?
- boost::algorithm::replace_all(format,
- duration_sign_negative_only,
- negative_sign);
+ // replace %- with minus sign. Should we use the numpunct facet?
+ boost::algorithm::replace_all(format,
+ duration_sign_negative_only,
+ negative_sign);
           // remove all the %+ in the string with '-'
- boost::algorithm::replace_all(format,
- duration_sign_always,
- negative_sign);
+ boost::algorithm::replace_all(format,
+ duration_sign_always,
+ negative_sign);
       }
       else { //duration is positive
- // remove all the %- combos from the string
- boost::algorithm::replace_all(format,
- duration_sign_negative_only,
- "");
- // remove all the %+ in the string with '+'
- boost::algorithm::replace_all(format,
- duration_sign_always,
- positive_sign);
+ // remove all the %- combos from the string
+ boost::algorithm::erase_all(format, duration_sign_negative_only);
+ // remove all the %+ in the string with '+'
+ boost::algorithm::replace_all(format,
+ duration_sign_always,
+ positive_sign);
+ }
+
+ /*
+ * 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
+ * (See ISO 14882-2003 22.2.5.3.1 par. 1) and strftime's behavior is
+ * unspecified for the case when tm_hour field is outside 0-23 range
+ * (See ISO 9899-1999 7.23.3.5 par. 3). So we must output %H and %O
+ * here ourself.
+ */
+ string_type hours_str;
+ if (format.find(unrestricted_hours_format) != string_type::npos) {
+ hours_str = hours_as_string(a_time_dur);
+ boost::algorithm::replace_all(format, unrestricted_hours_format, hours_str);
+ }
+ // We still have to process restricted hours format specifier. In order to
+ // support parseability of durations in ISO format (%H%M%S), we'll have to
+ // restrict the stringified hours length to 2 characters.
+ if (format.find(hours_format) != string_type::npos) {
+ if (hours_str.empty())
+ hours_str = hours_as_string(a_time_dur);
+ if (hours_str.length() > 2)
+ hours_str.erase(0, hours_str.length() - 2);
+ boost::algorithm::replace_all(format, hours_format, hours_str);
       }
 
       string_type frac_str;
@@ -485,17 +519,33 @@
       }
 
       //make sure there is no sign
- frac_sec = date_time::absolute_value(frac_sec);
+ return integral_as_string(
+ date_time::absolute_value(frac_sec),
+ time_duration_type::num_fractional_digits());
+ }
+
+ static
+ string_type
+ hours_as_string(const time_duration_type& a_time, int width = 2)
+ {
+ return integral_as_string(date_time::absolute_value(a_time.hours()), width);
+ }
+
+ template< typename IntT >
+ static
+ string_type
+ integral_as_string(IntT val, int width = 2)
+ {
       std::basic_ostringstream<char_type> ss;
       ss.imbue(std::locale::classic()); // don't want any formatting
- ss << std::setw(time_duration_type::num_fractional_digits())
- << std::setfill(static_cast<char_type>('0'));
+ ss << std::setw(width)
+ << std::setfill(static_cast<char_type>('0'));
 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
       // JDG [7/6/02 VC++ compatibility]
       char_type buff[34];
- ss << _i64toa(static_cast<boost::int64_t>(frac_sec), buff, 10);
+ ss << _i64toa(static_cast<boost::int64_t>(val), buff, 10);
 #else
- ss << frac_sec;
+ ss << val;
 #endif
       return ss.str();
     }
@@ -504,7 +554,7 @@
     string_type m_time_duration_format;
 
   };
-
+
   template <class time_type, class CharT, class OutItrT>
   std::locale::id time_facet<time_type, CharT, OutItrT>::id;
 
@@ -548,6 +598,14 @@
 
   template <class time_type, class CharT, class OutItrT>
   const typename time_facet<time_type, CharT, OutItrT>::char_type*
+ time_facet<time_type, CharT, OutItrT>::hours_format = time_formats<CharT>::hours_format;
+
+ template <class time_type, class CharT, class OutItrT>
+ const typename time_facet<time_type, CharT, OutItrT>::char_type*
+ time_facet<time_type, CharT, OutItrT>::unrestricted_hours_format = time_formats<CharT>::unrestricted_hours_format;
+
+ template <class time_type, class CharT, class OutItrT>
+ const typename time_facet<time_type, CharT, OutItrT>::char_type*
   time_facet<time_type, CharT, OutItrT>::standard_format = time_formats<CharT>::standard_format;
 
   template <class time_type, class CharT, class OutItrT>
@@ -705,11 +763,15 @@
           c = *sitr;
         }
         
- long hour = 0;
- long min = 0;
- long sec = 0;
+ typedef typename time_duration_type::hour_type hour_type;
+ typedef typename time_duration_type::min_type min_type;
+ typedef typename time_duration_type::sec_type sec_type;
+
+ hour_type hour = 0;
+ min_type min = 0;
+ sec_type sec = 0;
         typename time_duration_type::fractional_seconds_type frac(0);
-
+
         typedef std::num_get<CharT, InItrT> num_get;
         if(!std::has_facet<num_get>(a_ios.getloc())) {
           num_get* ng = new num_get();
@@ -720,45 +782,49 @@
         const_itr itr(m_time_duration_format.begin());
         while (itr != m_time_duration_format.end() && (sitr != stream_end)) {
           if (*itr == '%') {
- itr++;
+ ++itr;
             if (*itr != '%') {
               switch(*itr) {
- case 'H':
+ case 'O':
                 {
- match_results mr;
- hour = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
+ // A period may span more than 24 hours. In that case the format
+ // string should be composed with the unrestricted hours specifier.
+ hour = var_string_to_int<hour_type, CharT>(sitr, stream_end,
+ std::numeric_limits<hour_type>::digits10 + 1);
                   if(hour == -1){
                      return check_special_value(sitr, stream_end, td, c);
                   }
                   break;
                 }
- case 'M':
+ case 'H':
                 {
                   match_results mr;
- min = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
- if(min == -1){
+ hour = fixed_string_to_int<hour_type, CharT>(sitr, stream_end, mr, 2);
+ if(hour == -1){
                      return check_special_value(sitr, stream_end, td, c);
                   }
                   break;
                 }
- case 'S':
+ case 'M':
                 {
                   match_results mr;
- sec = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
- if(sec == -1){
+ min = fixed_string_to_int<min_type, CharT>(sitr, stream_end, mr, 2);
+ if(min == -1){
                      return check_special_value(sitr, stream_end, td, c);
                   }
                   break;
                 }
               case 's':
+ case 'S':
                 {
                   match_results mr;
- sec = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
+ sec = fixed_string_to_int<sec_type, CharT>(sitr, stream_end, mr, 2);
                   if(sec == -1){
                      return check_special_value(sitr, stream_end, td, c);
                   }
+ if (*itr == 'S')
+ break;
                   // %s is the same as %S%f so we drop through into %f
- //break;
                 }
               case 'f':
                 {
@@ -796,20 +862,20 @@
               }// switch
             }
             else { // itr == '%', second consecutive
- sitr++;
+ ++sitr;
             }
         
- itr++; //advance past format specifier
+ ++itr; //advance past format specifier
           }
           else { //skip past chars in format and in buffer
- itr++;
+ ++itr;
             // set use_current_char when sitr is already
             // pointing at the next character to process
             if (use_current_char) {
               use_current_char = false;
             }
             else {
- sitr++;
+ ++sitr;
             }
           }
         }
@@ -858,11 +924,15 @@
         if((sitr != stream_end) && (*sitr == '-' || *sitr == '+')) {
           c = *sitr;
         }
-
+
+ typedef typename time_duration_type::hour_type hour_type;
+ typedef typename time_duration_type::min_type min_type;
+ typedef typename time_duration_type::sec_type sec_type;
+
         // time elements
- long hour = 0;
- long min = 0;
- long sec = 0;
+ hour_type hour = 0;
+ min_type min = 0;
+ sec_type sec = 0;
         typename time_duration_type::fractional_seconds_type frac(0);
         // date elements
         short day_of_year(0);
@@ -884,7 +954,7 @@
         const_itr itr(this->m_format.begin());
         while (itr != this->m_format.end() && (sitr != stream_end)) {
           if (*itr == '%') {
- itr++;
+ ++itr;
             if (*itr != '%') {
               // the cases are grouped by date & time flags - not alphabetical order
               switch(*itr) {
@@ -998,7 +1068,7 @@
                 case 'H':
                   {
                     match_results mr;
- hour = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
+ hour = fixed_string_to_int<hour_type, CharT>(sitr, stream_end, mr, 2);
                     if(hour == -1){
                        return check_special_value(sitr, stream_end, t, c);
                     }
@@ -1007,30 +1077,23 @@
                 case 'M':
                   {
                     match_results mr;
- min = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
+ min = fixed_string_to_int<min_type, CharT>(sitr, stream_end, mr, 2);
                     if(min == -1){
                        return check_special_value(sitr, stream_end, t, c);
                     }
                     break;
                   }
- case 'S':
- {
- match_results mr;
- sec = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
- if(sec == -1){
- return check_special_value(sitr, stream_end, t, c);
- }
- break;
- }
                 case 's':
+ case 'S':
                   {
                     match_results mr;
- sec = fixed_string_to_int<short, CharT>(sitr, stream_end, mr, 2);
+ sec = fixed_string_to_int<sec_type, CharT>(sitr, stream_end, mr, 2);
                     if(sec == -1){
                        return check_special_value(sitr, stream_end, t, c);
                     }
+ if (*itr == 'S')
+ break;
                     // %s is the same as %S%f so we drop through into %f
- //break;
                   }
                 case 'f':
                   {
@@ -1097,26 +1160,26 @@
               }// switch
             }
             else { // itr == '%', second consecutive
- sitr++;
+ ++sitr;
             }
        
             if(use_current_format_char) {
               use_current_format_char = false;
             }
             else {
- itr++; //advance past format specifier
+ ++itr; //advance past format specifier
             }
              
           }
           else { //skip past chars in format and in buffer
- itr++;
+ ++itr;
             // set use_current_char when sitr is already
             // pointing at the next character to process
             if (use_current_char) {
               use_current_char = false;
             }
             else {
- sitr++;
+ ++sitr;
             }
           }
         }
@@ -1149,7 +1212,8 @@
         this->m_sv_parser.match(sitr, stream_end, mr);
         if(mr.current_match == match_results::PARSE_ERROR) {
           std::string tmp = convert_string_type<char_type, char>(mr.cache);
- throw std::ios_base::failure("Parse failed. No match found for '" + tmp + "'");
+ boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + tmp + "'"));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return sitr); // should never reach
         }
         tt = temporal_type(static_cast<special_values>(mr.current_match));
         return sitr;

Modified: trunk/boost/date_time/time_formatting_streams.hpp
==============================================================================
--- trunk/boost/date_time/time_formatting_streams.hpp (original)
+++ trunk/boost/date_time/time_formatting_streams.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -9,12 +9,16 @@
  * $Date$
  */
 
-
-#include "boost/date_time/date_formatting_locales.hpp"
-#include "boost/date_time/time_resolution_traits.hpp"
+#include <boost/date_time/compiler_config.hpp>
 
 #ifndef BOOST_DATE_TIME_NO_LOCALE
 
+#include <locale>
+#include <iomanip>
+#include <iostream>
+#include <boost/date_time/date_formatting_locales.hpp>
+#include <boost/date_time/time_resolution_traits.hpp>
+
 namespace boost {
 namespace date_time {
 
@@ -116,4 +120,3 @@
 #endif //BOOST_DATE_TIME_NO_LOCALE
 
 #endif
-

Modified: trunk/boost/date_time/time_system_split.hpp
==============================================================================
--- trunk/boost/date_time/time_system_split.hpp (original)
+++ trunk/boost/date_time/time_system_split.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -132,7 +132,7 @@
     }
     static std::string zone_name(const time_rep_type&)
     {
- return "";
+ return std::string();
     }
     static bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs)
     {
@@ -166,12 +166,9 @@
         return add_time_duration(base,td1);
       }
 
- //std::cout << td.ticks() << std::endl;
       wrap_int_type day_offset(base.time_of_day.ticks());
       date_duration_type day_overflow(static_cast<typename date_duration_type::duration_rep_type>(day_offset.subtract(td.ticks())));
-// std::cout << "sub: " << base.time_of_day.ticks() << "|"
-// << day_offset.as_int() << "|"
-// << day_overflow.days() << std::endl;
+
       return time_rep_type(base.day-day_overflow,
                            time_duration_type(0,0,0,day_offset.as_int()));
     }
@@ -185,13 +182,10 @@
         time_duration_type td1 = td.invert_sign();
         return subtract_time_duration(base,td1);
       }
+
       wrap_int_type day_offset(base.time_of_day.ticks());
- typename date_duration_type::duration_rep_type doff = day_offset.add(td.ticks());
-// std::cout << "day overflow: " << doff << std::endl;
-// std::cout << "ticks: " << td.ticks() << std::endl;
- date_duration_type day_overflow(doff);
-// std::cout << "base: " << to_simple_string(base.day) << std::endl;
-// std::cout << "overflow " << day_overflow.days() << std::endl;
+ date_duration_type day_overflow(static_cast< typename date_duration_type::duration_rep_type >(day_offset.add(td.ticks())));
+
       return time_rep_type(base.day+day_overflow,
                            time_duration_type(0,0,0,day_offset.as_int()));
     }

Modified: trunk/boost/date_time/tz_db_base.hpp
==============================================================================
--- trunk/boost/date_time/tz_db_base.hpp (original)
+++ trunk/boost/date_time/tz_db_base.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -8,17 +8,19 @@
  * $Date$
  */
 
-#include "boost/shared_ptr.hpp"
-#include "boost/date_time/time_zone_names.hpp"
-#include "boost/date_time/time_zone_base.hpp"
-#include "boost/date_time/time_parsing.hpp"
-#include "boost/tokenizer.hpp"
-#include <string>
-#include <sstream>
 #include <map>
 #include <vector>
-#include <stdexcept>
+#include <string>
+#include <sstream>
 #include <fstream>
+#include <stdexcept>
+#include <boost/tokenizer.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/date_time/compiler_config.hpp>
+#include <boost/date_time/time_zone_names.hpp>
+#include <boost/date_time/time_zone_base.hpp>
+#include <boost/date_time/time_parsing.hpp>
 
 namespace boost {
   namespace date_time {
@@ -158,7 +160,7 @@
       typedef typename time_zone_type::base_type time_zone_base_type;
       typedef typename time_zone_type::time_duration_type time_duration_type;
       typedef time_zone_names_base<char_type> time_zone_names;
- typedef dst_adjustment_offsets<time_duration_type> dst_adjustment_offsets;
+ typedef boost::date_time::dst_adjustment_offsets<time_duration_type> dst_adjustment_offsets;
       typedef std::basic_string<char_type> string_type;
 
       //! Constructs an empty database
@@ -173,7 +175,7 @@
         
         std::ifstream ifs(pathspec.c_str());
         if(!ifs){
- throw data_not_accessible(pathspec);
+ boost::throw_exception(data_not_accessible(pathspec));
         }
         std::getline(ifs, buff); // first line is column headings
 
@@ -183,13 +185,13 @@
       }
 
       //! returns true if record successfully added to map
- /*! Takes an id string in the form of "America/Phoenix", and a
+ /*! Takes a region name in the form of "America/Phoenix", and a
        * time_zone object for that region. The id string must be a unique
        * name that does not already exist in the database. */
- bool add_record(const string_type& id,
+ bool add_record(const string_type& region,
                       boost::shared_ptr<time_zone_base_type> tz)
       {
- typename map_type::value_type p(id, tz);
+ typename map_type::value_type p(region, tz);
         return (m_zone_map.insert(p)).second;
       }
 
@@ -307,7 +309,6 @@
        * zone_spec successfully added to database */
       bool parse_string(string_type& s)
       {
-
         std::vector<string_type> result;
         typedef boost::token_iterator_generator<boost::escaped_list_separator<char_type>, string_type::const_iterator, string_type >::type token_iter_type;
 
@@ -326,10 +327,11 @@
         //take a shot at fixing gcc 4.x error
         const unsigned int expected_fields = static_cast<unsigned int>(FIELD_COUNT);
         if (result.size() != expected_fields) {
- std::stringstream msg;
+ std::ostringstream msg;
           msg << "Expecting " << FIELD_COUNT << " fields, got "
             << result.size() << " fields in line: " << s;
- throw bad_field_count(msg.str());
+ boost::throw_exception(bad_field_count(msg.str()));
+ BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return false); // should never reach
         }
 
         // initializations

Modified: trunk/boost/date_time/wrapping_int.hpp
==============================================================================
--- trunk/boost/date_time/wrapping_int.hpp (original)
+++ trunk/boost/date_time/wrapping_int.hpp 2008-11-01 06:34:04 EDT (Sat, 01 Nov 2008)
@@ -43,10 +43,11 @@
    * wraps went. Ex: add a negative number and wrapping under could occur,
    * this would be indicated by a negative return value. If wrapping over
    * took place, a positive value would be returned */
- int_type add(int_type v)
+ template< typename IntT >
+ IntT add(IntT v)
   {
     int_type remainder = static_cast<int_type>(v % (wrap_val));
- int_type overflow = static_cast<int_type>(v / (wrap_val));
+ IntT overflow = static_cast<IntT>(v / (wrap_val));
     value_ = static_cast<int_type>(value_ + remainder);
     return calculate_wrap(overflow);
   }
@@ -56,26 +57,28 @@
    * Ex: subtract a negative number and wrapping over could
    * occur, this would be indicated by a negative return value. If
    * wrapping under took place, a positive value would be returned. */
- int_type subtract(int_type v)
+ template< typename IntT >
+ IntT subtract(IntT v)
   {
     int_type remainder = static_cast<int_type>(v % (wrap_val));
- int_type underflow = static_cast<int_type>(-(v / (wrap_val)));
+ IntT underflow = static_cast<IntT>(-(v / (wrap_val)));
     value_ = static_cast<int_type>(value_ - remainder);
     return calculate_wrap(underflow) * -1;
   }
 private:
   int_type value_;
 
- int_type calculate_wrap(int_type wrap)
+ template< typename IntT >
+ IntT calculate_wrap(IntT wrap)
   {
     if ((value_) >= wrap_val)
     {
- wrap++;
+ ++wrap;
       value_ -= (wrap_val);
     }
     else if(value_ < 0)
     {
- wrap--;
+ --wrap;
       value_ += (wrap_val);
     }
     return wrap;
@@ -114,10 +117,11 @@
    * wraps went. Ex: add a negative number and wrapping under could occur,
    * this would be indicated by a negative return value. If wrapping over
    * took place, a positive value would be returned */
- int_type add(int_type v)
+ template< typename IntT >
+ IntT add(IntT v)
   {
     int_type remainder = static_cast<int_type>(v % (wrap_max - wrap_min + 1));
- int_type overflow = static_cast<int_type>(v / (wrap_max - wrap_min + 1));
+ IntT overflow = static_cast<IntT>(v / (wrap_max - wrap_min + 1));
     value_ = static_cast<int_type>(value_ + remainder);
     return calculate_wrap(overflow);
   }
@@ -126,10 +130,11 @@
    * wraps went. Ex: subtract a negative number and wrapping over could
    * occur, this would be indicated by a positive return value. If
    * wrapping under took place, a negative value would be returned */
- int_type subtract(int_type v)
+ template< typename IntT >
+ IntT subtract(IntT v)
   {
     int_type remainder = static_cast<int_type>(v % (wrap_max - wrap_min + 1));
- int_type underflow = static_cast<int_type>(-(v / (wrap_max - wrap_min + 1)));
+ IntT underflow = static_cast<IntT>(-(v / (wrap_max - wrap_min + 1)));
     value_ = static_cast<int_type>(value_ - remainder);
     return calculate_wrap(underflow);
   }
@@ -137,16 +142,17 @@
 private:
   int_type value_;
 
- int_type calculate_wrap(int_type wrap)
+ template< typename IntT >
+ IntT calculate_wrap(IntT wrap)
   {
     if ((value_) > wrap_max)
     {
- wrap++;
+ ++wrap;
       value_ -= (wrap_max - wrap_min + 1);
     }
     else if((value_) < wrap_min)
     {
- wrap--;
+ --wrap;
       value_ += (wrap_max - wrap_min + 1);
     }
     return wrap;


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