Kea: isc::http::HttpDateTime Class Reference

| Kea 3.0.2-git

isc::http::HttpDateTime Class Reference

This class parses and generates time values used in HTTP. More...

`#include <date_time.h>`

## Public Member Functions
| HttpDateTime ()
| Default constructor.
| HttpDateTime (const boost::posix_time::ptime &t)
| Construct from `boost::posix_time::ptime` object.
std::string | asctimeFormat () const
| Returns time value formatted as output of ANSI C's asctime().
boost::posix_time::ptime | getPtime () const
| Returns time encapsulated by this class.
std::string | rfc1123Format () const
| Returns time value formatted as specified in RFC 1123.
std::string | rfc850Format () const
| Returns time value formatted as specified in RFC 850.

## 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.
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 | fromRfc1123 (const std::string &time_string)
| Creates an instance from a string containing time value formatted as specified in RFC 1123.
static HttpDateTime | fromRfc850 (const std::string &time_string)
| Creates an instance from a string containing time value formatted as specified in RFC 850.

## Detailed Description

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:

- Sun, 06 Nov 1994 08:49:37 GMT
- Sunday, 06-Nov-94 08:49:37 GMT
- Sun Nov 6 08:49:37 1994

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.

## Constructor & Destructor Documentation

## ◆ HttpDateTime() [1/2]

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 fromAny(), fromAsctime(), fromRfc1123(), and fromRfc850().

## ◆ HttpDateTime() [2/2]

isc::http::HttpDateTime::HttpDateTime | ( | const boost::posix_time::ptime & | t | ) |
| explicit

Construct from `boost::posix_time::ptime` object.

Parameters

  t | time value to be set.

Definition at line 25 of file date_time.cc.

## Member Function Documentation

## ◆ asctimeFormat()

std::string isc::http::HttpDateTime::asctimeFormat | ( |  | ) | const

Returns time value formatted as output of ANSI C's asctime().

Returns
  A string containing time value formatted as Sun Nov 6 08:49:37 1994.

Definition at line 40 of file date_time.cc.

## ◆ fromAny()

HttpDateTime isc::http::HttpDateTime::fromAny | ( | const std::string & | time_string | ) |
| 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:

- a format specified in RFC 1123,
- a format specified in RFC 850,
- a format of asctime output.

Parameters

  time_string | Input string holding formatted time value.

Returns
  Instance of HttpDateTime.

Exceptions

  HttpTimeConversionError | if provided value doesn't match any of the supported formats.

Definition at line 77 of file date_time.cc.

References HttpDateTime(), fromAsctime(), fromRfc1123(), fromRfc850(), and isc_throw.

Here is the call graph for this function:

## ◆ fromAsctime()

HttpDateTime isc::http::HttpDateTime::fromAsctime | ( | const std::string & | time_string | ) |
| static

Creates an instance from a string containing time value formatted as output from asctime() function.

Parameters

  time_string | Input string holding formatted time value.

Returns
  Instance of HttpDateTime.

Exceptions

  HttpTimeConversionError | if provided timestamp has invalid format.

Definition at line 59 of file date_time.cc.

References HttpDateTime().

Referenced by fromAny().

Here is the call graph for this function:

## ◆ fromRfc1123()

HttpDateTime isc::http::HttpDateTime::fromRfc1123 | ( | const std::string & | time_string | ) |
| static

Creates an instance from a string containing time value formatted as specified in RFC 1123.

Parameters

  time_string | Input string holding formatted time value.

Returns
  Instance of HttpDateTime.

Exceptions

  HttpTimeConversionError | if provided timestamp has invalid format.

Definition at line 45 of file date_time.cc.

References HttpDateTime().

Referenced by fromAny().

Here is the call graph for this function:

## ◆ fromRfc850()

HttpDateTime isc::http::HttpDateTime::fromRfc850 | ( | const std::string & | time_string | ) |
| static

Creates an instance from a string containing time value formatted as specified in RFC 850.

Parameters

  time_string | Input string holding formatted time value.

Returns
  Instance of HttpDateTime.

Exceptions

  HttpTimeConversionError | if provided timestamp has invalid format.

Definition at line 52 of file date_time.cc.

References HttpDateTime().

Referenced by fromAny().

Here is the call graph for this function:

## ◆ getPtime()

boost::posix_time::ptime isc::http::HttpDateTime::getPtime | ( |  | ) | const
| inline

Returns time encapsulated by this class.

Returns
  `boost::posix_time::ptime` value encapsulated by the instance of this class.

Definition at line 59 of file date_time.h.

## ◆ rfc1123Format()

std::string isc::http::HttpDateTime::rfc1123Format | ( |  | ) | const

Returns time value formatted as specified in RFC 1123.

Returns
  A string containing time value formatted as Sun, 06 Nov 1994 08:49:37 GMT.

Definition at line 30 of file date_time.cc.

Referenced by isc::http::HttpResponse::getDateHeaderValue(), and isc::ha::HAService::processHeartbeat().

## ◆ rfc850Format()

std::string isc::http::HttpDateTime::rfc850Format | ( |  | ) | const

Returns time value formatted as specified in RFC 850.

Returns
  A string containing time value formatted as Sunday, 06-Nov-94 08:49:37 GMT.

Definition at line 35 of file date_time.cc.

The documentation for this class was generated from the following files:

- date_time.h
- date_time.cc