/src/botan/build/include/botan/internal/calendar.h
Line | Count | Source (jump to first uncovered line) |
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 | | #include <string> |
15 | | |
16 | | namespace Botan { |
17 | | |
18 | | /** |
19 | | * Struct representing a particular date and time |
20 | | */ |
21 | | class BOTAN_TEST_API calendar_point |
22 | | { |
23 | | public: |
24 | | |
25 | | /** The year */ |
26 | 0 | uint32_t year() const { return m_year; } |
27 | | |
28 | | /** The month, 1 through 12 for Jan to Dec */ |
29 | 0 | uint32_t month() const { return m_month; } |
30 | | |
31 | | /** The day of the month, 1 through 31 (or 28 or 30 based on month */ |
32 | 0 | uint32_t day() const { return m_day; } |
33 | | |
34 | | /** Hour in 24-hour form, 0 to 23 */ |
35 | 0 | uint32_t hour() const { return m_hour; } |
36 | | |
37 | | /** Minutes in the hour, 0 to 60 */ |
38 | 0 | uint32_t minutes() const { return m_minutes; } |
39 | | |
40 | | /** Seconds in the minute, 0 to 60, but might be slightly |
41 | | larger to deal with leap seconds on some systems |
42 | | */ |
43 | 0 | uint32_t seconds() const { return m_seconds; } |
44 | | |
45 | | /** |
46 | | * Initialize a calendar_point |
47 | | * @param y the year |
48 | | * @param mon the month |
49 | | * @param d the day |
50 | | * @param h the hour |
51 | | * @param min the minute |
52 | | * @param sec the second |
53 | | */ |
54 | | calendar_point(uint32_t y, uint32_t mon, uint32_t d, uint32_t h, uint32_t min, uint32_t sec) : |
55 | 0 | m_year(y), m_month(mon), m_day(d), m_hour(h), m_minutes(min), m_seconds(sec) {} |
56 | | |
57 | | /** |
58 | | * Convert a time_point to a calendar_point |
59 | | * @param time_point a time point from the system clock |
60 | | */ |
61 | | calendar_point(const std::chrono::system_clock::time_point& time_point); |
62 | | |
63 | | /** |
64 | | * Returns an STL timepoint object |
65 | | */ |
66 | | std::chrono::system_clock::time_point to_std_timepoint() const; |
67 | | |
68 | | /** |
69 | | * Returns a human readable string of the struct's components. |
70 | | * Formatting might change over time. Currently it is RFC339 'iso-date-time'. |
71 | | */ |
72 | | std::string to_string() const; |
73 | | |
74 | | private: |
75 | | uint32_t m_year; |
76 | | uint32_t m_month; |
77 | | uint32_t m_day; |
78 | | uint32_t m_hour; |
79 | | uint32_t m_minutes; |
80 | | uint32_t m_seconds; |
81 | | }; |
82 | | |
83 | | } |
84 | | |
85 | | #endif |