AWS SDK for C++  1.9.109
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:
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 
126 
130  Aws::String ToLocalTimeString(const char* formatStr) const;
131 
136 
140  Aws::String ToGmtString(const char* formatStr) const;
141 
145  double SecondsWithMSPrecision() const;
146 
150  int64_t Seconds() const;
151 
155  int64_t Millis() const;
156 
160  std::chrono::system_clock::time_point UnderlyingTimestamp() const;
161 
165  int GetYear(bool localTime = false) const;
166 
170  Month GetMonth(bool localTime = false) const;
171 
175  int GetDay(bool localTime = false) const;
176 
180  DayOfWeek GetDayOfWeek(bool localTime = false) const;
181 
185  int GetHour(bool localTime = false) const;
186 
190  int GetMinute(bool localTime = false) const;
191 
195  int GetSecond(bool localTime = false) const;
196 
200  bool IsDST(bool localTime = false) const;
201 
205  static DateTime Now();
206 
210  static int64_t CurrentTimeMillis();
211 
215  static Aws::String CalculateLocalTimestampAsString(const char* formatStr);
216 
220  static Aws::String CalculateGmtTimestampAsString(const char* formatStr);
221 
225  static int CalculateCurrentHour();
226 
231 
237 
241  static std::chrono::milliseconds Diff(const DateTime& a, const DateTime& b);
242 
243  std::chrono::milliseconds operator - (const DateTime& other) const;
244  private:
245  std::chrono::system_clock::time_point m_time;
246  bool m_valid;
247 
248  void ConvertTimestampStringToTimePoint(const char* timestamp, DateFormat format);
249  tm GetTimeStruct(bool localTime) const;
250  tm ConvertTimestampToLocalTimeStruct() const;
251  tm ConvertTimestampToGmtStruct() const;
252  };
253 
254  } // namespace Utils
255 } // namespace Aws
Aws::Utils::DateTime
Definition: DateTime.h:55
Aws::Utils::DayOfWeek::Sunday
@ Sunday
Aws::Utils::DateTime::DateTime
DateTime()
Aws::Utils::DateTime::IsDST
bool IsDST(bool localTime=false) const
Aws::Utils::DateTime::Now
static DateTime Now()
Aws::Utils::DateTime::ToLocalTimeString
Aws::String ToLocalTimeString(DateFormat format) const
AWS_CORE_API
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25
Aws::Utils::DateTime::DateTime
DateTime(double epoch_millis)
Aws::Utils::DayOfWeek
DayOfWeek
Definition: DateTime.h:41
Aws::Utils::DateTime::ComputeCurrentTimestampInAmazonFormat
static double ComputeCurrentTimestampInAmazonFormat()
Aws::Utils::DateTime::ToLocalTimeString
Aws::String ToLocalTimeString(const char *formatStr) const
Aws::Utils::DateTime::operator-
DateTime operator-(const std::chrono::milliseconds &a) const
Aws::Utils::DateTime::CalculateLocalTimestampAsString
static Aws::String CalculateLocalTimestampAsString(const char *formatStr)
Aws::Utils::DateTime::Millis
int64_t Millis() const
Aws::Utils::Month::January
@ January
Aws::Utils::DateTime::DateTime
DateTime(int64_t millisSinceEpoch)
Aws::Utils::DateFormat
DateFormat
Definition: DateTime.h:17
format
char const int const cJSON_bool format
Definition: cJSON.h:174
Aws::Utils::DateFormat::RFC822
@ RFC822
Aws::Utils::DateTime::GetHour
int GetHour(bool localTime=false) const
Aws::Utils::DateTime::Seconds
int64_t Seconds() const
Aws::Utils::DateTime::operator=
DateTime & operator=(const Aws::String &timestamp)
b
const cJSON *const b
Definition: cJSON.h:267
Aws::Utils::DateTime::GetMinute
int GetMinute(bool localTime=false) const
Aws::Utils::DateTime::DateTime
DateTime(const char *timestamp, DateFormat format)
Aws::Utils::DateTime::operator=
DateTime & operator=(double secondsSinceEpoch)
Aws::Utils::DateTime::Diff
static std::chrono::milliseconds Diff(const DateTime &a, const DateTime &b)
Aws::Utils::DateTime::UnderlyingTimestamp
std::chrono::system_clock::time_point UnderlyingTimestamp() const
Aws::Utils::DateTime::operator=
DateTime & operator=(int64_t millisSinceEpoch)
AWSString.h
Aws::Utils::DateTime::GetSecond
int GetSecond(bool localTime=false) const
Aws::Utils::DateTime::ToGmtString
Aws::String ToGmtString(const char *formatStr) const
Aws::Utils::Month
Month
Definition: DateTime.h:25
Aws::Utils::DateTime::GetDay
int GetDay(bool localTime=false) const
Aws::Utils::DateTime::DateTime
DateTime(const std::chrono::system_clock::time_point &timepointToAssign)
Aws::Utils::DateTime::GetMonth
Month GetMonth(bool localTime=false) const
Core_EXPORTS.h
Aws::Utils::DateTime::operator=
DateTime & operator=(const std::chrono::system_clock::time_point &timepointToAssign)
Aws
Definition: AccessManagementClient.h:15
Aws::Utils::DateTime::SecondsWithMSPrecision
double SecondsWithMSPrecision() const
Aws::Utils::DateTime::CalculateGmtTimeWithMsPrecision
static Aws::String CalculateGmtTimeWithMsPrecision()
Aws::Utils::DateTime::CalculateCurrentHour
static int CalculateCurrentHour()
Aws::Utils::DateTime::CalculateGmtTimestampAsString
static Aws::String CalculateGmtTimestampAsString(const char *formatStr)
Aws::String
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::Utils::DateTime::GetDayOfWeek
DayOfWeek GetDayOfWeek(bool localTime=false) const
Aws::Utils::DateTime::operator+
DateTime operator+(const std::chrono::milliseconds &a) const
Aws::Utils::DateTime::DateTime
DateTime(const Aws::String &timestamp, DateFormat format)
Aws::Utils::DateTime::GetYear
int GetYear(bool localTime=false) const
Aws::Utils::DateTime::WasParseSuccessful
bool WasParseSuccessful() const
Definition: DateTime.h:120
Aws::Utils::DateTime::ToGmtString
Aws::String ToGmtString(DateFormat format) const
Aws::Utils::DateTime::CurrentTimeMillis
static int64_t CurrentTimeMillis()