32 #include <boost/algorithm/string.hpp>
33 #include <boost/assign.hpp>
34 #include <boost/regex.hpp>
35 #include <boost/unordered_map.hpp>
37 using namespace boost::algorithm;
38 using namespace boost::gregorian;
39 using namespace boost::posix_time;
41 using boost::lexical_cast;
42 using boost::unordered_map;
49 const string FORMAT_HTTP(
"%a, %d %b %Y %H:%M:%S GMT");
59 "^(\\w{3}), (\\d{2}) (\\w{3}) (\\d{4}) (\\d{2}):(\\d{2}):(\\d{2}) GMT$",
60 boost::regbase::perl);
63 string & dia_sem,
string & dia_mes,
64 string & mes,
string & any,
65 string & hora,
string & minut,
string & segon)
67 assert( boost::regex_match(s, RE_RFC822) );
69 boost::regex_match(s, m, RE_RFC822);
81 "^(\\w+), (\\d{2})-(\\w{3})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2}) GMT$",
82 boost::regbase::perl);
85 string & dia_sem,
string & dia_mes,
86 string & mes,
string & any,
87 string & hora,
string & minut,
string & segon)
89 assert( boost::regex_match(s,
RE_RFC850) );
103 "^(\\w{3}) (\\w{3}) ?(\\d{1,2}) (\\d{2}):(\\d{2}):(\\d{2}) (\\d{4})$",
104 boost::regbase::perl);
107 string & dia_sem,
string & dia_mes,
108 string & mes,
string & any,
109 string & hora,
string & minut,
string & segon)
124 const unordered_map<string, int>
DIES_SETMANA = boost::assign::map_list_of
125 (
"mon", 0 ) (
"monday", 0 )
126 (
"tue", 1 ) (
"tuesday", 1 )
127 (
"wed", 2 ) (
"wednesday", 2 )
128 (
"thu", 3 ) (
"thursday", 3 )
129 (
"fri", 4 ) (
"friday", 4 )
130 (
"sat", 5 ) (
"saturday", 5 )
131 (
"sun", 6 ) (
"sunday", 6 );
133 const unordered_map<string, int>
MESOS = boost::assign::map_list_of
152 const time_t r = mktime(&t);
180 const bool es_rfc822 = boost::regex_match(s, RE_RFC822),
181 es_rfc850 = boost::regex_match(s,
RE_RFC850),
182 es_asctime = boost::regex_match(s,
RE_ASCTIME);
184 if (!es_rfc822 && !es_rfc850 && !es_asctime) {
187 string dia_sem, dia_mes, mes, any, hora, minut, segon;
188 void (*implementacio)(
const string&,
string&,
string&,
string&,
string&,
string&,
string&,
string&);
192 else if (es_rfc850) {
196 assert( es_asctime );
199 implementacio(s, dia_sem, dia_mes, mes, any, hora, minut, segon);
200 assert( any.length() == 4 );
202 const auto it_mes =
MESOS.find(to_lower_copy(mes));
203 const auto it_dsem =
DIES_SETMANA.find(to_lower_copy(dia_sem));
212 t.tm_sec = lexical_cast<
int>(segon);
213 t.tm_min = lexical_cast<
int>(minut);
214 t.tm_hour = lexical_cast<
int>(hora);
215 t.tm_mday = lexical_cast<
int>(dia_mes);
216 t.tm_mon = it_mes->second;
217 t.tm_year = lexical_cast<
int>(any) - 1900;
218 t.tm_wday = it_dsem->second;