AWS SDK for C++  1.8.95
AWS SDK for C++
DateTime.h
Go to the documentation of this file.
1 
6 #pragma once
7 
10 #include <chrono>
11 
12 namespace Aws
13 {
14  namespace Utils
15  {
16  enum class DateFormat
17  {
18  RFC822, //for http headers
19  ISO_8601, //for query and xml payloads
20  ISO_8601_BASIC, // for retry headers and signers
22  };
23 
24  enum class Month
25  {
26  January = 0,
27  February,
28  March,
29  April,
30  May,
31  June,
32  July,
33  August,
34  September,
35  October,
36  November,
37  December
38  };
39 
40  enum class DayOfWeek
41  {
42  Sunday = 0,
43  Monday,
44  Tuesday,
45  Wednesday,
46  Thursday,
47  Friday,
48  Saturday
49  };
50 
55  {
56  public:
60  DateTime();
61 
65  DateTime(const std::chrono::system_clock::time_point& timepointToAssign);
66 
70  DateTime(int64_t millisSinceEpoch);
71 
75  DateTime(double epoch_millis);
76 
80  DateTime(const Aws::String& timestamp, DateFormat format);
81 
85  DateTime(const char* timestamp, DateFormat format);
86 
87  bool operator == (const DateTime& other) const;
88  bool operator < (const DateTime& other) const;
89  bool operator > (const DateTime& other) const;
90  bool operator != (const DateTime& other) const;
91  bool operator <= (const DateTime& other) const;
92  bool operator >= (const DateTime& other) const;
93 
94  DateTime operator+(const std::chrono::milliseconds& a) const;
95  DateTime operator-(const std::chrono::milliseconds& a) const;
96 
100  DateTime& operator=(double secondsSinceEpoch);
101 
105  DateTime& operator=(int64_t millisSinceEpoch);
106 
110  DateTime& operator=(const std::chrono::system_clock::time_point& timepointToAssign);
111 
115  DateTime& operator=(const Aws::String& timestamp);
116 
120  inline bool WasParseSuccessful() const { return m_valid; }
121 
125  Aws::String ToLocalTimeString(DateFormat format) const;
126 
130  Aws::String ToLocalTimeString(const char* formatStr) const;
131 
135  Aws::String ToGmtString(DateFormat format) const;
136 
140  Aws::String ToGmtString(const char* formatStr) const;
141 
145  double SecondsWithMSPrecision() const;
146 
150  int64_t Millis() const;
151 
155  std::chrono::system_clock::time_point UnderlyingTimestamp() const;
156 
160  int GetYear(bool localTime = false) const;
161 
165  Month GetMonth(bool localTime = false) const;
166 
170  int GetDay(bool localTime = false) const;
171 
175  DayOfWeek GetDayOfWeek(bool localTime = false) const;
176 
180  int GetHour(bool localTime = false) const;
181 
185  int GetMinute(bool localTime = false) const;
186 
190  int GetSecond(bool localTime = false) const;
191 
195  bool IsDST(bool localTime = false) const;
196 
200  static DateTime Now();
201 
205  static int64_t CurrentTimeMillis();
206 
210  static Aws::String CalculateLocalTimestampAsString(const char* formatStr);
211 
215  static Aws::String CalculateGmtTimestampAsString(const char* formatStr);
216 
220  static int CalculateCurrentHour();
221 
225  static double ComputeCurrentTimestampInAmazonFormat();
226 
231  static Aws::String CalculateGmtTimeWithMsPrecision();
232 
236  static std::chrono::milliseconds Diff(const DateTime& a, const DateTime& b);
237 
238  std::chrono::milliseconds operator - (const DateTime& other) const;
239  private:
240  std::chrono::system_clock::time_point m_time;
241  bool m_valid;
242 
243  void ConvertTimestampStringToTimePoint(const char* timestamp, DateFormat format);
244  tm GetTimeStruct(bool localTime) const;
245  tm ConvertTimestampToLocalTimeStruct() const;
246  tm ConvertTimestampToGmtStruct() const;
247  };
248 
249  } // namespace Utils
250 } // namespace Aws
const cJSON *const b
Definition: cJSON.h:255
bool WasParseSuccessful() const
Definition: DateTime.h:120
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25
char const int const cJSON_bool format
Definition: cJSON.h:164