Ticket #1861: date_time_long_hours_patch2.patch

File date_time_long_hours_patch2.patch, 12.4 KB (added by ilya.bobir@…, 14 years ago)
  • boost/date_time/time_facet.hpp

     
    159159  template <class CharT> 
    160160  const typename time_formats<CharT>::char_type
    161161  time_formats<CharT>::default_time_duration_format[11] =
    162     {'%','H',':','%','M',':','%','S','%','F'};
     162    {'%','O',':','%','M',':','%','S','%','F'};
    163163
    164164
    165165
  • boost/date_time/format_date_parser.hpp

     
    100100inline
    101101int_type
    102102var_string_to_int(std::istreambuf_iterator<charT>& itr,
    103                   std::istreambuf_iterator<charT>& /* stream_end */,
     103                  const std::istreambuf_iterator<charT>& stream_end,
    104104                  unsigned int max_length)
    105105{
    106106  typedef std::basic_string<charT>  string_type;
    107107  unsigned int j = 0;
    108108  string_type s;
    109   while ((j < max_length) && std::isdigit(*itr)) {
     109  while (itr != stream_end && (j < max_length) && std::isdigit(*itr)) {
    110110    s += (*itr);
    111111    itr++;
    112112    j++;
  • libs/date_time/test/posix_time/testtime_facet.cpp

     
    197197      ss.str("");
    198198    }
    199199
     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
    200210    // The test verifies that #2698 is fixed. That is, the time and date facet should
    201211    // not dereference end() iterator for the format string in do_put_tm.
    202212    {
  • libs/date_time/test/posix_time/testtime_serialize.cpp

     
    3232#else
    3333  time_duration td(12,13,52,123456);
    3434#endif
     35  time_duration td_l(101, 23, 45);
    3536  ptime pt(d, td);
    3637  time_period tp(pt, ptime(date(2002, Oct, 31), hours(19)));
    3738  ptime sv_pt1(not_a_date_time);
     
    4142  // for loading in from archive
    4243  date d2(not_a_date_time);
    4344  time_duration td2(1,0,0);
     45  time_duration td2_l(1, 0, 0);
    4446  ptime pt2(d2, td2);
    4547  time_period tp2(pt2, hours(1));
    4648  ptime sv_pt3(min_date_time);
     
    6668    save_to(oa, BOOST_SERIALIZATION_NVP(sv_pt2));
    6769    save_to(oa, BOOST_SERIALIZATION_NVP(tp));
    6870    save_to(oa, BOOST_SERIALIZATION_NVP(td));
     71    save_to(oa, BOOST_SERIALIZATION_NVP(td_l));
    6972    save_to(oa, BOOST_SERIALIZATION_NVP(sv_td));
    7073#else
    7174    save_to(oa, pt);
     
    7376    save_to(oa, sv_pt2);
    7477    save_to(oa, tp);
    7578    save_to(oa, td);
     79    save_to(oa, td_l);
    7680    save_to(oa, sv_td);
    7781#endif // DATE_TIME_XML_SERIALIZE
    7882  }catch(archive::archive_exception& ae){
     
    9599    ia >> BOOST_SERIALIZATION_NVP(sv_pt4);
    96100    ia >> BOOST_SERIALIZATION_NVP(tp2);
    97101    ia >> BOOST_SERIALIZATION_NVP(td2);
     102    ia >> BOOST_SERIALIZATION_NVP(td2_l);
    98103    ia >> BOOST_SERIALIZATION_NVP(sv_td2);
    99104#else
    100105    ia >> pt2;
     
    102107    ia >> sv_pt4;
    103108    ia >> tp2;
    104109    ia >> td2;
     110    ia >> td2_l;
    105111    ia >> sv_td2;
    106112#endif // DATE_TIME_XML_SERIALIZE
    107113  }catch(archive::archive_exception& ae){
     
    115121  check("special_values ptime (pos_infin)", sv_pt2 == sv_pt4);
    116122  check("time_period", tp == tp2);
    117123  check("time_duration", td == td2);
     124  check("time_duration long", td_l == td2_l);
    118125  check("special_values time_duration (neg_infin)", sv_td == sv_td2);
    119126
    120127  return printTestStats();
  • libs/date_time/test/posix_time/testtime_input_facet.cpp

     
    104104#endif
    105105
    106106  // test all flags that appear in time_input_facet
     107  iss.clear();
    107108  iss.str("12:34:56 2005-Jan-15 12:34:56");
    108109  iss >> td;
    109110  iss >> pt;
     
    111112  // the following test insures %F parsing stops at the appropriate point
    112113  check("Default format ptime", pt == ptime(date(2005,01,15),time_duration(12,34,56)));
    113114 
     115  iss.clear();
    114116  iss.str("14:13:12 extra stuff"); // using default %H:%M:%S%F format
    115117  iss >> td;
    116118  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));
    117125 
    118126  time_input_facet* facet = new time_input_facet();
    119127  std::locale loc(std::locale::classic(), facet);
    120128  facet->time_duration_format("%H:%M:%S%f");
    121129  iss.imbue(loc);
    122130
     131  iss.clear();
    123132  iss.str("14:13:12.0 extra stuff");
    124133  iss >> td;
    125134  check("Required-frac_sec format time_duration", td == time_duration(14,13,12));
    126135
     136  iss.clear();
    127137  iss.str("12");
    128138  facet->time_duration_format("%H");
    129139  iss >> td;
    130140  check("Hours format", td == hours(12));
    131141
     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();
    132149  iss.str("05");
    133150  facet->time_duration_format("%M");
    134151  iss >> td;
    135152  check("Minutes format", td == minutes(5));
    136153
     154  iss.clear();
    137155  iss.str("45");
    138156  facet->time_duration_format("%S");
    139157  iss >> td;
    140158  check("Seconds w/o frac_sec format", td == seconds(45));
    141159
     160  iss.clear();
    142161  iss.str("10.01");
    143162  facet->time_duration_format("%s");
    144163  iss >> td;
     
    148167  check("Seconds w/ frac_sec format", td == time_duration(0,0,10,10000));
    149168#endif
    150169 
     170  iss.clear();
    151171  iss.str("2005-105T23:59");
    152172  facet->format("%Y-%jT%H:%M"); // extended ordinal format
    153173  iss >> pt;
    154174  check("Extended Ordinal format", pt == ptime(date(2005,4,15),time_duration(23,59,0)));
    155175
    156176  /* this is not implemented yet. The flags: %I & %p are not parsed
     177  iss.clear();
    157178  iss.str("2005-Jun-14 03:15:00 PM");
    158179  facet->format("%Y-%b-%d %I:%M:%S %p");
    159180  iss >> pt;
    160181  check("12 hour time format (AM/PM)", pt == ptime(date(2005,6,14),time_duration(15,15,0)));
    161182  */
    162183
     184  iss.clear();
    163185  iss.str("2005-Jun-14 15:15:00 %d");
    164186  facet->format("%Y-%b-%d %H:%M:%S %%d");
    165187  iss >> pt;
    166188  check("Literal '%' in format", pt == ptime(date(2005,6,14),time_duration(15,15,0)));
     189  iss.clear();
    167190  iss.str("15:15:00 %d");
    168191  facet->time_duration_format("%H:%M:%S %%d");
    169192  iss >> td;
    170193  check("Literal '%' in time_duration format", td == time_duration(15,15,0));
     194  iss.clear();
    171195  iss.str("2005-Jun-14 15:15:00 %14");
    172196  facet->format("%Y-%b-%d %H:%M:%S %%%d"); // %% => % & %d => day_of_month
    173197  iss >> pt;
    174198  check("Multiple literal '%'s in format", pt == ptime(date(2005,6,14),time_duration(15,15,0)));
     199  iss.clear();
    175200  iss.str("15:15:00 %15");
    176201  facet->time_duration_format("%H:%M:%S %%%M");
    177202  iss >> td;
     
    281306  // special_values tests. prove the individual flags catch special_values
    282307  // NOTE: these flags all by themselves will not parse a complete ptime,
    283308  // these are *specific* special_values tests
     309  iss.clear();
    284310  iss.str("+infinity -infinity");
    285311  facet->format("%H");
    286312  facet->time_duration_format("%H");
     
    289315  check("Special value: ptime %H flag", pt == ptime(pos_infin));
    290316  check("Special value: time_duration %H flag", td == time_duration(neg_infin));
    291317 
     318  iss.clear();
    292319  iss.str("not-a-date-time +infinity");
    293320  facet->format("%M");
    294321  facet->time_duration_format("%M");
     
    297324  check("Special value: ptime %M flag", pt == ptime(not_a_date_time));
    298325  check("Special value: time_duration %M flag", td == time_duration(pos_infin));
    299326 
     327  iss.clear();
    300328  iss.str("-infinity not-a-date-time ");
    301329  facet->format("%S");
    302330  facet->time_duration_format("%S");
     
    305333  check("Special value: ptime %S flag", pt == ptime(neg_infin));
    306334  check("Special value: time_duration %S flag", td == time_duration(not_a_date_time));
    307335 
     336  iss.clear();
    308337  iss.str("+infinity -infinity");
    309338  facet->format("%s");
    310339  facet->time_duration_format("%s");
     
    313342  check("Special value: ptime %s flag", pt == ptime(pos_infin));
    314343  check("Special value: time_duration %s flag", td == time_duration(neg_infin));
    315344 
     345  iss.clear();
    316346  iss.str("not-a-date-time +infinity");
    317347  facet->format("%j");
    318348  facet->time_duration_format("%f");
     
    323353 
    324354  // time_period tests - the time_period_parser is thoroughly tested in gregorian tests
    325355  // default period format is closed range so last ptime is included in peiod
     356  iss.clear();
    326357  iss.str("[2005-Jan-01 00:00:00/2005-Dec-31 23:59:59]");
    327358  facet->format(time_input_facet::default_time_input_format); // reset format
    328359  iss >> tp;
  • libs/date_time/test/posix_time/testparse_time.cpp

     
    102102  }
    103103#endif
    104104
     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
    105110#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
    106111
    107112  std::string ts2("2002-12-31 00:00:00.999999999");
  • libs/date_time/xmldoc/time_facet.xml

     
    7272            <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>
    7373          </row>
    7474          <row>
    75             <entry><screen>f->time_duration_format("%+%H:%M");
     75            <entry><screen>f->time_duration_format("%+%O:%M");
    7676// hours and minutes only w/ sign always displayed
    7777time_duration td1(3, 15, 56);
    7878time_duration td2(-12, 25, 32);
  • libs/date_time/xmldoc/format_flags.xml

     
    301301          </row>
    302302
    303303          <row>
    304             <entry valign="top" morerows="1"><screen>%O</screen></entry>
     304            <entry valign="top" morerows="1"><screen>%O *</screen></entry>
    305305            <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>
    306306          </row>
    307307          <row>
     
    309309          </row>
    310310
    311311          <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>
    312322            <entry valign="top" morerows="1"><screen>%I !</screen></entry>
    313323            <entry>The hour as a decimal number using a 12-hour clock</entry>
    314324          </row>
     
    481491          </row>
    482492
    483493          <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>
    485495            <entry>Default time_duration format for output. Sign will only be displayed for negative durations.</entry>
    486496          </row>
    487497          <row>
     
    489499          </row>
    490500
    491501          <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>
    493503            <entry>Default time_duration format for input.</entry>
    494504          </row>
    495505          <row>