10#include <boost/date_time/time_facet.hpp> 
   11#include <boost/date_time/local_time/local_time.hpp> 
   15using namespace boost::local_time;
 
   16using namespace boost::posix_time;
 
   22    : time_(boost::posix_time::second_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
 
 
  109HttpDateTime::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");
 
  129HttpDateTime::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());
 
This class parses and generates time values used in HTTP.
std::string rfc1123Format() const
Returns time value formatted as specified in RFC 1123.
HttpDateTime()
Default constructor.
std::string asctimeFormat() const
Returns time value formatted as output of ANSI C's asctime().
static HttpDateTime fromRfc850(const std::string &time_string)
Creates an instance from a string containing time value formatted as specified in RFC 850.
static HttpDateTime fromRfc1123(const std::string &time_string)
Creates an instance from a string containing time value formatted as specified in RFC 1123.
std::string rfc850Format() const
Returns time value formatted as specified in RFC 850.
static HttpDateTime fromAsctime(const std::string &time_string)
Creates an instance from a string containing time value formatted as output from asctime() function.
static HttpDateTime fromAny(const std::string &time_string)
Creates an instance from a string containing time value formatted in one of the supported formats.
Exception thrown when there is an error during time conversion.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.