Botan 2.19.5 Crypto and TLS for C&

Public Member Functions | Public Attributes | List of all members
Botan::calendar_point Class 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)
uint32_t | get_day () const
uint32_t | get_hour () const
uint32_t | get_minutes () const
uint32_t | get_month () const
uint32_t | get_seconds () const
uint32_t | get_year () const
std::chrono::system_clock::time_point | to_std_timepoint () const
std::string | to_string () const

## Public Attributes
BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES | __pad0__: uint32_t year
uint32_t | day
uint32_t | hour
uint32_t | minutes
uint32_t | month
uint32_t | seconds

## Detailed Description

Struct representing a particular date and time

Definition at line 21 of file calendar.h.

## Constructor & Destructor Documentation

## ◆ calendar_point()

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 54 of file calendar.h.

54 :
55 year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}
Botan::calendar_point::day
uint32_t day
Definition: calendar.h:75
Botan::calendar_point::month
uint32_t month
Definition: calendar.h:74
Botan::calendar_point::seconds
uint32_t seconds
Definition: calendar.h:78
Botan::calendar_point::hour
uint32_t hour
Definition: calendar.h:76
Botan::calendar_point::minutes
uint32_t minutes
Definition: calendar.h:77

## Member Function Documentation

## ◆ get_day()

uint32_t Botan::calendar_point::get_day | ( |  | ) | const
| inline

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

Definition at line 32 of file calendar.h.

32{ return day; }

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

## ◆ get_hour()

uint32_t Botan::calendar_point::get_hour | ( |  | ) | const
| inline

Hour in 24-hour form, 0 to 23

Definition at line 35 of file calendar.h.

35{ return hour; }

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

## ◆ get_minutes()

uint32_t Botan::calendar_point::get_minutes | ( |  | ) | const
| inline

Minutes in the hour, 0 to 60

Definition at line 38 of file calendar.h.

38{ return minutes; }

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

## ◆ get_month()

uint32_t Botan::calendar_point::get_month | ( |  | ) | const
| inline

The month, 1 through 12 for Jan to Dec

Definition at line 29 of file calendar.h.

29{ return month; }

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

## ◆ get_seconds()

uint32_t Botan::calendar_point::get_seconds | ( |  | ) | const
| inline

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

Definition at line 43 of file calendar.h.

43{ return seconds; }

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

## ◆ get_year()

uint32_t Botan::calendar_point::get_year | ( |  | ) | const
| inline

The year

Definition at line 26 of file calendar.h.

26{ return year; }

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

## ◆ to_std_timepoint()

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

Returns an STL timepoint object

Definition at line 60 of file calendar.cpp.

61 {
62 if(get_year() < 1970)
63 throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years before 1970");
64
65 // 32 bit time_t ends at January 19, 2038
66 // https://msdn.microsoft.com/en-us/library/2093ets1.aspx
67 // Throw after 2037 if 32 bit time_t is used
68
69 BOTAN_IF_CONSTEXPR(sizeof(std::time_t) == 4)
70 {
71 if(get_year() > 2037)
72 {
73 throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2037 on this system");
74 }
75 }
76
77 // This upper bound is completely arbitrary
78 if(get_year() >= 2400)
79 {
80 throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2400");
81 }
82
83 const uint64_t seconds_64 = (days_since_epoch(get_year(), get_month(), get_day()) * 86400) +
84 (get_hour() * 60 * 60) + (get_minutes() * 60) + get_seconds();
85
86 const time_t seconds_time_t = static_cast<time_t>(seconds_64);
87
88 if(seconds_64 - seconds_time_t != 0)
89 {
90 throw Invalid_Argument("calendar_point::to_std_timepoint time_t overflow");
91 }
92
93 return std::chrono::system_clock::from_time_t(seconds_time_t);
94 }
Botan::calendar_point::get_minutes
uint32_t get_minutes() const
Definition: calendar.h:38
Botan::calendar_point::get_month
uint32_t get_month() const
Definition: calendar.h:29
Botan::calendar_point::get_seconds
uint32_t get_seconds() const
Definition: calendar.h:43
Botan::calendar_point::get_hour
uint32_t get_hour() const
Definition: calendar.h:35
Botan::calendar_point::get_year
uint32_t get_year() const
Definition: calendar.h:26
Botan::calendar_point::get_day
uint32_t get_day() const
Definition: calendar.h:32
BOTAN_IF_CONSTEXPR
#define BOTAN_IF_CONSTEXPR
Definition: compiler.h:176

References BOTAN_IF_CONSTEXPR, get_day(), get_hour(), get_minutes(), get_month(), get_seconds(), and get_year().

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

## ◆ to_string()

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 96 of file calendar.cpp.

97 {
98 // desired format: <YYYY>-<MM>-<dd>T<HH>:<mm>:<ss>
99 std::stringstream output;
100 output << std::setfill('0')
101 << std::setw(4) << get_year() << "-"
102 << std::setw(2) << get_month() << "-"
103 << std::setw(2) << get_day() << "T"
104 << std::setw(2) << get_hour() << ":"
105 << std::setw(2) << get_minutes() << ":"
106 << std::setw(2) << get_seconds();
107 return output.str();
108 }

References get_day(), get_hour(), get_minutes(), get_month(), get_seconds(), and get_year().

## Member Data Documentation

## ◆ __pad0__

BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES Botan::calendar_point::__pad0__

Definition at line 68 of file calendar.h.

## ◆ day

uint32_t Botan::calendar_point::day

Definition at line 75 of file calendar.h.

## ◆ hour

uint32_t Botan::calendar_point::hour

Definition at line 76 of file calendar.h.

## ◆ minutes

uint32_t Botan::calendar_point::minutes

Definition at line 77 of file calendar.h.

## ◆ month

uint32_t Botan::calendar_point::month

Definition at line 74 of file calendar.h.

## ◆ seconds

uint32_t Botan::calendar_point::seconds

Definition at line 78 of file calendar.h.

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

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