forked from srsart01/Auto_data-modification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-3_datetime updation.txt
More file actions
235 lines (193 loc) · 7.91 KB
/
code-3_datetime updation.txt
File metadata and controls
235 lines (193 loc) · 7.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#pragma once
#include <aws/core/Core_EXPORTS.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <chrono>
namespace Aws
{
namespace Utils
{
enum class DateFormat
{
RFC822, //for http headers
ISO_8601, //for query and xml payloads
AutoDetect
};
enum class Month
{
January = 0,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
enum class DayOfWeek
{
Sunday = 0,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
/**
* Wrapper for all the weird crap we need to do with timestamps.
*/
class AWS_CORE_API DateTime
{
public:
/**
* Initializes time point to epoch
*/
DateTime();
/**
* Initializes time point to any other arbirtrary timepoint
*/
DateTime(const std::chrono::system_clock::time_point& timepointToAssign);
/**
* Initializes time point to millis Since epoch
*/
DateTime(int64_t millisSinceEpoch);
/**
* Initializes time point to epoch time in seconds.millis
*/
DateTime(double epoch_millis);
/**
* Initializes time point to value represented by timestamp and format.
*/
DateTime(const Aws::String& timestamp, DateFormat format);
/**
* Initializes time point to value represented by timestamp and format.
*/
DateTime(const char* timestamp, DateFormat format);
bool operator == (const DateTime& other) const;
bool operator < (const DateTime& other) const;
bool operator > (const DateTime& other) const;
bool operator != (const DateTime& other) const;
bool operator <= (const DateTime& other) const;
bool operator >= (const DateTime& other) const;
DateTime operator+(const std::chrono::milliseconds& a) const;
DateTime operator-(const std::chrono::milliseconds& a) const;
/**
* Assign from seconds.millis since epoch.
*/
DateTime& operator=(double secondsSinceEpoch);
/**
* Assign from millis since epoch.
*/
DateTime& operator=(int64_t millisSinceEpoch);
/**
* Assign from another time_point
*/
DateTime& operator=(const std::chrono::system_clock::time_point& timepointToAssign);
/**
* Whether or not parsing the timestamp from string was successful.
*/
inline bool WasParseSuccessful() const { return m_valid; }
Aws::String ToLocalTimeString(DateFormat format) const;
Aws::String ToLocalTimeString(const char* formatStr) const;
Aws::String ToGmtString(DateFormat format) const;
Aws::String ToGmtString(const char* formatStr) const;
/**
* Get the representation of this datetime as seconds.milliseconds since epoch
*/
double SecondsWithMSPrecision() const;
/**
* Milliseconds since epoch of this datetime.
*/
int64_t Millis() const;
/**
* 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.
*/
std::chrono::system_clock::time_point UnderlyingTimestamp() const;
/**
* Get the Year portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
int GetYear(bool localTime = false) const;
/**
* Get the Month portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
Month GetMonth(bool localTime = false) const;
/**
* Get the Day of the Month portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
int GetDay(bool localTime = false) const;
/**
* Get the Day of the Week portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
DayOfWeek GetDayOfWeek(bool localTime = false) const;
/**
* Get the Hour portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
int GetHour(bool localTime = false) const;
/**
* Get the Minute portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
int GetMinute(bool localTime = false) const;
/**
* Get the Second portion of this dateTime. localTime if true, return local time, otherwise return UTC
*/
int GetSecond(bool localTime = false) const;
/**
* Get whether or not this dateTime is in Daylight savings time. localTime if true, return local time, otherwise return UTC
*/
bool IsDST(bool localTime = false) const;
/**
* Get an instance of DateTime representing this very instant.
*/
static DateTime Now();
/**
* Get the millis since epoch representing this very instant.
*/
static int64_t CurrentTimeMillis();
/**
* Calculates the current local timestamp, formats it and returns it as a string
*/
static Aws::String CalculateLocalTimestampAsString(const char* formatStr);
/**
* Calculates the current gmt timestamp, formats it, and returns it as a string
*/
static Aws::String CalculateGmtTimestampAsString(const char* formatStr);
/**
* Calculates the current hour of the day in localtime.
*/
static int CalculateCurrentHour();
/**
* The amazon timestamp format is a double with seconds.milliseconds
*/
static double ComputeCurrentTimestampInAmazonFormat();
/**
* Compute the difference between two timestamps.
*/
static std::chrono::milliseconds Diff(const DateTime& a, const DateTime& b);
private:
std::chrono::system_clock::time_point m_time;
bool m_valid;
void ConvertTimestampStringToTimePoint(const char* timestamp, DateFormat format);
tm GetTimeStruct(bool localTime) const;
tm ConvertTimestampToLocalTimeStruct() const;
tm ConvertTimestampToGmtStruct() const;
};
} // namespace Utils
} // namespace Aws