Botan 3.13.0
Crypto and TLS for C&
calendar.h
Go to the documentation of this file.
1/*
2* Calendar Functions
3* (C) 1999-2009,2015 Jack Lloyd
4* (C) 2015 Simon Warta (Kullo GmbH)
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_CALENDAR_H_
10#define BOTAN_CALENDAR_H_
11
12#include <botan/types.h>
13#include <chrono>
14
15namespace Botan {
16
17/**
18* Struct representing a particular date and time
19*/
21 public:
22 /** The year, less than or equal to 9999 */
23 uint32_t year() const { return m_year; }
24
25 /** The month, 1 through 12 for Jan to Dec */
26 uint32_t month() const { return m_month; }
27
28 /** The day of the month, 1 through 31 */
29 uint32_t day() const { return m_day; }
30
31 /** Hour in 24-hour form, 0 to 23 */
32 uint32_t hour() const { return m_hour; }
33
34 /** Minutes in the hour, 0 to 59 */
35 uint32_t minutes() const { return m_minutes; }
36
37 /** Seconds in the minute, 0 to 59 */
38 uint32_t seconds() const { return m_seconds; }
39
40 /**
41 * Initialize a calendar_point
42 * @param y the year
43 * @param mon the month
44 * @param d the day
45 * @param h the hour
46 * @param min the minute
47 * @param sec the second
48 */
49 calendar_point(uint32_t y, uint32_t mon, uint32_t d, uint32_t h, uint32_t min, uint32_t sec);
50
51 /**
52 * Convert a time_point to a calendar_point
53 * @param time_point a time point from the system clock
54 */
55 explicit calendar_point(const std::chrono::system_clock::time_point& time_point);
56
57 /**
58 * Return seconds since epoch
59 *
60 * This is negative for dates before 1970
61 */
62 int64_t seconds_since_epoch() const;
63
64 /**
65 * Returns an STL timepoint object
66 *
67 * Note this throws an exception if the time is not representable
68 * in the system time_t
69 */
70 std::chrono::system_clock::time_point to_std_timepoint() const;
71
72 private:
73 uint16_t m_year;
74 uint8_t m_month;
75 uint8_t m_day;
76 uint8_t m_hour;
77 uint8_t m_minutes;
78 uint8_t m_seconds;
79};
80
81} // namespace Botan
82
83#endif
#define BOTAN_TEST_API
Definition api.h:41
uint32_t hour() const
Definition calendar.h:32
uint32_t seconds() const
Definition calendar.h:38
uint32_t day() const
Definition calendar.h:29
calendar_point(uint32_t y, uint32_t mon, uint32_t d, uint32_t h, uint32_t min, uint32_t sec)
Definition calendar.cpp:83
uint32_t minutes() const
Definition calendar.h:35
uint32_t month() const
Definition calendar.h:26
uint32_t year() const
Definition calendar.h:23