Skip to content

Commit 77b7d7d

Browse files
Added date time binding, added string hash function. Improved STL all… (aws#2)
DateTime Bindings/ Json Binding/ Optional Type.
1 parent 0c29940 commit 77b7d7d

22 files changed

+5575
-106
lines changed

CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ file(GLOB AWS_CRT_MQTT_HEADERS
1919
"include/aws/crt/mqtt/*.h"
2020
)
2121

22+
file(GLOB AWS_CRT_EXTERNAL_HEADERS
23+
"include/aws/crt/external/*.h"
24+
)
25+
2226
file(GLOB AWS_CRT_CPP_HEADERS
2327
${AWS_CRT_HEADERS}
2428
${AWS_CRT_IO_HEADERS}
@@ -37,20 +41,28 @@ file (GLOB AWS_CRT_MQTT_SRC
3741
"source/mqtt/*.cpp"
3842
)
3943

44+
file(GLOB AWS_CRT_EXTERNAL_CRC
45+
"source/external/*.cpp"
46+
)
47+
4048
file(GLOB AWS_CRT_CPP_SRC
4149
${AWS_CRT_SRC}
4250
${AWS_CRT_IO_SRC}
43-
${AWS_CRT_MQTT_SRC}
51+
${AWS_CRT_MQTT_SRC}
52+
${AWS_CRT_EXTERNAL_CRC}
4453
)
4554

4655
if (WIN32)
4756
if (MSVC)
4857
source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_HEADERS})
4958
source_group("Header Files\\aws\\crt\\io" FILES ${AWS_CRT_IO_HEADERS})
5059
source_group("Header Files\\aws\\crt\\mqtt" FILES ${AWS_CRT_MQTT_HEADERS})
60+
source_group("Header Files\\aws\\crt\\external" FILES ${AWS_CRT_EXTERNAL_HEADERS})
61+
5162
source_group("Source Files" FILES ${AWS_CRT_SRC})
5263
source_group("Source Files\\io" FILES ${AWS_CRT_IO_SRC})
5364
source_group("Source Files\\mqtt" FILES ${AWS_CRT_MQTT_SRC})
65+
source_group("Source Files\\external" FILES ${AWS_CRT_EXTERNAL_SRC})
5466
endif ()
5567
endif()
5668

@@ -86,6 +98,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME} AWS::aws-c-mqtt)
8698
install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt")
8799
install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io")
88100
install(FILES ${AWS_CRT_MQTT_HEADERS} DESTINATION "include/aws/crt/mqtt")
101+
install(FILES ${AWS_CRT_EXTERNAL_HEADERS} DESTINATION "include/aws/crt/external")
89102

90103
install(
91104
TARGETS ${CMAKE_PROJECT_NAME}

include/aws/crt/DateTime.h

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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+
62+
class AWS_CRT_CPP_API DateTime final
63+
{
64+
public:
65+
/**
66+
* Initializes time point to epoch
67+
*/
68+
DateTime() noexcept;
69+
70+
/**
71+
* Initializes time point to any other arbirtrary timepoint
72+
*/
73+
DateTime(const std::chrono::system_clock::time_point& timepointToAssign) noexcept;
74+
75+
/**
76+
* Initializes time point to millis Since epoch
77+
*/
78+
DateTime(uint64_t millisSinceEpoch) noexcept;
79+
80+
/**
81+
* Initializes time point to epoch time in seconds.millis
82+
*/
83+
DateTime(double epoch_millis) noexcept;
84+
85+
/**
86+
* Initializes time point to value represented by timestamp and format.
87+
*/
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+
100+
/**
101+
* Assign from seconds.millis since epoch.
102+
*/
103+
DateTime& operator=(double secondsSinceEpoch) noexcept;
104+
105+
/**
106+
* Assign from millis since epoch.
107+
*/
108+
DateTime& operator=(uint64_t millisSinceEpoch) noexcept;
109+
110+
/**
111+
* Assign from another time_point
112+
*/
113+
DateTime& operator=(const std::chrono::system_clock::time_point& timepointToAssign) noexcept;
114+
115+
/**
116+
* Assign from an ISO8601 or RFC822 formatted string
117+
*/
118+
DateTime& operator=(const char* timestamp) noexcept;
119+
120+
explicit operator bool() const noexcept;
121+
int GetLastError() const noexcept;
122+
123+
/**
124+
* Convert dateTime to local time string using predefined format.
125+
*/
126+
bool ToLocalTimeString(DateFormat format, ByteBuf& outputBuf) const noexcept;
127+
128+
/**
129+
* Convert dateTime to GMT time string using predefined format.
130+
*/
131+
bool ToGmtString(DateFormat format, ByteBuf& outputBuf) const noexcept;
132+
133+
/**
134+
* Get the representation of this datetime as seconds.milliseconds since epoch
135+
*/
136+
double SecondsWithMSPrecision() const noexcept;
137+
138+
/**
139+
* Milliseconds since epoch of this datetime.
140+
*/
141+
uint64_t Millis() const noexcept;
142+
143+
/**
144+
* In the likely case this class doesn't do everything you need to do, here's a copy of the time_point structure. Have fun.
145+
*/
146+
std::chrono::system_clock::time_point UnderlyingTimestamp() const noexcept;
147+
148+
/**
149+
* Get the Year portion of this dateTime. localTime if true, return local time, otherwise return UTC
150+
*/
151+
uint16_t GetYear(bool localTime = false) const noexcept;
152+
153+
/**
154+
* Get the Month portion of this dateTime. localTime if true, return local time, otherwise return UTC
155+
*/
156+
Month GetMonth(bool localTime = false) const noexcept;
157+
158+
/**
159+
* Get the Day of the Month portion of this dateTime. localTime if true, return local time, otherwise return UTC
160+
*/
161+
uint8_t GetDay(bool localTime = false) const noexcept;
162+
163+
/**
164+
* Get the Day of the Week portion of this dateTime. localTime if true, return local time, otherwise return UTC
165+
*/
166+
DayOfWeek GetDayOfWeek(bool localTime = false) const noexcept;
167+
168+
/**
169+
* Get the Hour portion of this dateTime. localTime if true, return local time, otherwise return UTC
170+
*/
171+
uint8_t GetHour(bool localTime = false) const noexcept;
172+
173+
/**
174+
* Get the Minute portion of this dateTime. localTime if true, return local time, otherwise return UTC
175+
*/
176+
uint8_t GetMinute(bool localTime = false) const noexcept;
177+
178+
/**
179+
* Get the Second portion of this dateTime. localTime if true, return local time, otherwise return UTC
180+
*/
181+
uint8_t GetSecond(bool localTime = false) const noexcept;
182+
183+
/**
184+
* Get whether or not this dateTime is in Daylight savings time. localTime if true, return local time, otherwise return UTC
185+
*/
186+
bool IsDST(bool localTime = false) const noexcept;
187+
188+
/**
189+
* Get an instance of DateTime representing this very instant.
190+
*/
191+
static DateTime Now() noexcept;
192+
193+
/**
194+
* Computes the difference between two DateTime instances and returns the difference
195+
* in milliseconds.
196+
*/
197+
std::chrono::milliseconds operator - (const DateTime& other) const noexcept;
198+
199+
private:
200+
aws_date_time m_date_time;
201+
bool m_good;
202+
};
203+
}
204+
}

0 commit comments

Comments
 (0)