
Christian Henning wrote:
Thank you very much. I was not paying to attention. My fault.
For the records, here is a sample that works:
date_input_facet* pMyFacet = new date_input_facet( "%m-%d-%Y" );
std::istringstream oo; oo.imbue( std::locale(oo.getloc(), pMyFacet )); oo.str( "11-03-2006" );
date myDate;
try { oo >> myDate;
date::ymd_type ymd = myDate.year_month_day();
std::cout << myDate; } catch( std::out_of_range oEx ) { std::cout << "Error: " << oEx.what() << std::endl; }
Unfortunately a string like "11-3-1997" wont work since the day is just a single digit. Is that something the date_time lib will be able to understand in the future?
Sure. I've uploaded an experimental change that you can try out to the vault: http://www.boost-consulting.com/vault/index.php?&direction=0&order=&directory=date_time Basically you need to drop the format_date_parser.hpp into you boost/date_time directory. This also allows for single digit days in addition to months. The only reason it's experimental is that it changes the behavior of failures for undelimited string parsing. For example, the iso format 2006021 will now succeed instead of failing. I believe this can be resolved, but it's going to take a bit more time... Jeff