Ticket #1861: date_time_long_hours_patch2.patch
File date_time_long_hours_patch2.patch, 12.4 KB (added by , 14 years ago) |
---|
-
boost/date_time/time_facet.hpp
159 159 template <class CharT> 160 160 const typename time_formats<CharT>::char_type 161 161 time_formats<CharT>::default_time_duration_format[11] = 162 {'%',' H',':','%','M',':','%','S','%','F'};162 {'%','O',':','%','M',':','%','S','%','F'}; 163 163 164 164 165 165 -
boost/date_time/format_date_parser.hpp
100 100 inline 101 101 int_type 102 102 var_string_to_int(std::istreambuf_iterator<charT>& itr, 103 std::istreambuf_iterator<charT>& /* stream_end */,103 const std::istreambuf_iterator<charT>& stream_end, 104 104 unsigned int max_length) 105 105 { 106 106 typedef std::basic_string<charT> string_type; 107 107 unsigned int j = 0; 108 108 string_type s; 109 while ( (j < max_length) && std::isdigit(*itr)) {109 while (itr != stream_end && (j < max_length) && std::isdigit(*itr)) { 110 110 s += (*itr); 111 111 itr++; 112 112 j++; -
libs/date_time/test/posix_time/testtime_facet.cpp
197 197 ss.str(""); 198 198 } 199 199 200 // "Long" time durations (longer then 24 hours) checks 201 { 202 std::string result; 203 std::stringstream ss; 204 time_duration td9(101, 23, 34); 205 ss << td9; 206 result = "101:23:34"; 207 check("Long time_duration", result == ss.str()); 208 } 209 200 210 // The test verifies that #2698 is fixed. That is, the time and date facet should 201 211 // not dereference end() iterator for the format string in do_put_tm. 202 212 { -
libs/date_time/test/posix_time/testtime_serialize.cpp
32 32 #else 33 33 time_duration td(12,13,52,123456); 34 34 #endif 35 time_duration td_l(101, 23, 45); 35 36 ptime pt(d, td); 36 37 time_period tp(pt, ptime(date(2002, Oct, 31), hours(19))); 37 38 ptime sv_pt1(not_a_date_time); … … 41 42 // for loading in from archive 42 43 date d2(not_a_date_time); 43 44 time_duration td2(1,0,0); 45 time_duration td2_l(1, 0, 0); 44 46 ptime pt2(d2, td2); 45 47 time_period tp2(pt2, hours(1)); 46 48 ptime sv_pt3(min_date_time); … … 66 68 save_to(oa, BOOST_SERIALIZATION_NVP(sv_pt2)); 67 69 save_to(oa, BOOST_SERIALIZATION_NVP(tp)); 68 70 save_to(oa, BOOST_SERIALIZATION_NVP(td)); 71 save_to(oa, BOOST_SERIALIZATION_NVP(td_l)); 69 72 save_to(oa, BOOST_SERIALIZATION_NVP(sv_td)); 70 73 #else 71 74 save_to(oa, pt); … … 73 76 save_to(oa, sv_pt2); 74 77 save_to(oa, tp); 75 78 save_to(oa, td); 79 save_to(oa, td_l); 76 80 save_to(oa, sv_td); 77 81 #endif // DATE_TIME_XML_SERIALIZE 78 82 }catch(archive::archive_exception& ae){ … … 95 99 ia >> BOOST_SERIALIZATION_NVP(sv_pt4); 96 100 ia >> BOOST_SERIALIZATION_NVP(tp2); 97 101 ia >> BOOST_SERIALIZATION_NVP(td2); 102 ia >> BOOST_SERIALIZATION_NVP(td2_l); 98 103 ia >> BOOST_SERIALIZATION_NVP(sv_td2); 99 104 #else 100 105 ia >> pt2; … … 102 107 ia >> sv_pt4; 103 108 ia >> tp2; 104 109 ia >> td2; 110 ia >> td2_l; 105 111 ia >> sv_td2; 106 112 #endif // DATE_TIME_XML_SERIALIZE 107 113 }catch(archive::archive_exception& ae){ … … 115 121 check("special_values ptime (pos_infin)", sv_pt2 == sv_pt4); 116 122 check("time_period", tp == tp2); 117 123 check("time_duration", td == td2); 124 check("time_duration long", td_l == td2_l); 118 125 check("special_values time_duration (neg_infin)", sv_td == sv_td2); 119 126 120 127 return printTestStats(); -
libs/date_time/test/posix_time/testtime_input_facet.cpp
104 104 #endif 105 105 106 106 // test all flags that appear in time_input_facet 107 iss.clear(); 107 108 iss.str("12:34:56 2005-Jan-15 12:34:56"); 108 109 iss >> td; 109 110 iss >> pt; … … 111 112 // the following test insures %F parsing stops at the appropriate point 112 113 check("Default format ptime", pt == ptime(date(2005,01,15),time_duration(12,34,56))); 113 114 115 iss.clear(); 114 116 iss.str("14:13:12 extra stuff"); // using default %H:%M:%S%F format 115 117 iss >> td; 116 118 check("Default frac_sec format time_duration", td == time_duration(14,13,12)); 119 120 iss.clear(); 121 iss.str("100:11:22"); // default format should work for more than 24 hours 122 iss >> td; 123 check("Default format time_duration longer then 24 hours", 124 td == time_duration(100, 11, 22)); 117 125 118 126 time_input_facet* facet = new time_input_facet(); 119 127 std::locale loc(std::locale::classic(), facet); 120 128 facet->time_duration_format("%H:%M:%S%f"); 121 129 iss.imbue(loc); 122 130 131 iss.clear(); 123 132 iss.str("14:13:12.0 extra stuff"); 124 133 iss >> td; 125 134 check("Required-frac_sec format time_duration", td == time_duration(14,13,12)); 126 135 136 iss.clear(); 127 137 iss.str("12"); 128 138 facet->time_duration_format("%H"); 129 139 iss >> td; 130 140 check("Hours format", td == hours(12)); 131 141 142 iss.clear(); 143 iss.str("101"); 144 facet->time_duration_format("%O"); 145 iss >> td; 146 check("Hours format long", td == hours(101)); 147 148 iss.clear(); 132 149 iss.str("05"); 133 150 facet->time_duration_format("%M"); 134 151 iss >> td; 135 152 check("Minutes format", td == minutes(5)); 136 153 154 iss.clear(); 137 155 iss.str("45"); 138 156 facet->time_duration_format("%S"); 139 157 iss >> td; 140 158 check("Seconds w/o frac_sec format", td == seconds(45)); 141 159 160 iss.clear(); 142 161 iss.str("10.01"); 143 162 facet->time_duration_format("%s"); 144 163 iss >> td; … … 148 167 check("Seconds w/ frac_sec format", td == time_duration(0,0,10,10000)); 149 168 #endif 150 169 170 iss.clear(); 151 171 iss.str("2005-105T23:59"); 152 172 facet->format("%Y-%jT%H:%M"); // extended ordinal format 153 173 iss >> pt; 154 174 check("Extended Ordinal format", pt == ptime(date(2005,4,15),time_duration(23,59,0))); 155 175 156 176 /* this is not implemented yet. The flags: %I & %p are not parsed 177 iss.clear(); 157 178 iss.str("2005-Jun-14 03:15:00 PM"); 158 179 facet->format("%Y-%b-%d %I:%M:%S %p"); 159 180 iss >> pt; 160 181 check("12 hour time format (AM/PM)", pt == ptime(date(2005,6,14),time_duration(15,15,0))); 161 182 */ 162 183 184 iss.clear(); 163 185 iss.str("2005-Jun-14 15:15:00 %d"); 164 186 facet->format("%Y-%b-%d %H:%M:%S %%d"); 165 187 iss >> pt; 166 188 check("Literal '%' in format", pt == ptime(date(2005,6,14),time_duration(15,15,0))); 189 iss.clear(); 167 190 iss.str("15:15:00 %d"); 168 191 facet->time_duration_format("%H:%M:%S %%d"); 169 192 iss >> td; 170 193 check("Literal '%' in time_duration format", td == time_duration(15,15,0)); 194 iss.clear(); 171 195 iss.str("2005-Jun-14 15:15:00 %14"); 172 196 facet->format("%Y-%b-%d %H:%M:%S %%%d"); // %% => % & %d => day_of_month 173 197 iss >> pt; 174 198 check("Multiple literal '%'s in format", pt == ptime(date(2005,6,14),time_duration(15,15,0))); 199 iss.clear(); 175 200 iss.str("15:15:00 %15"); 176 201 facet->time_duration_format("%H:%M:%S %%%M"); 177 202 iss >> td; … … 281 306 // special_values tests. prove the individual flags catch special_values 282 307 // NOTE: these flags all by themselves will not parse a complete ptime, 283 308 // these are *specific* special_values tests 309 iss.clear(); 284 310 iss.str("+infinity -infinity"); 285 311 facet->format("%H"); 286 312 facet->time_duration_format("%H"); … … 289 315 check("Special value: ptime %H flag", pt == ptime(pos_infin)); 290 316 check("Special value: time_duration %H flag", td == time_duration(neg_infin)); 291 317 318 iss.clear(); 292 319 iss.str("not-a-date-time +infinity"); 293 320 facet->format("%M"); 294 321 facet->time_duration_format("%M"); … … 297 324 check("Special value: ptime %M flag", pt == ptime(not_a_date_time)); 298 325 check("Special value: time_duration %M flag", td == time_duration(pos_infin)); 299 326 327 iss.clear(); 300 328 iss.str("-infinity not-a-date-time "); 301 329 facet->format("%S"); 302 330 facet->time_duration_format("%S"); … … 305 333 check("Special value: ptime %S flag", pt == ptime(neg_infin)); 306 334 check("Special value: time_duration %S flag", td == time_duration(not_a_date_time)); 307 335 336 iss.clear(); 308 337 iss.str("+infinity -infinity"); 309 338 facet->format("%s"); 310 339 facet->time_duration_format("%s"); … … 313 342 check("Special value: ptime %s flag", pt == ptime(pos_infin)); 314 343 check("Special value: time_duration %s flag", td == time_duration(neg_infin)); 315 344 345 iss.clear(); 316 346 iss.str("not-a-date-time +infinity"); 317 347 facet->format("%j"); 318 348 facet->time_duration_format("%f"); … … 323 353 324 354 // time_period tests - the time_period_parser is thoroughly tested in gregorian tests 325 355 // default period format is closed range so last ptime is included in peiod 356 iss.clear(); 326 357 iss.str("[2005-Jan-01 00:00:00/2005-Dec-31 23:59:59]"); 327 358 facet->format(time_input_facet::default_time_input_format); // reset format 328 359 iss >> tp; -
libs/date_time/test/posix_time/testparse_time.cpp
102 102 } 103 103 #endif 104 104 105 std::string s9b("100:00:00"); // duration may span more than 24 hours 106 time_duration td9= boost::date_time::parse_delimited_time_duration<time_duration>(s9b); 107 check("parse long time duration: " + s9b, 108 td9 == time_duration(100, 0, 0)); 109 105 110 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS 106 111 107 112 std::string ts2("2002-12-31 00:00:00.999999999"); -
libs/date_time/xmldoc/time_facet.xml
72 72 <entry>Sets the time_duration format. The time_duration format has the ability to display the sign of the duration. The <code>'%+'</code> flag will always display the sign. The <code>'%-'</code> will only display if the sign is negative. Currently the '-' and '+' characters are used to denote the sign.</entry> 73 73 </row> 74 74 <row> 75 <entry><screen>f->time_duration_format("%+% H:%M");75 <entry><screen>f->time_duration_format("%+%O:%M"); 76 76 // hours and minutes only w/ sign always displayed 77 77 time_duration td1(3, 15, 56); 78 78 time_duration td2(-12, 25, 32); -
libs/date_time/xmldoc/format_flags.xml
301 301 </row> 302 302 303 303 <row> 304 <entry valign="top" morerows="1"><screen>%O </screen></entry>304 <entry valign="top" morerows="1"><screen>%O *</screen></entry> 305 305 <entry>The number of hours in a time duration as a decimal number (range 0 to max. representable duration); single digits are preceded by a zero.</entry> 306 306 </row> 307 307 <row> … … 309 309 </row> 310 310 311 311 <row> 312 <entry valign="top" morerows="1"><screen>%H</screen></entry> 313 <entry>The number of hours in a time duration as a decimal number (range 0 to 23); single digits 314 are preceded by a zero. Using this flag with a value that is out of range is an undefined 315 behavior. Probably an assertion in a debug version.</entry> 316 </row> 317 <row> 318 <entry><screen></screen></entry> 319 </row> 320 321 <row> 312 322 <entry valign="top" morerows="1"><screen>%I !</screen></entry> 313 323 <entry>The hour as a decimal number using a 12-hour clock</entry> 314 324 </row> … … 481 491 </row> 482 492 483 493 <row> 484 <entry valign="top" morerows="1"><screen>%-% H:%M:%S%F !</screen></entry>494 <entry valign="top" morerows="1"><screen>%-%O:%M:%S%F !</screen></entry> 485 495 <entry>Default time_duration format for output. Sign will only be displayed for negative durations.</entry> 486 496 </row> 487 497 <row> … … 489 499 </row> 490 500 491 501 <row> 492 <entry valign="top" morerows="1"><screen>% H:%M:%S%F</screen></entry>502 <entry valign="top" morerows="1"><screen>%O:%M:%S%F</screen></entry> 493 503 <entry>Default time_duration format for input.</entry> 494 504 </row> 495 505 <row>