Botan  2.8.0
Crypto and TLS for C++11
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
ythe year
monthe month
dthe day
hthe hour
minthe minute
secthe second

Definition at line 54 of file calendar.h.

54  :
55  year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}

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.

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

32 { return day; }

◆ 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.

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

35 { return hour; }

◆ 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.

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

38 { return minutes; }

◆ 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.

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

29 { return month; }

◆ 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.

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

43 { return seconds; }

◆ get_year()

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

The year

Definition at line 26 of file calendar.h.

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

26 { return year; }

◆ 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.

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

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

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  if(get_year() > 2037 && sizeof(std::time_t) == 4)
69  {
70  throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2037 on this system");
71  }
72  else if(get_year() >= 2400)
73  {
74  // This upper bound is somewhat arbitrary
75  throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2400");
76  }
77 
78  const uint64_t seconds_64 = (days_since_epoch(get_year(), get_month(), get_day()) * 86400) +
79  (get_hour() * 60 * 60) + (get_minutes() * 60) + get_seconds();
80 
81  const time_t seconds_time_t = static_cast<time_t>(seconds_64);
82 
83  if(seconds_64 - seconds_time_t != 0)
84  {
85  throw Invalid_Argument("calendar_point::to_std_timepoint time_t overflow");
86  }
87 
88  return std::chrono::system_clock::from_time_t(seconds_time_t);
89  }
uint32_t get_seconds() const
Definition: calendar.h:43
uint32_t get_month() const
Definition: calendar.h:29
uint32_t get_minutes() const
Definition: calendar.h:38
uint32_t get_hour() const
Definition: calendar.h:35
uint32_t get_day() const
Definition: calendar.h:32
uint32_t get_year() const
Definition: calendar.h:26

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

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

92  {
93  // desired format: <YYYY>-<MM>-<dd>T<HH>:<mm>:<ss>
94  std::stringstream output;
95  output << std::setfill('0')
96  << std::setw(4) << get_year() << "-"
97  << std::setw(2) << get_month() << "-"
98  << std::setw(2) << get_day() << "T"
99  << std::setw(2) << get_hour() << ":"
100  << std::setw(2) << get_minutes() << ":"
101  << std::setw(2) << get_seconds();
102  return output.str();
103  }
uint32_t get_seconds() const
Definition: calendar.h:43
uint32_t get_month() const
Definition: calendar.h:29
uint32_t get_minutes() const
Definition: calendar.h:38
uint32_t get_hour() const
Definition: calendar.h:35
uint32_t get_day() const
Definition: calendar.h:32
uint32_t get_year() const
Definition: calendar.h:26

Member Data Documentation

◆ __pad0__

BOTAN_DEPRECATED_PUBLIC_MEMBER_VARIABLES Botan::calendar_point::__pad0__

Definition at line 73 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: