FAST.Framework  1.0.0
FDateTime.h
1 /******************************************************************************
2 **
3 ** FAST.Framework
4 **
5 ** Created: 2020.08.29
6 ** Author: Boris Fast
7 ** Mail: Support@FAST-Framework.com
8 **
9 ******************************************************************************/
10 
11 #ifndef FDATETIME_H
12 #define FDATETIME_H
13 
14 #include <ctime>
15 
16 using namespace std;
17 
18 #include "FObject.h"
19 
23 enum class FDayOfWeek
24 {
25  Sunday = 0,
26  Monday,
27  Tuesday,
28  Wednesday,
29  Thursday,
30  Friday,
31  Saturday
32 };
33 
37 enum class FDateTimeKind
38 {
39  Unspecified = 0,
40  UTC,
41  Local
42 };
43 
47 class FDateTime : public FObject
48 {
49  public:
50  FDateTime(UInt year, UInt month, UInt day,
51  UInt hour = 0, UInt minute = 0, UInt = 0, FDateTimeKind kind = FDateTimeKind::Local);
52  FDateTime(time_t timestamp);
53  FDateTime();
54  virtual ~FDateTime() = default;
55 
56  Int Year() const;
57  Int Month() const;
58  Int Day() const;
59  Int Hour() const;
60  Int Minute() const;
61  Int Second() const;
62  FDayOfWeek DayOfWeek() const;
63  FDateTimeKind Kind() const;
64 
65  ULong Timestamp() const;
66 
67  Boolean IsDaylightSavingTime() const;
68  Boolean IsLeapYear() const;
69  Int DaysInMonth() const;
70  Int DaysInYear() const;
71  Int DayOfYear() const;
72 
73  FDateTime ToLocalTime() const;
74  FDateTime ToUniversalTime() const;
75 
76  FDateTime AddYears(Int years) const;
77  FDateTime AddMonths(Int months) const;
78  FDateTime AddDays(Int days) const;
79  FDateTime AddHours(Int hours) const;
80  FDateTime AddMinutes(Int minutes) const;
81  FDateTime AddSeconds(Int seconds) const;
82 
83  friend const FTimeSpan operator-(const FDateTime& first,
84  const FDateTime& second);
85  friend Boolean operator==(const FDateTime& first,
86  const FDateTime& second);
87  friend Boolean operator!=(const FDateTime& first,
88  const FDateTime& second);
89  friend Boolean operator<(const FDateTime& first,
90  const FDateTime& second);
91  friend Boolean operator>(const FDateTime& first,
92  const FDateTime& second);
93  friend Boolean operator<=(const FDateTime& first,
94  const FDateTime& second);
95  friend Boolean operator>=(const FDateTime& first,
96  const FDateTime& second);
97 
98  static Boolean IsLeapYear(Int year);
99  static Int DaysInMonth(Int year, Int month);
100  static Int DaysInYear(Int year);
101  static Int DayOfYear(Int year, Int month, Int day);
102  static const FDateTime Now();
103  static const FDateTime NowUTC();
104  static const FDateTime Today();
105  static Boolean IsValid(UInt year, UInt month, UInt day,
106  UInt hour, UInt minute, UInt second);
107 
108  const type_info& GetType() override;
109  FString GetName() const override;
110 
111  private:
112  time_t timestamp;
113  struct tm buffer;
114  ULong nanoseconds;
115  FDateTimeKind kind;
116 };
117 
118 #endif // FDATETIME_H
FString
Definition: FString.h:21
FTimeSpan
Definition: FTimeSpan.h:21
FDateTime
Definition: FDateTime.h:47
FObject
Definition: FObject.h:49