id summary reporter owner description type status milestone component version severity resolution keywords cc 3967 Parsing dates using date_input_facet accepts wrong input anonymous az_sw_dude "Hi! I got no answer on the ML, but I consider this a bug. With the code below I try to automagically determine the date format found in input files. I'd expect the code below to find the date format ""%d.%m.%Y"" for ""05.02.2008"", but I got surprised by obtaining ""%m/%d/%Y"". It seems like date accepts '.' where I said ""expect '/'"", so I think this should be changed. #include #include #include #include #include #include #include #include inline std::string determine_date_format(std::string const & s) { using namespace boost::assign; using namespace boost::gregorian; std::list possible_formats = // TODO: add others here! list_of (""%Y-%m-%d"")(""%Y/%m/%d"")(""%m/%d/%Y"")(""%d.%m.%Y""); bool inform_user = false; BOOST_FOREACH(std::string const & format, possible_formats) { if (inform_user) { std::cout << ""Trying format '"" << format << ""' ..."" << std::endl; } try { date_input_facet * input_facet = new date_input_facet(format.c_str()); std::istringstream iss(s); iss.imbue(std::locale(iss.getloc(), input_facet)); date d(not_a_date_time); iss >> d; if (!iss.fail() && (!d.is_not_a_date())) { return format; } std::cout << ""WARNING: date format '"" << format << ""' does not match '"" << s << ""'."" << std::endl; inform_user = true; } catch(...) { } } std::cout << ""WARNING: date format not recognized. "" << ""Please reconfigure your measurement equipment "" << ""to ISO standard output!"" << std::endl; return """"; } int main() { std::string the_date = ""05.02.2008""; std::string format = determine_date_format(the_date); std::cout << the_date << "" has date-time-format "" << format << std::endl; return 0; } " Bugs new Boost 1.43.0 date_time Boost 1.37.0 Showstopper