*** boost/date_time/time_facet.hpp.orig Wed Apr 23 21:42:46 2008 --- boost/date_time/time_facet.hpp Wed Apr 23 23:26:03 2008 *************** *** 16,21 **** --- 16,22 ---- #include #include #include + #include namespace boost { namespace date_time { *************** *** 416,421 **** --- 417,435 ---- positive_sign); } + if (format.find("%H") != string_type::npos) { + /* + * 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 here + * ourself. + */ + string_type hours_str = hours_as_string(a_time_dur); + boost::algorithm::replace_all(format, "%H", hours_str); + } + string_type frac_str; if (format.find(seconds_with_fractional_seconds_format) != string_type::npos) { // replace %s with %S.nnn *************** *** 500,505 **** --- 514,539 ---- return ss.str(); } + static + string_type + hours_as_string(const time_duration_type& a_time, int width = 2) + { + typename time_duration_type::hour_type hours = a_time.hours(); + + std::basic_ostringstream ss; + ss.imbue(std::locale::classic()); // don't want any formatting + ss << std::setw(width) + << std::setfill(static_cast('0')); + #if (defined(BOOST_MSVC) && (_MSC_VER < 1300)) + // JDG [7/6/02 VC++ compatibility] + char_type buff[34]; + ss << _i64toa(static_cast(hours), buff, 10); + #else + ss << hours; + #endif + return ss.str(); + } + private: string_type m_time_duration_format; *************** *** 705,714 **** c = *sitr; } ! long hour = 0; ! long min = 0; ! long sec = 0; ! typename time_duration_type::fractional_seconds_type frac(0); typedef std::num_get num_get; if(!std::has_facet(a_ios.getloc())) { --- 739,752 ---- 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; ! ! hour_type hour = 0; ! min_type min = 0; ! sec_type sec = 0; ! fractional_seconds_type frac(0); typedef std::num_get num_get; if(!std::has_facet(a_ios.getloc())) { *************** *** 726,732 **** case 'H': { match_results mr; ! hour = fixed_string_to_int(sitr, stream_end, mr, 2); if(hour == -1){ return check_special_value(sitr, stream_end, td, c); } --- 764,772 ---- case 'H': { match_results mr; ! // A period may span more than 24 hours. ! hour = var_string_to_int(sitr, stream_end, ! std::numeric_limits::digits10); if(hour == -1){ return check_special_value(sitr, stream_end, td, c); }