Kea  2.3.5-git
date_time.h
Go to the documentation of this file.
1 // Copyright (C) 2016-2019 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 
48  HttpDateTime();
49 
53  explicit HttpDateTime(const boost::posix_time::ptime& t);
54 
59  boost::posix_time::ptime getPtime() const {
60  return (time_);
61  }
62 
67  std::string rfc1123Format() const;
68 
73  std::string rfc850Format() const;
74 
80  std::string asctimeFormat() const;
81 
89  static HttpDateTime fromRfc1123(const std::string& time_string);
90 
98  static HttpDateTime fromRfc850(const std::string& time_string);
99 
107  static HttpDateTime fromAsctime(const std::string& time_string);
108 
122  static HttpDateTime fromAny(const std::string& time_string);
123 
124 private:
125 
130  std::string toString(const std::string& format,
131  const std::string& method_name) const;
132 
149  static boost::posix_time::ptime
150  fromString(const std::string& time_string, const std::string& format,
151  const std::string& method_name, const bool zone_check = true);
152 
154  boost::posix_time::ptime time_;
155 
156 };
157 
158 } // namespace http
159 } // namespace isc
160 
161 #endif
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::posix_time::ptime getPtime() const
Returns time encapsulated by this class.
Definition: date_time.h:59
This class parses and generates time values used in HTTP.
Definition: date_time.h:41
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
Exception thrown when there is an error during time conversion.
Definition: date_time.h:21
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
Definition: strutil.cc:157
HttpTimeConversionError(const char *file, size_t line, const char *what)
Definition: date_time.h:23