10 #include <boost/date_time/time_facet.hpp>
11 #include <boost/date_time/local_time/local_time.hpp>
15 using namespace boost::local_time;
16 using namespace boost::posix_time;
21 HttpDateTime::HttpDateTime()
22 : time_(
boost::posix_time::microsec_clock::universal_time()) {
31 return (toString(
"%a, %d %b %Y %H:%M:%S GMT",
"RFC 1123"));
36 return (toString(
"%A, %d-%b-%y %H:%M:%S GMT",
"RFC 850"));
41 return (toString(
"%a %b %e %H:%M:%S %Y",
"asctime"));
47 "%a, %d %b %Y %H:%M:%S %ZP",
54 "%A, %d-%b-%y %H:%M:%S %ZP",
68 std::string time_string_copy(time_string);
69 boost::replace_all(time_string_copy,
" ",
" 0");
71 "%a %b %d %H:%M:%S %Y",
100 "unsupported time format of the '" << time_string
109 HttpDateTime::toString(
const std::string&
format,
110 const std::string& method_name)
const {
111 std::ostringstream s;
114 time_facet* df(
new time_facet(
format.c_str()));
115 s.imbue(std::locale(std::locale::classic(), df));
121 <<
"time value of '" << time_ <<
"'"
122 <<
" to " << method_name <<
" format");
129 HttpDateTime::fromString(
const std::string& time_string,
130 const std::string&
format,
131 const std::string& method_name,
132 const bool zone_check) {
133 std::istringstream s(time_string);
136 time_input_facet* tif(
new time_input_facet(
format));
137 s.imbue(std::locale(std::locale::classic(), tif));
139 time_zone_ptr zone(
new posix_time_zone(
"GMT"));
140 local_date_time ldt = local_microsec_clock::local_time(zone);
146 (zone_check && (!ldt.zone() ||
147 ldt.zone()->std_zone_abbrev() !=
"GMT"))) {
148 isc_throw(HttpTimeConversionError,
"unable to parse "
149 << method_name <<
" time value of '"
150 << time_string <<
"'");
153 return (ldt.local_time());