Kea  1.5.0
date_time.h
Go to the documentation of this file.
1 // Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef HTTP_DATE_TIME_H
8 #define HTTP_DATE_TIME_H
9 
10 #include <exceptions/exceptions.h>
11 #include <boost/date_time/posix_time/posix_time.hpp>
12 #include <string>
13 
14 namespace isc {
15 namespace http {
16 
22 public:
23  HttpTimeConversionError(const char* file, size_t line, const char* what) :
24  isc::Exception(file, line, what) { };
25 };
26 
41 class HttpDateTime {
42 public:
43 
47  HttpDateTime();
48 
52  explicit HttpDateTime(const boost::posix_time::ptime& t);
53 
58  boost::posix_time::ptime getPtime() const {
59  return (time_);
60  }
61 
66  std::string rfc1123Format() const;
67 
72  std::string rfc850Format() const;
73 
79  std::string asctimeFormat() const;
80 
88  static HttpDateTime fromRfc1123(const std::string& time_string);
89 
97  static HttpDateTime fromRfc850(const std::string& time_string);
98 
106  static HttpDateTime fromAsctime(const std::string& time_string);
107 
121  static HttpDateTime fromAny(const std::string& time_string);
122 
123 private:
124 
129  std::string toString(const std::string& format,
130  const std::string& method_name) const;
131 
148  static boost::posix_time::ptime
149  fromString(const std::string& time_string, const std::string& format,
150  const std::string& method_name, const bool zone_check = true);
151 
153  boost::posix_time::ptime time_;
154 
155 };
156 
157 } // namespace http
158 } // namespace isc
159 
160 #endif
isc::http::HttpDateTime::fromRfc850
static HttpDateTime fromRfc850(const std::string &time_string)
Creates an instance from a string containing time value formatted as specified in RFC 850.
Definition: date_time.cc:52
isc::http::HttpDateTime::rfc1123Format
std::string rfc1123Format() const
Returns time value formatted as specified in RFC 1123.
Definition: date_time.cc:30
isc::http::HttpDateTime::HttpDateTime
HttpDateTime()
Default constructor.
Definition: date_time.cc:21
isc::http::HttpDateTime::fromAsctime
static HttpDateTime fromAsctime(const std::string &time_string)
Creates an instance from a string containing time value formatted as output from asctime() function.
Definition: date_time.cc:59
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::util::str::format
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
Definition: strutil.cc:157
isc::http::HttpDateTime::asctimeFormat
std::string asctimeFormat() const
Returns time value formatted as output of ANSI C's asctime().
Definition: date_time.cc:40
isc::http::HttpTimeConversionError::HttpTimeConversionError
HttpTimeConversionError(const char *file, size_t line, const char *what)
Definition: date_time.h:23
isc::http::HttpDateTime::fromRfc1123
static HttpDateTime fromRfc1123(const std::string &time_string)
Creates an instance from a string containing time value formatted as specified in RFC 1123.
Definition: date_time.cc:45
isc::http::HttpDateTime::fromAny
static HttpDateTime fromAny(const std::string &time_string)
Creates an instance from a string containing time value formatted in one of the supported formats.
Definition: date_time.cc:77
exceptions.h
isc::http::HttpDateTime::getPtime
boost::posix_time::ptime getPtime() const
Returns time encapsulated by this class.
Definition: date_time.h:58
isc::http::HttpDateTime::rfc850Format
std::string rfc850Format() const
Returns time value formatted as specified in RFC 850.
Definition: date_time.cc:35
isc::http::HttpDateTime
This class parses and generates time values used in HTTP.
Definition: date_time.h:41
isc::http::HttpTimeConversionError
Exception thrown when there is an error during time conversion.
Definition: date_time.h:21