You.i Engine
YiDateTime.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_DATE_TIME_H_
3 #define _YI_DATE_TIME_H_
4 
5 #include "framework/YiPredef.h"
6 #include "utility/YiString.h"
7 
18 {
19 public:
23  typedef int64_t TimeDelta;
24 
28  CYIDateTime(const CYIString &rDateTimeString);
29 
34  CYIDateTime(const time_t epochTime);
35 
39  CYIDateTime();
40 
44  virtual ~CYIDateTime();
45 
49  bool IsValid() const;
50 
54  uint32_t GetDay() const;
55 
59  bool SetDay(uint32_t day);
60 
64  uint32_t GetMonth() const;
65 
70  bool SetMonth(uint32_t month);
71 
75  uint32_t GetYear() const;
76 
80  bool SetYear(uint32_t year);
81 
85  uint32_t GetHour() const;
86 
90  bool SetHour(uint32_t hour);
91 
95  uint32_t GetMinute() const;
96 
100  bool SetMinute(uint32_t minute);
101 
106  uint32_t GetSecond() const;
107 
112  bool SetSecond(uint32_t second);
113 
119  CYIString GetMonthName() const;
120 
127 
133  uint32_t GetDayOfWeek() const;
134 
140  CYIString GetDayOfWeekName() const;
141 
148 
153 
157  bool SetDateTime(const CYIString &rDateTimeString);
158 
162  bool SetDateTimeRFC1123(const CYIString &rDateTimeString);
163 
167  CYIString FormatString(const CYIString &rFormatString) const;
168 
172  enum class StringFormat
173  {
174  ISO_8601,
175  RFC_1123
176  };
177 
182 
186  time_t GetEpochTime() const;
187 
193  bool SetEpochTime(const time_t epochTime);
194 
199  static uint32_t GetDaysInMonth(const uint32_t month, const uint32_t year);
200 
204  static bool IsLeapYear(const uint32_t year);
205 
211  bool AddYears(const int32_t years);
212 
218  bool AddMonths(const int32_t months);
219 
225  bool AddDays(const int32_t days);
226 
232  bool AddHours(const int32_t hours);
233 
239  bool AddMinutes(const int32_t minutes);
240 
246  bool AddSeconds(const int32_t seconds);
247 
248  virtual bool operator==(const CYIDateTime &rOther) const;
249  virtual bool operator!=(const CYIDateTime &rOther) const;
250  virtual bool operator>(const CYIDateTime &rOther) const;
251  virtual bool operator<(const CYIDateTime &rOther) const;
252  virtual bool operator>=(const CYIDateTime &rOther) const;
253  virtual bool operator<=(const CYIDateTime &rOther) const;
254  virtual bool operator+=(TimeDelta delta);
255  virtual bool operator-=(TimeDelta delta);
256 
257 private:
258  CYIDateTime(const tm &rDateTime);
259  struct tm m_dateTime;
260  time_t m_epochTime;
261  static bool ParseDate(const std::string &rDateTimeString, tm &rDateTime, time_t &rEpochTime);
262  static CYIString FormatString(const struct tm *pDatetime, const CYIString &formatString);
263  static CYIString ConvertFormatToWindowsStyle(const CYIString &rFormatString);
264 };
265 
269 
270 std::ostream &operator<<(std::ostream &rStream, const CYIDateTime &rVal);
271 
274 #endif /* _YI_DATE_TIME_H_ */
bool AddSeconds(const int32_t seconds)
virtual bool operator<(const CYIDateTime &rOther) const
bool SetDay(uint32_t day)
bool SetDateTime(const CYIString &rDateTimeString)
CYIString FormatString(const CYIString &rFormatString) const
int64_t TimeDelta
Definition: YiDateTime.h:23
bool SetHour(uint32_t hour)
Would output a string similar to: Sat, 28 Nov 2009 03:50:37 GMT. Latest HTTP1.1 spec (RFC 1123) uses ...
CYIString GetMonthShortName() const
static bool IsLeapYear(const uint32_t year)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
virtual bool operator<=(const CYIDateTime &rOther) const
uint32_t GetHour() const
bool SetYear(uint32_t year)
uint32_t GetDayOfWeek() const
virtual bool operator-=(TimeDelta delta)
Would output a string similar to: 2008-09-15T15:53:00
bool AddYears(const int32_t years)
virtual bool operator!=(const CYIDateTime &rOther) const
bool SetDateTimeRFC1123(const CYIString &rDateTimeString)
bool AddMinutes(const int32_t minutes)
CYIString GetDayOfWeekName() const
bool IsValid() const
bool SetMonth(uint32_t month)
bool AddHours(const int32_t hours)
StringFormat
Definition: YiDateTime.h:172
virtual bool operator>(const CYIDateTime &rOther) const
virtual bool operator>=(const CYIDateTime &rOther) const
CYIString GetMonthName() const
static CYIDateTime GetCurrentDateTime()
bool AddDays(const int32_t days)
bool SetEpochTime(const time_t epochTime)
uint32_t GetSecond() const
uint32_t GetMinute() const
virtual ~CYIDateTime()
bool AddMonths(const int32_t months)
uint32_t GetDay() const
CYIString GetDayOfWeekShortName() const
uint32_t GetMonth() const
bool SetMinute(uint32_t minute)
Utility class that requires a string as per the following format: http://en.wikipedia.org/wiki/ISO_8601 to construct an instance and provides some commmonly used parts like year, month, hour etc. in different data types and formats. All dates are in the local timezone unless otherwise specified.
Definition: YiDateTime.h:17
CYIDateTime operator+(CYIDateTime lhs, CYIDateTime::TimeDelta delta)
virtual bool operator==(const CYIDateTime &rOther) const
std::ostream & operator<<(std::ostream &rStream, const CYIDateTime &rVal)
CYIDateTime operator-(CYIDateTime lhs, CYIDateTime::TimeDelta delta)
bool SetSecond(uint32_t second)
virtual bool operator+=(TimeDelta delta)
uint32_t GetYear() const
static uint32_t GetDaysInMonth(const uint32_t month, const uint32_t year)
time_t GetEpochTime() const