aws-crt-cpp
DateTime.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License").
6  * You may not use this file except in compliance with the License.
7  * A copy of the License is located at
8  *
9  * http://aws.amazon.com/apache2.0
10  *
11  * or in the "license" file accompanying this file. This file is distributed
12  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 #include <aws/crt/Exports.h>
17 
18 #include <aws/crt/Types.h>
19 
20 #include <aws/common/date_time.h>
21 
22 #include <chrono>
23 
24 namespace Aws
25 {
26  namespace Crt
27  {
28  enum class DateFormat
29  {
30  RFC822 = AWS_DATE_FORMAT_RFC822,
31  ISO_8601 = AWS_DATE_FORMAT_ISO_8601,
32  AutoDetect = AWS_DATE_FORMAT_AUTO_DETECT,
33  };
34 
35  enum class Month
36  {
37  January = AWS_DATE_MONTH_JANUARY,
38  February = AWS_DATE_MONTH_FEBRUARY,
39  March = AWS_DATE_MONTH_MARCH,
40  April = AWS_DATE_MONTH_APRIL,
41  May = AWS_DATE_MONTH_MAY,
42  June = AWS_DATE_MONTH_JUNE,
43  July = AWS_DATE_MONTH_JULY,
44  August = AWS_DATE_MONTH_AUGUST,
45  September = AWS_DATE_MONTH_SEPTEMBER,
46  October = AWS_DATE_MONTH_OCTOBER,
47  November = AWS_DATE_MONTH_NOVEMBER,
48  December = AWS_DATE_MONTH_DECEMBER,
49  };
50 
51  enum class DayOfWeek
52  {
53  Sunday = AWS_DATE_DAY_OF_WEEK_SUNDAY,
54  Monday = AWS_DATE_DAY_OF_WEEK_MONDAY,
55  Tuesday = AWS_DATE_DAY_OF_WEEK_TUESDAY,
56  Wednesday = AWS_DATE_DAY_OF_WEEK_WEDNESDAY,
57  Thursday = AWS_DATE_DAY_OF_WEEK_THURSDAY,
58  Friday = AWS_DATE_DAY_OF_WEEK_FRIDAY,
59  Saturday = AWS_DATE_DAY_OF_WEEK_SATURDAY,
60  };
61 
63  {
64  public:
68  DateTime() noexcept;
69 
73  DateTime(const std::chrono::system_clock::time_point &timepointToAssign) noexcept;
74 
78  DateTime(uint64_t millisSinceEpoch) noexcept;
79 
83  DateTime(double epoch_millis) noexcept;
84 
88  DateTime(const char *timestamp, DateFormat format) noexcept;
89 
90  bool operator==(const DateTime &other) const noexcept;
91  bool operator<(const DateTime &other) const noexcept;
92  bool operator>(const DateTime &other) const noexcept;
93  bool operator!=(const DateTime &other) const noexcept;
94  bool operator<=(const DateTime &other) const noexcept;
95  bool operator>=(const DateTime &other) const noexcept;
96 
97  DateTime operator+(const std::chrono::milliseconds &a) const noexcept;
98  DateTime operator-(const std::chrono::milliseconds &a) const noexcept;
99 
103  DateTime &operator=(double secondsSinceEpoch) noexcept;
104 
108  DateTime &operator=(uint64_t millisSinceEpoch) noexcept;
109 
113  DateTime &operator=(const std::chrono::system_clock::time_point &timepointToAssign) noexcept;
114 
118  DateTime &operator=(const char *timestamp) noexcept;
119 
120  explicit operator bool() const noexcept;
121  int GetLastError() const noexcept;
122 
126  bool ToLocalTimeString(DateFormat format, ByteBuf &outputBuf) const noexcept;
127 
131  bool ToGmtString(DateFormat format, ByteBuf &outputBuf) const noexcept;
132 
136  double SecondsWithMSPrecision() const noexcept;
137 
141  uint64_t Millis() const noexcept;
142 
147  std::chrono::system_clock::time_point UnderlyingTimestamp() const noexcept;
148 
152  uint16_t GetYear(bool localTime = false) const noexcept;
153 
157  Month GetMonth(bool localTime = false) const noexcept;
158 
163  uint8_t GetDay(bool localTime = false) const noexcept;
164 
169  DayOfWeek GetDayOfWeek(bool localTime = false) const noexcept;
170 
174  uint8_t GetHour(bool localTime = false) const noexcept;
175 
179  uint8_t GetMinute(bool localTime = false) const noexcept;
180 
184  uint8_t GetSecond(bool localTime = false) const noexcept;
185 
190  bool IsDST(bool localTime = false) const noexcept;
191 
195  static DateTime Now() noexcept;
196 
201  std::chrono::milliseconds operator-(const DateTime &other) const noexcept;
202 
203  private:
204  aws_date_time m_date_time;
205  bool m_good;
206  };
207  } // namespace Crt
208 } // namespace Aws
Aws::Crt::Month::September
@ September
Aws::Crt::Month::July
@ July
Aws::Crt::Month::May
@ May
Types.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:34
Aws::Crt::Month::December
@ December
Aws::Crt::Month::February
@ February
Aws::Crt::DayOfWeek::Thursday
@ Thursday
Aws::Crt::Month::June
@ June
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:43
Aws::Crt::DayOfWeek::Tuesday
@ Tuesday
Aws::Crt::Month::October
@ October
Aws::Crt::DateFormat
DateFormat
Definition: DateTime.h:29
Aws::Crt::Month::November
@ November
Aws::Crt::DayOfWeek
DayOfWeek
Definition: DateTime.h:52
Aws::format
p format
Definition: cJSON.cpp:1041
Aws
Definition: Api.h:25
Aws::Crt::DayOfWeek::Monday
@ Monday
Exports.h
Aws::Crt::DateFormat::RFC822
@ RFC822
Aws::Crt::Month::April
@ April
Aws::Crt::Month::August
@ August
Aws::Crt::Month::March
@ March
Aws::a
cJSON * a
Definition: cJSON.cpp:2081
Aws::Crt::DateFormat::ISO_8601
@ ISO_8601
Aws::Crt::DayOfWeek::Friday
@ Friday
Aws::Crt::DateFormat::AutoDetect
@ AutoDetect
Aws::Crt::Month::January
@ January
Aws::Crt::DayOfWeek::Saturday
@ Saturday
Aws::Crt::DayOfWeek::Wednesday
@ Wednesday
Aws::Crt::DayOfWeek::Sunday
@ Sunday
Aws::Crt::Month
Month
Definition: DateTime.h:36
Aws::Crt::DateTime
Definition: DateTime.h:63