|
Boost Users : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2007-02-27 10:58:26
Gregory J. Sharp wrote:
> I'm trying to use the date_time/ptime module to parse strings.
>
> Platform: MacOS X 10.4.7 on Intel
> Compiler: gcc 4.0.1
>
> I have three potential bugs, so far. Perhaps I'm unreasonable in
> hoping that the
> following strings should be acceptable to time_from_string.
>
> 1. time_from_string( "2006-12-06" ) != time_from_string( "2006-12-06
> 00:00:00" )
> 2. time_from_string( "2006/12/06" ) throws an exception (probably
> related to 1)
> even though time_from_string( "2006,12,06" ) doesn't throw.
> 3. time_from_string( "2006-12-06 " ) throws an exception because it
> passes a null
> string to str_from_delimited_time_duration(), which tries to read
> the first
> character of the string, even though there isn't one.
>
> I think 1 & 2 are probably caused by parse_delimited_time() doing a
> split on ' ' and getting nothing to pass to
> parse_delimited_time_duration().
The main problem is that the time_from_string function is expecting a complete
time (eg: 2006-12-26 00:00:00), not just a date. I believe all of these will
parse correctly if you do this:
using namespace boost::gregorian;
date d = from_string("2006-12-06");
which can trivially be turned into a ptime if that's what you need.
Jeff
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net