On 27Feb2007, at 15:15 , Jeff Garland wrote
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?
On MacOS 10.4.7 the following program prints:
2006-12-30 == 2007-03-23T14:12:30
It should crash, but something magical happens, except when the
separator is /. Scary stuff.
-- snip --
#include "boost/date_time/posix_time/posix_time.hpp"
#include <iostream>
using namespace boost::posix_time;
main(int argc, char * argv[])
{
std::string d( "2006-12-30" );
ptime x( time_from_string( d ) );
std::cout << d << " == " << to_iso_extended_string( x ) <<
std::endl;
}
-- snip --
I think you could fix this to be more forgiving (and accept a date
without a time) by changing the split function in boost/date_time/
time_parser.hpp as follows. It would also not crash if there on
inputs like "2007-10-02 " and "2006-11-12 4" (double space).
int sep_pos = static_cast<int>(s.find(sep));
first = s.substr(0,sep_pos);
// Skip leading space on time field (catches double space
between fields)
sep_pos = s.find_first_not_of(sep, sep_pos+1);
if ( pos == std::string::npos ) {
second = "";
} else {
// There might be a time field. Strip leading space.
second = s.substr(sep_pos); // NOTE: removed the +1
}
return true;
and then in parse_delimited_time() change it to
//split date/time on a unique delimiter char such as ' ' or 'T'
std::string date_string, tod_string;
split(s, sep, date_string, tod_string);
//call parse_date with first string
date_type d = parse_date