Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | List of all members
Botan::calendar_point Struct Reference

`#include <calendar.h>`

## Public Member Functions
| calendar_point (uint32_t y, uint32_t mon, uint32_t d, uint32_t h, uint32_t min, uint32_t sec)
std::chrono::system_clock::time_point | to_std_timepoint () const
std::string | to_string () const

## Public Attributes
uint32_t | day
uint32_t | hour
uint32_t | minutes
uint32_t | month
uint32_t | seconds
uint32_t | year

## Detailed Description

Struct representing a particular date and time

Definition at line 21 of file calendar.h.

## Constructor & Destructor Documentation

Botan::calendar_point::calendar_point | ( | uint32_t | y,
|  | uint32_t | mon,
|  | uint32_t | d,
|  | uint32_t | h,
|  | uint32_t | min,
|  | uint32_t | sec
| ) |  |
| inline

Initialize a calendar_point

Parameters

  y | the year
  mon | the month
  d | the day
  h | the hour
  min | the minute
  sec | the second

Definition at line 52 of file calendar.h.

Referenced by Botan::calendar_value().

52 :
53 year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}
Botan::calendar_point::year
uint32_t year
Definition: calendar.h:24
Botan::calendar_point::day
uint32_t day
Definition: calendar.h:30
Botan::calendar_point::hour
uint32_t hour
Definition: calendar.h:33
Botan::calendar_point::month
uint32_t month
Definition: calendar.h:27
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:180
Botan::calendar_point::minutes
uint32_t minutes
Definition: calendar.h:36
Botan::calendar_point::seconds
uint32_t seconds
Definition: calendar.h:41

## Member Function Documentation

std::chrono::system_clock::time_point Botan::calendar_point::to_std_timepoint | ( |  | ) | const

Returns an STL timepoint object

Definition at line 117 of file calendar.cpp.

References day, hour, minutes, month, seconds, and to_string().

Referenced by Botan::X509_Time::to_std_timepoint().

118 {
119 if (year < 1970)
120 throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years before 1970.");
121
122 // 32 bit time_t ends at January 19, 2038
123 // https://msdn.microsoft.com/en-us/library/2093ets1.aspx
124 // Throw after 2037 if 32 bit time_t is used
125 if (year > 2037 && sizeof(std::time_t) == 4)
126 {
127 throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2037.");
128 }
129
130 // std::tm: struct without any timezone information
131 std::tm tm;
132 tm.tm_isdst = -1; // i.e. no DST information available
133 tm.tm_sec = seconds;
134 tm.tm_min = minutes;
135 tm.tm_hour = hour;
136 tm.tm_mday = day;
137 tm.tm_mon = month - 1;
138 tm.tm_year = year - 1900;
139
140 // Define a function alias `botan_timegm`
141 #if defined(BOTAN_TARGET_OS_HAS_TIMEGM)
142 std::time_t (&botan_timegm)(std::tm *tm) = timegm;
143 #elif defined(BOTAN_TARGET_OS_HAS_MKGMTIME) && defined(BOTAN_BUILD_COMPILER_IS_MSVC)
144 // http://stackoverflow.com/questions/16647819/timegm-cross-platform
145 std::time_t (&botan_timegm)(std::tm *tm) = _mkgmtime;
146 #elif defined(BOTAN_HAS_BOOST_DATETIME)
147 std::time_t (&botan_timegm)(std::tm *tm) = boost_timegm;
148 #elif defined(BOTAN_OS_TYPE_IS_UNIX)
149 std::time_t (&botan_timegm)(std::tm *tm) = fallback_timegm;
150 #else
151 std::time_t (&botan_timegm)(std::tm *tm) = mktime; // localtime instead...
152 #endif
153
154 // Convert std::tm to std::time_t
155 std::time_t tt = botan_timegm(&tm);
156 if (tt == -1)
157 throw Invalid_Argument("calendar_point couldn't be converted: " + to_string());
158
159 return std::chrono::system_clock::from_time_t(tt);
160 }
Botan::calendar_point::to_string
std::string to_string() const
Definition: calendar.cpp:162
Botan::calendar_point::year
uint32_t year
Definition: calendar.h:24
Botan::calendar_point::day
uint32_t day
Definition: calendar.h:30
Botan::calendar_point::hour
uint32_t hour
Definition: calendar.h:33
Botan::calendar_point::month
uint32_t month
Definition: calendar.h:27
Botan::calendar_point::minutes
uint32_t minutes
Definition: calendar.h:36
Botan::calendar_point::seconds
uint32_t seconds
Definition: calendar.h:41

std::string Botan::calendar_point::to_string | ( |  | ) | const

Returns a human readable string of the struct's components. Formatting might change over time. Currently it is RFC339 'iso-date-time'.

Definition at line 162 of file calendar.cpp.

References minutes, month, and seconds.

Referenced by to_std_timepoint().

163 {
164 // desired format: <YYYY>-<MM>-<dd>T<HH>:<mm>:<ss>
165 std::stringstream output;
166 {
167 using namespace std;
168 output << setfill('0')
169 << setw(4) << year << "-" << setw(2) << month << "-" << setw(2) << day
170 << "T"
171 << setw(2) << hour << ":" << setw(2) << minutes << ":" << setw(2) << seconds;
172 }
173 return output.str();
174 }
Botan::calendar_point::year
uint32_t year
Definition: calendar.h:24
Botan::calendar_point::day
uint32_t day
Definition: calendar.h:30
std
Definition: bigint.h:619
Botan::calendar_point::hour
uint32_t hour
Definition: calendar.h:33
Botan::calendar_point::month
uint32_t month
Definition: calendar.h:27
Botan::calendar_point::minutes
uint32_t minutes
Definition: calendar.h:36
Botan::calendar_point::seconds
uint32_t seconds
Definition: calendar.h:41

## Member Data Documentation

uint32_t Botan::calendar_point::day

The day of the month, 1 through 31 (or 28 or 30 based on month

Definition at line 30 of file calendar.h.

Referenced by to_std_timepoint(), and Botan::X509_Time::X509_Time().

uint32_t Botan::calendar_point::hour

Hour in 24-hour form, 0 to 23

Definition at line 33 of file calendar.h.

Referenced by to_std_timepoint(), and Botan::X509_Time::X509_Time().

uint32_t Botan::calendar_point::minutes

Minutes in the hour, 0 to 60

Definition at line 36 of file calendar.h.

Referenced by to_std_timepoint(), to_string(), and Botan::X509_Time::X509_Time().

uint32_t Botan::calendar_point::month

The month, 1 through 12 for Jan to Dec

Definition at line 27 of file calendar.h.

Referenced by to_std_timepoint(), to_string(), and Botan::X509_Time::X509_Time().

uint32_t Botan::calendar_point::seconds

Seconds in the minute, 0 to 60, but might be slightly larger to deal with leap seconds on some systems

Definition at line 41 of file calendar.h.

Referenced by to_std_timepoint(), to_string(), and Botan::X509_Time::X509_Time().

uint32_t Botan::calendar_point::year

The year

Definition at line 24 of file calendar.h.

Referenced by Botan::X509_Time::X509_Time().

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

- src/lib/utils/calendar.h
- src/lib/utils/calendar.cpp