AWS IoT Device SDK C++ v2: crt/aws-crt-cpp/include/aws/crt/DateTime.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

DateTime.h
Go to the documentation of this file.
1#pragma once
6#include <aws/crt/Exports.h>
7
8#include <aws/crt/Types.h>
9
10#include <aws/common/date_time.h>
11
12#include <chrono>
13
14namespace Aws
15{
16 namespace Crt
17 {
18 enum class DateFormat
19 {
20 RFC822 = AWS_DATE_FORMAT_RFC822,
21 ISO_8601 = AWS_DATE_FORMAT_ISO_8601,
22 AutoDetect = AWS_DATE_FORMAT_AUTO_DETECT,
23 };
24
25 enum class Month
26 {
27 January = AWS_DATE_MONTH_JANUARY,
28 February = AWS_DATE_MONTH_FEBRUARY,
29 March = AWS_DATE_MONTH_MARCH,
30 April = AWS_DATE_MONTH_APRIL,
31 May = AWS_DATE_MONTH_MAY,
32 June = AWS_DATE_MONTH_JUNE,
33 July = AWS_DATE_MONTH_JULY,
34 August = AWS_DATE_MONTH_AUGUST,
35 September = AWS_DATE_MONTH_SEPTEMBER,
36 October = AWS_DATE_MONTH_OCTOBER,
37 November = AWS_DATE_MONTH_NOVEMBER,
38 December = AWS_DATE_MONTH_DECEMBER,
39 };
40
41 enum class DayOfWeek
42 {
43 Sunday = AWS_DATE_DAY_OF_WEEK_SUNDAY,
44 Monday = AWS_DATE_DAY_OF_WEEK_MONDAY,
45 Tuesday = AWS_DATE_DAY_OF_WEEK_TUESDAY,
46 Wednesday = AWS_DATE_DAY_OF_WEEK_WEDNESDAY,
47 Thursday = AWS_DATE_DAY_OF_WEEK_THURSDAY,
48 Friday = AWS_DATE_DAY_OF_WEEK_FRIDAY,
49 Saturday = AWS_DATE_DAY_OF_WEEK_SATURDAY,
50 };
51
52 class AWS_CRT_CPP_API DateTime final
53 {
54 public:
58 DateTime() noexcept;
59
63 DateTime(const std::chrono::system_clock::time_point &timepointToAssign) noexcept;
64
68 DateTime(uint64_t millisSinceEpoch) noexcept;
69
73 DateTime(double epoch_millis) noexcept;
74
78 DateTime(const char *timestamp, DateFormat format) noexcept;
79
80 bool operator==(const DateTime &other) const noexcept;
81 bool operator<(const DateTime &other) const noexcept;
82 bool operator>(const DateTime &other) const noexcept;
83 bool operator!=(const DateTime &other) const noexcept;
84 bool operator<=(const DateTime &other) const noexcept;
85 bool operator>=(const DateTime &other) const noexcept;
86
87 DateTime operator+(const std::chrono::milliseconds &a) const noexcept;
88 DateTime operator-(const std::chrono::milliseconds &a) const noexcept;
89
93 DateTime &operator=(double secondsSinceEpoch) noexcept;
94
98 DateTime &operator=(uint64_t millisSinceEpoch) noexcept;
99
103 DateTime &operator=(const std::chrono::system_clock::time_point &timepointToAssign) noexcept;
104
108 DateTime &operator=(const char *timestamp) noexcept;
109
110 explicit operator bool() const noexcept;
111 int GetLastError() const noexcept;
112
116 bool ToLocalTimeString(DateFormat format, ByteBuf &outputBuf) const noexcept;
117
121 bool ToGmtString(DateFormat format, ByteBuf &outputBuf) const noexcept;
122
126 double SecondsWithMSPrecision() const noexcept;
127
131 uint64_t Millis() const noexcept;
132
137 std::chrono::system_clock::time_point UnderlyingTimestamp() const noexcept;
138
142 uint16_t GetYear(bool localTime = false) const noexcept;
143
147 Month GetMonth(bool localTime = false) const noexcept;
148
153 uint8_t GetDay(bool localTime = false) const noexcept;
154
159 DayOfWeek GetDayOfWeek(bool localTime = false) const noexcept;
160
164 uint8_t GetHour(bool localTime = false) const noexcept;
165
169 uint8_t GetMinute(bool localTime = false) const noexcept;
170
174 uint8_t GetSecond(bool localTime = false) const noexcept;
175
180 bool IsDST(bool localTime = false) const noexcept;
181
185 static DateTime Now() noexcept;
186
191 std::chrono::milliseconds operator-(const DateTime &other) const noexcept;
192
193 private:
194 aws_date_time m_date_time;
195 bool m_good;
196 };
197 } // namespace Crt
198} // namespace Aws
Types.h
Aws::Crt::DateTime
Definition: DateTime.h:53
Exports.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::operator<=
constexpr bool operator<=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:765
Aws::Crt::operator<
bool operator<(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:715
Aws::Crt::operator>=
constexpr bool operator>=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:790
Aws::Crt::DateFormat
DateFormat
Definition: DateTime.h:19
Aws::Crt::DateFormat::AutoDetect
@ AutoDetect
Aws::Crt::DateFormat::ISO_8601
@ ISO_8601
Aws::Crt::DateFormat::RFC822
@ RFC822
Aws::Crt::operator>
constexpr bool operator>(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:740
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:32
Aws::Crt::Month
Month
Definition: DateTime.h:26
Aws::Crt::Month::May
@ May
Aws::Crt::Month::July
@ July
Aws::Crt::Month::April
@ April
Aws::Crt::Month::August
@ August
Aws::Crt::Month::February
@ February
Aws::Crt::Month::June
@ June
Aws::Crt::Month::November
@ November
Aws::Crt::Month::December
@ December
Aws::Crt::Month::January
@ January
Aws::Crt::Month::September
@ September
Aws::Crt::Month::October
@ October
Aws::Crt::Month::March
@ March
Aws::Crt::DayOfWeek
DayOfWeek
Definition: DateTime.h:42
Aws::Crt::DayOfWeek::Tuesday
@ Tuesday
Aws::Crt::DayOfWeek::Monday
@ Monday
Aws::Crt::DayOfWeek::Thursday
@ Thursday
Aws::Crt::DayOfWeek::Wednesday
@ Wednesday
Aws::Crt::DayOfWeek::Saturday
@ Saturday
Aws::Crt::DayOfWeek::Sunday
@ Sunday
Aws::Crt::DayOfWeek::Friday
@ Friday
Aws::Crt::operator==
bool operator==(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:665
Aws::Crt::operator!=
bool operator!=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:690
Aws
Definition: Api.h:17
Aws::format
char const int const cJSON_bool format
Definition: cJSON.h:181
Aws::a
cJSON * a
Definition: cJSON.cpp:2562