acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
earth_time.h
1#pragma once
2
3
4#include "earth_time_shift.h"
5#include "acme/prototype/time/_time.h"
6
7
8#if defined(__ANDROID__) || defined(__APPLE__)
9
10struct tm;
11
12#endif
13
15
16enum _CTIMESPANFORMATSTEP
17{
18 _CTFS_NONE = 0,
19 _CTFS_FORMAT = 1,
20 _CTFS_NZ = 2
21};
22#define _CTIMESPANFORMATS 3
23
24
25namespace earth
26{
27
28 class gregorian_time;
29
30 // it is in UTC by default?
31 class CLASS_DECL_ACME time :
32 public posix_time
33 {
34 public:
35
36
37 //posix_time m_posixtime;
38
39
40 constexpr time() noexcept;
41
42 inline time(now_t) noexcept : posix_time(now_t{}) { }
43
44 //constexpr time(const time &time);
45
46 constexpr time(const posix_time & time) noexcept;
47
48 time(::i32 nYear, ::i32 nMonth, ::i32 nDay, ::i32 nHour, ::i32 nMin, ::i32 nSec,
49 const class ::time &timeshift = {});
51 explicit time(const ::earth::gregorian_time & gregoriantime,
52 const class ::time & timeshift = {});
53 explicit time(const file_time & filetime,
54 const class ::time & timeshift = {});
55 explicit time(const ::system_time & systemtime,
56 const class ::time & timeshift = {});
57
58#ifdef WINDOWS
59 time(::u16 wDosDate, ::u16 wDosTime, ::i32 nDST = -1);
60#endif
61
62
63 static time now() noexcept;
64 static time now(const class ::time& timeshift) noexcept;
65 static time midnight(const class ::time& timeshift = {}) noexcept;
66
67 static time midnight(const ::earth::time & time, const class ::time& timeshift = {}) noexcept;
68
69 void Now() { *this = now(); }
70 void Null() { *this = posix_time({ posix_time_t{}, 0 }); }
71
72
73 constexpr time &operator=(const time &time) noexcept;
74
75
76 bool is_null_or_positive() const { return m_iSecond >= 0; }
77
78 bool is_positive() const { return m_iSecond > 0; }
79
80 time &operator +=(date_span span);
81
82 time &operator-=(date_span span);
83
84 constexpr time &operator +=(time_span span) noexcept;
85
86 constexpr time &operator-=(time_span span) noexcept;
87
88 //time& operator +=( const time & span ) noexcept;
89 //time& operator-=( const time & span ) noexcept;
90
91 constexpr class ::time operator % (class ::time & time) const noexcept
92 {
93
94 return ((class ::time)*this) % time;
95
96 }
97
98 constexpr time_span operator-(time time) const noexcept;
99
100 constexpr time operator-(time_span span) const noexcept;
101
102 constexpr time operator +(time_span span) const noexcept;
103
104 time operator-(date_span span) const;
105
106 time operator +(date_span span) const;
107
108 constexpr time operator +(class ::time & time) const;
109
110 //time operator-(const class time & time) const;
111 //time operator +(const class time & time) const;
112
113 constexpr bool operator==(time time) const noexcept;
114
115 //constexpr bool operator!=(time time) const noexcept;
116
117 constexpr ::std::strong_ordering operator<=>(::earth::time time) const noexcept;
118
119 //constexpr bool operator>(time time) const noexcept;
120
121 //constexpr bool operator<=(time time) const noexcept;
122
123 //constexpr bool operator>=(time time) const noexcept;
124
125 posix_time get_time() const noexcept;
126
127 ::i32 year(const class ::time &timeshift = {}) const noexcept;
128
129 ::i32 month(const class ::time &timeshift = {}) const noexcept;
130
131 ::i32 day(const class ::time &timeshift = {}) const noexcept;
132
133 ::i32 hour(const class ::time &timeshift = {}) const noexcept;
134
135 ::i32 minute(const class ::time &timeshift = {}) const noexcept;
136
137 ::i32 second(const class ::time &timeshift = {}) const noexcept;
138
139 ::i32 day_of_week(const class ::time &timeshift = {}) const noexcept; // 1 = Sunday, 7 = Saturday
140
141
142 time get_sunday(const class ::time &timeshift = {}) const;
143
144 posix_time time_of_day(const class ::time &timeshift = {}) const noexcept;
145
146 ::i64 day_sig(const class ::time &timeshift = {}) const noexcept;
147
148
149 time_span elapsed() const;
150
151 time_span abs_diff(const ::earth::time &time) const;
152
153
154 bool operator == (const class ::time & time) const; \
155 ::std::strong_ordering operator <=> (const class ::time & time) const;
156
157
158 ::i64 total_minutes(const class ::time & timeshift = {}) const noexcept;
159
160
161 };
162
163
164 constexpr bool time::operator==(time time) const noexcept
165 {
166 return m_iSecond == time.m_iSecond;
167
168 }
169
170
171 //constexpr bool time::operator!=(time time) const noexcept
172 //{
173
174 // return m_posixtime != time.m_posixtime;
175
176 //}
177
178
179 constexpr ::std::strong_ordering time::operator<=>(::earth::time time) const noexcept
180 {
181
182 return m_iSecond <=> time.m_iSecond;
183
184 }
185
186
187 //constexpr bool time::operator>(time time) const noexcept
188 //{
189
190 // return m_posixtime > time.m_posixtime;
191
192 //}
193
194
195 //constexpr bool time::operator<=(time time) const noexcept
196 //{
197
198 // return m_posixtime <= time.m_posixtime;
199
200 //}
201
202
203 //constexpr bool time::operator>=(time time) const noexcept
204 //{
205
206 // return m_posixtime >= time.m_posixtime;
207
208 //}
209
210
211} // namespace earth
212
213
214#include "earth_time_span.h"
215
216
217namespace earth
218{
219
220
221 constexpr time_span time::operator-(time time) const noexcept
222 {
223
224 return posix_time::operator - (time);
225
226 }
227
228
229 constexpr ::earth::time time::operator-(time_span span) const noexcept
230 {
231
232 return posix_time::operator - (span);
233
234 }
235
236
237 constexpr ::earth::time time::operator +(time_span span) const noexcept
238 {
239
240 return posix_time::operator + (span);
241
242 }
243
244
245 constexpr time::time() noexcept// :
246 //posixtime({ posix_time_t{}, 0 })
247 {
248
249 }
250
251
252// constexpr time::time(const class time & time) :
253// posix_time(time)
254// {
255//
256// }
257
258
259 constexpr time::time(const posix_time & time) noexcept :
260 posix_time(time)
261 {
262
263 }
264
265
266 constexpr ::earth::time & time::operator=(const class time & time) noexcept
267 {
268
269 posix_time::operator =(time);
270
271 return *this;
272
273 }
274
275
276 constexpr ::earth::time & time::operator +=(time_span span) noexcept
277 {
278
279 posix_time::operator +=(span);
280
281 return *this;
282
283 }
284
285
286 constexpr ::earth::time & time::operator-=(time_span span) noexcept
287 {
288
289 posix_time::operator -= (span);
290
291 return *this;
292
293 }
294
295
296
297
298
299 //DEFINE_COMPARISON_WITH_TIME(inline, time)
300
301} // namespace earth
302
303
304
305
306
307
Definition date_span.h:9
Definition earth_gregorian_time.h:15
Definition earth_time_span.h:20
Definition earth_time.h:33
Definition file_time.h:11
Definition aaa_time.h:13
Definition _structures.h:48
Definition posix_time.h:5
Definition release_time_for_project.h:6