Kea
1.9.9-git
|
This class parses and generates time values used in HTTP. More...
#include <date_time.h>
Public Member Functions | |
HttpDateTime () | |
Default constructor. More... | |
HttpDateTime (const boost::posix_time::ptime &t) | |
Construct from boost::posix_time::ptime object. More... | |
std::string | asctimeFormat () const |
Returns time value formatted as output of ANSI C's asctime(). More... | |
boost::posix_time::ptime | getPtime () const |
Returns time encapsulated by this class. More... | |
std::string | rfc1123Format () const |
Returns time value formatted as specified in RFC 1123. More... | |
std::string | rfc850Format () const |
Returns time value formatted as specified in RFC 850. More... | |
Static Public Member Functions | |
static HttpDateTime | fromAny (const std::string &time_string) |
Creates an instance from a string containing time value formatted in one of the supported formats. More... | |
static HttpDateTime | fromAsctime (const std::string &time_string) |
Creates an instance from a string containing time value formatted as output from asctime() function. More... | |
static HttpDateTime | fromRfc1123 (const std::string &time_string) |
Creates an instance from a string containing time value formatted as specified in RFC 1123. More... | |
static HttpDateTime | fromRfc850 (const std::string &time_string) |
Creates an instance from a string containing time value formatted as specified in RFC 850. More... | |
This class parses and generates time values used in HTTP.
The HTTP protocol have historically allowed 3 different date/time formats (see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html). These are:
The first format is preferred but implementations must also support remaining two obsolete formats for compatibility. This class implements parsers and generators for all three formats. It uses boost::posix_time
to represent time and date. It uses boost::date_time::time_facet
and boost::date_time::time_input_facet
to generate and parse the timestamps.
Definition at line 41 of file date_time.h.
isc::http::HttpDateTime::HttpDateTime | ( | ) |
Default constructor.
Sets current universal time as time value. Time resolution is to seconds (i.e no fractional seconds).
Definition at line 21 of file date_time.cc.
Referenced by fromAsctime(), fromRfc1123(), and fromRfc850().
|
explicit |
Construct from boost::posix_time::ptime
object.
t | time value to be set. |
Definition at line 25 of file date_time.cc.
std::string isc::http::HttpDateTime::asctimeFormat | ( | ) | const |
Returns time value formatted as output of ANSI C's asctime().
Definition at line 40 of file date_time.cc.
|
static |
Creates an instance from a string containing time value formatted in one of the supported formats.
This method will detect the format of the time value and parse it. It tries parsing the value in the following order:
time_string | Input string holding formatted time value. |
HttpTimeConversionError | if provided value doesn't match any of the supported formats. |
Definition at line 77 of file date_time.cc.
References fromAsctime(), fromRfc1123(), fromRfc850(), and isc_throw.
|
static |
Creates an instance from a string containing time value formatted as output from asctime() function.
time_string | Input string holding formatted time value. |
HttpTimeConversionError | if provided timestamp has invalid format. |
Definition at line 59 of file date_time.cc.
References HttpDateTime().
Referenced by fromAny().
|
static |
Creates an instance from a string containing time value formatted as specified in RFC 1123.
time_string | Input string holding formatted time value. |
HttpTimeConversionError | if provided timestamp has invalid format. |
Definition at line 45 of file date_time.cc.
References HttpDateTime().
Referenced by fromAny().
|
static |
Creates an instance from a string containing time value formatted as specified in RFC 850.
time_string | Input string holding formatted time value. |
HttpTimeConversionError | if provided timestamp has invalid format. |
Definition at line 52 of file date_time.cc.
References HttpDateTime().
Referenced by fromAny().
|
inline |
Returns time encapsulated by this class.
boost::posix_time::ptime
value encapsulated by the instance of this class. Definition at line 59 of file date_time.h.
std::string isc::http::HttpDateTime::rfc1123Format | ( | ) | const |
Returns time value formatted as specified in RFC 1123.
Definition at line 30 of file date_time.cc.
Referenced by isc::http::HttpResponse::getDateHeaderValue(), and isc::ha::HAService::processHeartbeat().
std::string isc::http::HttpDateTime::rfc850Format | ( | ) | const |
Returns time value formatted as specified in RFC 850.
Definition at line 35 of file date_time.cc.