[date_time] howto determine date format?
Hi!
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". A major pain it is with those dates.
Whether my shallow knowledge of locales and imbue
or boost::date_time (from boost-1.37.0) is to be blamed is
beyond my horizon.
I feel like date accepts '.' where I said "expect '/'", so I think
this should be changed. I may be wrong.
Could you please shed some light on the issue?
Thanks, Markus
#include
BOOST_FOREACH(std: :string const
%20format,%20possible_formats)%0A>%20%20%20%20%20%7B%0A>%20%20%20%20%20%20%20%20%20if%20(inform_user)%0A>%20%20%20%20%20%20%20%20%20%7B%0A>%20%20%20%20%20%20%20%20%20%20%20%20%20std: :cout%20<<%20%22Trying%20format%20'%22%20<<%20format%20<<%20%22'%20...%22%20<<%20std::endl;%20%0A>%20%20%20%20%20%20%20%20%20%7D%20%0A>%20%0A>%20%20%20%20%20%20%20%20%20try%0A>%20%20%20%20%20%20%20%20%20%7B%0A>%20%20%20%20%20%20%20%20%20%20%20%20%20date_input_facet%20*%20input_facet%20:
std: :istringstream iss(s); iss.imbue(std: :locale(iss.getloc(), input_facet));
Content-type: text/plain; charset=UTF-8 Date: Thu, 15 Apr 2010 23:47:31 -0400 Message-id: <1271389651.25933.26.camel@localhost> MIME-version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-1.fc12) Content-transfer-encoding: 7bit On 2010-02-24 14:08, Markus Werle wrote:
Hi!
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". A major pain it is with those dates. Whether my shallow knowledge of locales and imbue or boost::date_time (from boost-1.37.0) is to be blamed is beyond my horizon.
I feel like date accepts '.' where I said "expect '/'", so I think this should be changed. I may be wrong.
Could you please shed some light on the issue?
Thanks, Markus
#include
#include
#include #include #include #include #include <string> #include <list>
inline std::string determine_date_format(std::string const
I'm having the similar problems, with similar code. It's aggravating.
Oh, yeah, I have boost-1.39.0-9.fc12.x86_64.
This is what happens when I run the executable:
echo "1230735660" | ./dateIO
5660-Dec-07 00:00:00 %m/%d/%Y %H:%M:%S
It thinks 1230735660 is in the format %m/%d/%Y %H:%M:%S, as if 3 were
the separator, which then produces m=12, d=07 and Y=5660. How come? If I
want / to be the separator, then / should be the separator, not 3.
And this is the code:
// g++ -g -Wall -o dateIO dateIO.C -lboost_date_time
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string>
#include
participants (2)
-
Amadeus W.M.
-
Markus Werle