Hi all, I come across a bug in boost::posix_time::time_from_string(); try { ptime t1(time_from_string("2005-01-01")); cout << to_simple_string(t1) << endl; } catch (...) { cout << "exception thrown" << endl; } The above code will strangely output: "2005-Mar-25 13:01:01" time_from_string() will parse "2005-01-01 12", "2005-01-01 12:23" and "2005-01-01 12:23:33" correctly. It will even parse "2005-01-01 34" to the next day and output "2005-Jan-02 10:00:00" Does anyone have a fix for this bug? It should either parse correctly or it should throw an exception. Thanks Michael
Michael Lin wrote:
Hi all,
I come across a bug in boost::posix_time::time_from_string();
try { ptime t1(time_from_string("2005-01-01")); cout << to_simple_string(t1) << endl; } catch (...) { cout << "exception thrown" << endl; }
The above code will strangely output: "2005-Mar-25 13:01:01"
time_from_string() will parse "2005-01-01 12", "2005-01-01 12:23" and "2005-01-01 12:23:33" correctly.
It will even parse "2005-01-01 34" to the next day and output "2005-Jan-02 10:00:00"
Does anyone have a fix for this bug? It should either parse correctly or it should throw an exception.
Thanks Michael _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
You could parse the elements independently and check it yourself pretty trivially. time_duration td; date d; std::stringstream ss("2005-Jan-01 13:20:20"); ss >> d; ss >> td; if (td.hours() > 23 || td == not_a_date_time) {.... //parse failed.. Didn't compile the above, but should be close :-) from_string treats the second part as a time duration and isn't strict about limiting the input, so that's why it behaves as it does... Jeff
On Thu, 08 Dec 2005 17:41:05 +1100, Michael Lin wrote:
try { ptime t1(time_from_string("2005-01-01")); cout << to_simple_string(t1) << endl; } catch (...) { cout << "exception thrown" << endl; }
You're right, this is a bug. Thanks for bringing this to our attention. Bart
participants (3)
-
Bart
-
Jeff Garland
-
Michael Lin