
Gregory J. Sharp wrote:
On 27Feb2007, at 10:58 , Jeff Garland wrote:
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.
Thanks. I didn't see the requirement that it have a time component in the manual. Perhaps it is worth adding a note about that?
The fact that it silently accepts "2006-12-06" but does the wrong thing(TM) with it, is also a worry.
I thought this case threw and exception and "2006,12,06" didn't? And, honestly I find it strange -- what was the constructed value? NADT?
I will try to make a time_from_Gstring() function that parses more aggressively, since I also prefer to avoid things like "2006-05-06 123" being a valid time, in my application.
You might have a look at the iostream, format facet-based parsing approaches. This is the more flexible and complete way to do date-time i/o http://www.boost.org/doc/html/date_time/date_time_io.html I pretty much never use the from_string stuff anymore. Jeff