Plasma Engine  2.0
Loading...
Searching...
No Matches
Timestamp.h
1#pragma once
2
3#include <Foundation/Reflection/Reflection.h>
4#include <Foundation/Time/Time.h>
5
16
22class PL_FOUNDATION_DLL plTimestamp
23{
24public:
26 {
33 };
37 static const plTimestamp CurrentTimestamp(); // [tested]
38
39 PL_DECLARE_POD_TYPE();
40
41 // *** Constructors ***
42public:
44 plTimestamp(); // [tested]
45
47 [[nodiscard]] static plTimestamp MakeInvalid() { return plTimestamp(); }
48
50 [[nodiscard]] static plTimestamp MakeFromInt(plInt64 iTimeValue, plSIUnitOfTime::Enum unitOfTime);
51
52 // *** Public Functions ***
53public:
55 bool IsValid() const; // [tested]
56
58 plInt64 GetInt64(plSIUnitOfTime::Enum unitOfTime) const; // [tested]
59
65 bool Compare(const plTimestamp& rhs, CompareMode::Enum mode) const; // [tested]
66
67 // *** Operators ***
68public:
70 void operator+=(const plTime& timeSpan); // [tested]
71
73 void operator-=(const plTime& timeSpan); // [tested]
74
76 const plTime operator-(const plTimestamp& other) const; // [tested]
77
79 const plTimestamp operator+(const plTime& timeSpan) const; // [tested]
80
82 const plTimestamp operator-(const plTime& timeSpan) const; // [tested]
83
84
85private:
86 static constexpr const plInt64 PL_INVALID_TIME_STAMP = plMath::MinValue<plInt64>();
87
88 PL_ALLOW_PRIVATE_PROPERTIES(plTimestamp);
90 plInt64 m_iTimestamp = PL_INVALID_TIME_STAMP;
91};
92
94const plTimestamp operator+(plTime& ref_timeSpan, const plTimestamp& timestamp);
95
96PL_DECLARE_REFLECTABLE_TYPE(PL_FOUNDATION_DLL, plTimestamp);
97
102class PL_FOUNDATION_DLL plDateTime
103{
104public:
108 plDateTime(); // [tested]
109 ~plDateTime();
110
112 bool IsValid() const;
113
115 [[nodiscard]] static plDateTime MakeZero() { return plDateTime(); }
116
121 [[nodiscard]] static plDateTime MakeFromTimestamp(plTimestamp timestamp);
122
128 [[nodiscard]] const plTimestamp GetTimestamp() const; // [tested]
129
135 plResult SetFromTimestamp(plTimestamp timestamp);
136
137 // *** Accessors ***
138public:
140 plUInt32 GetYear() const; // [tested]
141
143 void SetYear(plInt16 iYear); // [tested]
144
146 plUInt8 GetMonth() const; // [tested]
147
149 void SetMonth(plUInt8 uiMonth); // [tested]
150
152 plUInt8 GetDay() const; // [tested]
153
155 void SetDay(plUInt8 uiDay); // [tested]
156
158 plUInt8 GetDayOfWeek() const;
159
161 void SetDayOfWeek(plUInt8 uiDayOfWeek);
162
164 plUInt8 GetHour() const; // [tested]
165
167 void SetHour(plUInt8 uiHour); // [tested]
168
170 plUInt8 GetMinute() const; // [tested]
171
173 void SetMinute(plUInt8 uiMinute); // [tested]
174
176 plUInt8 GetSecond() const; // [tested]
177
179 void SetSecond(plUInt8 uiSecond); // [tested]
180
182 plUInt32 GetMicroseconds() const; // [tested]
183
185 void SetMicroseconds(plUInt32 uiMicroSeconds); // [tested]
186
187private:
189 plUInt32 m_uiMicroseconds = 0;
191 plInt16 m_iYear = 0;
193 plUInt8 m_uiMonth = 0;
195 plUInt8 m_uiDay = 0;
197 plUInt8 m_uiDayOfWeek = 0;
199 plUInt8 m_uiHour = 0;
201 plUInt8 m_uiMinute = 0;
203 plUInt8 m_uiSecond = 0;
204};
205
206PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plDateTime& arg);
207
209{
210 enum FormattingFlags
211 {
212 ShowDate = PL_BIT(0),
213 TextualDate = ShowDate | PL_BIT(1),
214 ShowWeekday = PL_BIT(2),
215 ShowTime = PL_BIT(3),
216 ShowSeconds = ShowTime | PL_BIT(4),
217 ShowMilliseconds = ShowSeconds | PL_BIT(5),
218 ShowTimeZone = PL_BIT(6),
219
220 Default = ShowDate | ShowSeconds,
221 DefaultTextual = TextualDate | ShowSeconds,
222 };
223
229 inline explicit plArgDateTime(const plDateTime& dateTime, plUInt32 uiFormattingFlags = Default)
230 : m_Value(dateTime)
231 , m_uiFormattingFlags(uiFormattingFlags)
232 {
233 }
234
235 plDateTime m_Value;
236 plUInt32 m_uiFormattingFlags;
237};
238
239PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plArgDateTime& arg);
240
241#include <Foundation/Time/Implementation/Timestamp_inl.h>
The plDateTime class can be used to convert plTimestamp into a human readable form.
Definition Timestamp.h:103
plDateTime()
Creates an empty date time instance with an invalid date.
static plDateTime MakeZero()
Returns a date time that is all zero.
Definition Timestamp.h:115
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
The timestamp class encapsulates a date in time as microseconds since Unix epoch.
Definition Timestamp.h:23
plTimestamp()
Creates an invalidated timestamp.
static plTimestamp MakeInvalid()
Returns an invalid timestamp.
Definition Timestamp.h:47
constexpr TYPE MinValue()
Returns the smallest possible value (that is not -infinity). Usually zero or -MaxValue()....
Definition Timestamp.h:209
plArgDateTime(const plDateTime &dateTime, plUInt32 uiFormattingFlags=Default)
Initialized a formatting object for an plDateTime instance.
Definition Timestamp.h:229
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition Timestamp.h:7
Enum
Definition Timestamp.h:9
@ Second
SI-unit of time (base unit)
Definition Timestamp.h:13
@ Microsecond
SI-unit of time (10^-6 second)
Definition Timestamp.h:11
@ Nanosecond
SI-unit of time (10^-9 second)
Definition Timestamp.h:10
@ Millisecond
SI-unit of time (10^-3 second)
Definition Timestamp.h:12
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
Definition Timestamp.h:26
Enum
Definition Timestamp.h:28
@ FileTimeEqual
Uses a resolution that guarantees that a file's timestamp is considered equal on all platforms.
Definition Timestamp.h:29
@ Newer
Just compares values and returns true if the left-hand side is larger than the right hand side.
Definition Timestamp.h:31
@ Identical
Uses maximal stored resolution.
Definition Timestamp.h:30