[date time] std::out_of_range thrown on date 2012-5-29
Hello all,
Following piece of program gives a std::out_of_range exception:
#include
On Thu, Aug 8, 2013 at 11:13 AM, Matthijs Möhlmann
Hello all,
Following piece of program gives a std::out_of_range exception:
#include
int main(int argc, char **argv) {
boost::posix_time::ptime datetime; datetime = boost::posix_time::time_from_string("2012-5-29"); return 0; }
From the docs it seems you're missing time in the string:
http://www.boost.org/doc/libs/1_54_0/doc/html/date_time/posix_time.html#date... Search for time_from_string. I don't think this is a bug, although the exception could have been more descriptive.
Where can I officially report bugs?
On 8.8.2013 10:13, Matthijs Möhlmann wrote:
Hello all,
Following piece of program gives a std::out_of_range exception:
datetime = boost::posix_time::time_from_string("2012-5-29");
Hi, time_from_string() expects the string contain both date *and* time. So you're simply feeding it with a bad data. I must say that the source for this exception (basic_string::at) is a bit misleading. By looking at code it is probably thrown from str_from_delimited_time_duration() as it doesn't check if its fed with an empty basic_string (as quite likely happens in this case) and always calls at(0). Maybe somebody (you?) could write a patch that does a little bit more checking or add a note to documentation about this behavior. -- Pekka
On 08-08-13 09:47, Pekka Seppänen wrote:
Hi,
time_from_string() expects the string contain both date *and* time. So you're simply feeding it with a bad data.
Well this worked before with boost 1.53, it is faulty behaviour on our side and we fixed it.
I must say that the source for this exception (basic_string::at) is a bit misleading. By looking at code it is probably thrown from str_from_delimited_time_duration() as it doesn't check if its fed with an empty basic_string (as quite likely happens in this case) and always calls at(0).
Maybe somebody (you?) could write a patch that does a little bit more checking or add a note to documentation about this behavior.
-- Pekka
I can try to add a note or patch it, but I do not have much experience with C++ and template programming. And I also haven't got my head around programming using 'Value Semantics' [1]. Do you have some information about that, like an url I can read or a good book... Regards, Matthijs Möhlmann [1] http://www.cplusplus-soup.com/2012/10/value-semantics-and-polymorphism.html
participants (3)
-
Andrey Semashev
-
Matthijs Möhlmann
-
Pekka Seppänen