acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
time.h
1// Refactoring by camilo on 2021-10-05 12:46 BRT <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include "acme/prototype/mathematics/numeric.h"
6#include "acme/prototype/time/_structures.h"
7#include "posix_time.h"
8#include "nanosecond.h"
9#include "acme/platform/uint64_utilities.h"
10
11
12namespace earth
13{
14
15
16 class gregorian_time;
17
18
19} // namespace earth
20
21
22#define _TIME_COMPARISON_WITH(TYPE) \
23 inline bool operator == (const TYPE & t) const { return operator == ((class ::time) t); } \
24 inline ::std::strong_ordering operator <=> (const TYPE & t) const { return operator <=> ((class ::time) t); }
25
26
27class CLASS_DECL_ACME time :
28 public posix_time,
29 public nanosecond
30{
31public:
32
33 //nanosecond m_nanosecond;
34
35
36 enum enum_unit
37 {
38
39 unit_nanos,
40 unit_micros,
41 unit_millis,
42 unit_seconds,
43 unit_minutes,
44 unit_hours,
45 unit_days
46
47 };
48
49
50 static time s_timeFirst;
51
52 constexpr time() { }
53
54 constexpr time(zero_t) : posix_time(zero_t{}) { }
55
56 time(now_t) : posix_time(no_initialize_t{}), nanosecond(no_initialize_t{}) { Now(); }
57
58 constexpr time(infinite_t) { Infinite(); }
59
60 constexpr time(const class ::time& time) : posix_time(time),nanosecond(time) { }
61
62 explicit time(const ::earth::gregorian_time & time);
63
64 explicit time(const ::file_time & filetime);
65
66 template < prototype_integer INTEGER >
67 constexpr time(INTEGER iSecond)
68 : posix_time( {posix_time_t{}, (::i64)iSecond}), nanosecond({nanosecond_t{}, 0})
69 {
70
71
72 }
73
74 template < prototype_floating FLOATING >
75 time(FLOATING fSeconds)
76 {
77
78 fset(fSeconds);
79
80 }
81
82 template < prototype_integer INTEGER1, prototype_integral INTEGRAL2 >
83 constexpr time(INTEGER1 iSecond, INTEGRAL2 iNanosecond) :
84 posix_time( {posix_time_t{}, (::i64)iSecond}), nanosecond({nanosecond_t{}, (::i64)iNanosecond})
85 { }
86
87
88 template < prototype_floating FLOATING, prototype_number NUMBER >
89 time(FLOATING fSeconds, NUMBER nanoseconds)
90 {
91
92 fset(fSeconds, nanoseconds);
93
94 }
95
96 template < prototype_integral INTEGRAL1, prototype_integral INTEGRAL2 >
97 constexpr time(enum_raw, INTEGRAL1 iSecond, INTEGRAL2 iNanosecond)
98 {
99 m_iSecond = iSecond;
100
101 m_iNanosecond = iNanosecond;
102 }
103
104 template < prototype_integral INTEGRAL1 >
105 constexpr time(enum_raw, INTEGRAL1 iSecond) : time(e_raw, iSecond, 0) {}
106
107 template < prototype_integral INTEGRAL1, prototype_integral INTEGRAL2 >
108 constexpr time(enum_normalize, INTEGRAL1 iSecond, INTEGRAL2 iNanosecond)
109 {
110
111 m_iSecond = iSecond + iNanosecond / 1'000'000'000;
112
113 m_iNanosecond = iNanosecond % 1'000'000'000;
114
115 while(m_iNanosecond < 0)
116 {
117
118 m_iSecond--;
119
120 m_iNanosecond += 1'000'000'000;
121
122 }
123
124 }
125
126
127 constexpr time(const ::posix_time & posixtime) : posix_time(posixtime), nanosecond({ nanosecond_t{}, 0 }) {}
128
129
130 constexpr void raw_set(posix_time posixtime, nanosecond nanosecond = { nanosecond_t{}, 0 });
131 constexpr void set(posix_time posixtime, nanosecond nanosecond);
132 constexpr void set_null();
133 static constexpr time raw_create(posix_time posixtime, nanosecond nanosecond);
134 static constexpr time create(posix_time posixtime, nanosecond nanosecond);
135 static constexpr time create_null();
136
137
138 void fset(::f128 dSeconds);
139 void fset(::f128 dSeconds, ::f64 dNanoseconds);
140 static time fcreate(::f128 dSeconds, ::f64 dNanoseconds);
141
142
143 constexpr void set(::i64 i, enum_unit eunit);
144 void set(::f128 d, enum_unit eunit);
145
146
147 //inline bool is_infinity() const;
148 constexpr bool is_infinite() const;
149 constexpr bool is_null() const;
150 constexpr bool is_set() const {return ! is_null();}
151 //constexpr bool is_zero() const;
152 //constexpr bool is_set() const { return (m_iSecond >= 0 && m_iNanosecond > 0) || (m_iSecond > 0 && m_iNanosecond >= 0); }
153 constexpr static class ::time infinity();
154 //inline static time pos_infinity();
155 //constexpr static time zero();
156// constexpr bool operator !() const {return is_null();}
157
158 static class ::time local_offset();
159
160 //constexpr void infinite() {*this=infinity();}
161 //void PosInfinity() {*this=pos_infinity();}
162 //constexpr void zero() { this->m_iSecond = 0; this->m_iNanosecond = 0; }
163 //constexpr void Null() { Zero(); }
164
165 constexpr class ::time & operator = (const class time & time);
166 constexpr class ::time & operator = (const ::earth::time_span & time);
167
168 inline bool timeout(const class time & time) { return timeout(time, now()); }
169 constexpr bool timeout(const class time & time, const class time & timeNow);
170 constexpr void normalize();
171
172 //constexpr operator bool() const;
173
174 constexpr ::i64 total_nanoseconds() const { return m_iSecond * 1'000'000'000 + m_iNanosecond; }
175 //constexpr ::f64 operator() ()const { return floating_second(); }
176
177
178 //static inline class ::time first();
179 [[nodiscard]] static inline class ::time now() { return now_t{}; }
180
181 inline bool is_past() const { return now() > *this; }
182
183 class ::time & Now();
184
185 constexpr inline class ::time & Infinite()
186 {
187
188 return *this = infinity();
189
190 }
191
192
193 inline class time elapsed() const { return elapsed(now()); }
194 constexpr class time elapsed(const class time & time ) const { return time - *this; }
195 inline bool is_time_out_ok_with_update(const class time& timeOut)
196 {
197
198 auto timeNow = now();
199
200 auto timeElapsed = this->elapsed(timeNow);
201
202 if (timeElapsed < timeOut)
203 {
204
205 return true;
206
207 }
208
209 *this = timeNow;
210
211 return false;
212
213 }
214
215 inline bool has_timed_out_with_update(const class time & timeOut)
216 {
217
218 return !is_time_out_ok_with_update(timeOut);
219
220 }
221
222 inline time update_elapsed() { return update_elapsed(now()); }
223
224 constexpr time update_elapsed(const class time & timeStop)
225 {
226
227 auto elapsed = timeStop - *this;
228
229 operator=(timeStop);
230
231 return elapsed;
232
233 }
234
235 inline ::f64 period_rate(const class time & timePeriod) const { return period_rate(timePeriod, now()); }
236
237 constexpr ::f64 period_rate(const class time & timePeriod, const class time & time) const { return ((time - *this) % timePeriod) / timePeriod; }
238
239 inline ::f64 ramp_up(const class time & timePeriod) const { return ramp_up(timePeriod, now()); }
240
241 constexpr ::f64 ramp_up(const class time & timePeriod, const class time & time) const;
242
243 //inline class ::time operator - (const class time & time) const { return { e_normalize, m_iSecond - time.m_iSecond, m_iNanosecond - time.m_iNanosecond }; }
244 //inline class ::time operator + (const class time & time) const { return { e_normalize, m_iSecond + time.m_iSecond, m_iNanosecond + time.m_iNanosecond }; }
245 constexpr class ::time & operator -= (const class time & time) { m_iSecond -= time.m_iSecond; m_iNanosecond -= time.m_iNanosecond; normalize(); return *this; }
246 constexpr class ::time & operator += (const class time & time) { m_iSecond += time.m_iSecond; m_iNanosecond += time.m_iNanosecond; normalize(); return *this; }
247
248
249 template < prototype_floating FLOATING >
250 constexpr class ::time operator / (FLOATING d) const
251 {
252
253 auto nanosecond = (m_iSecond * 1'000'000'000.0 + m_iNanosecond) / d;
254
255 return { e_raw, (::i64)(nanosecond / 1'000'000'000.0), (long)fmod(nanosecond, 1'000'000'000.0) };
256
257 }
258
259
260 template < prototype_floating FLOATING >
261 constexpr class ::time operator * (FLOATING d) const
262 {
263
264 auto nanosecond = (m_iSecond * 1'000'000'000.0 + m_iNanosecond) * d;
265
266 return { e_raw, (::i64)(nanosecond / 1'000'000'000.0), (long)fmod(nanosecond, 1'000'000'000.0) };
267
268 }
269
270
271 template < prototype_integral INTEGRAL >
272 constexpr class ::time operator / (INTEGRAL i) const
273 {
274
275 auto nanosecond = (m_iSecond * 1'000'000'000 + m_iNanosecond) / i;
276
277 return { e_raw, (::i64)(nanosecond / 1'000'000'000), (long)(nanosecond % 1'000'000'000) };
278
279 }
280
281
282 template < prototype_integral INTEGRAL >
283 constexpr class ::time operator * (INTEGRAL i) const
284 {
285
286 auto nanosecond = (m_iSecond * 1'000'000'000 + m_iNanosecond) * i;
287
288 return { e_raw, (::i64)(nanosecond / 1'000'000'000), (long)(nanosecond % 1'000'000'000) };
289
290 }
291
292
293 template < prototype_floating FLOATING >
294 constexpr class ::time & operator /= (FLOATING d)
295 {
296
297 return operator=(*this / d);
298
299 }
300
301
302 template < prototype_floating FLOATING >
303 constexpr class ::time & operator *= (FLOATING d)
304 {
305
306 return operator= (*this / d);
307
308 }
309
310
311 template < prototype_integral INTEGRAL >
312 constexpr class ::time & operator /= (INTEGRAL i)
313 {
314
315 return operator= (*this / i);
316
317 }
318
319
320 template < prototype_integral INTEGRAL >
321 constexpr class ::time & operator *= (INTEGRAL i)
322 {
323
324 return operator= (*this * i);
325
326 }
327
328
329 constexpr class ::time half() const;
330
331
332 constexpr class ::time & operator %= (const class time & time);
333 //class ::time operator % (const class time & time) const;
334
335
336 constexpr posix_time GetTimeSpan() const;
337
338
339 //inline bool timeout(const class time & time);
340
341 inline time remaining(const class time & time, const class time & timeNow = now_t{});
342
343
344 constexpr class ::time wait() const;
345
346 bool on_off(const class time & period) const
347 {
348
349 return on_off(period, now());
350
351 }
352
353
354 constexpr bool on_off(const class time & period, const class time & now) const
355 {
356
357 return (elapsed(now) % period) < (period / 2);
358
359 }
360
361
362 // operator integral_day () const { return integral_day(); }
363 // operator integral_hour () const { return integral_hour(); }
364 // operator integral_minute () const { return integral_minute(); }
365 // operator integral_second () const { return integral_second(); }
366 // operator integral_millisecond () const { return integral_millisecond(); }
367 // operator integral_microsecond () const { return integral_microsecond(); }
368 // operator integral_nanosecond () const { return integral_nanosecond(); }
369
370 // operator floating_day () const { return floating_day(); }
371 // operator floating_hour () const { return floating_hour(); }
372 // operator floating_minute () const { return floating_minute(); }
373 // operator floating_second () const { return floating_second(); }
374 // operator floating_millisecond () const { return floating_millisecond(); }
375 // operator floating_microsecond () const { return floating_microsecond(); }
376 // operator floating_nanosecond () const { return floating_nanosecond(); }
377
378
379
380
381
382
383 constexpr ::i64 integral_day() const { return m_iSecond / 86'400; }
384 constexpr ::i64 integral_hour() const { return m_iSecond / 3'600; }
385 constexpr ::i64 integral_minute() const { return m_iSecond / 60; }
386 constexpr ::i64 integral_second() const { return m_iSecond; }
387 constexpr ::i64 integral_millisecond() const { return m_iSecond * 1'000 + m_iNanosecond / 1'000'000; }
388 constexpr ::i64 integral_microsecond() const { return m_iSecond * 1'000'000 + m_iNanosecond / 1'000; }
389 constexpr ::i64 integral_nanosecond() const { return m_iSecond * 1'000'000'000 + m_iNanosecond; }
390
391
392 constexpr ::f64 floating_day() const { return floating_second() / 86'400.0; }
393 constexpr ::f64 floating_hour() const { return floating_second() / 3'600.0; }
394 constexpr ::f64 floating_minute() const { return floating_second() / 60.0; }
395 constexpr ::f64 floating_second() const { return ((::f64)m_iSecond) + ((::f64) m_iNanosecond / 1'000'000'000.0); }
396 constexpr ::f64 floating_millisecond() const { return ((::f64)m_iSecond * 1'000.0) + ((::f64)m_iNanosecond / 1'000'000.0);}
397 constexpr ::f64 floating_microsecond() const { return ((::f64)m_iSecond * 1'000'000.0) + ((::f64)m_iNanosecond / 1'000.0); }
398 constexpr ::f64 floating_nanosecond() const { return (::f64)integral_nanosecond(); }
399
400
401 ::i32 millisecond() const { return (::i32) (m_iNanosecond / 1'000'000); }
402
403
404 constexpr bool operator == (const class time & time) const { return m_iSecond == time.m_iSecond && m_iNanosecond == time.m_iNanosecond; }
405 //inline bool operator != (const class time & time) const { return !operator ==(time); }
406 constexpr ::std::strong_ordering operator <=> (const class time & time) const
407 {
408
409 auto order = m_iSecond <=> time.m_iSecond;
410
411 return order != 0 ? order : m_iNanosecond <=> time.m_iNanosecond;
412
413 }
414
415 //inline bool operator <= (const class time & time) const { return m_iSecond < time.m_iSecond || (m_iSecond == time.m_iSecond && m_iNanosecond <= time.m_iNanosecond); }
416 //inline bool operator > (const class time & time) const { return !operator <=(time); }
417 //inline bool operator >= (const class time & time) const { return !operator <=(time); }
418 ::pair < ::collection::count, time > count_and_remainder(const class time & time) const
419 {
420
421 auto d = *this / time;
422
423 auto count = (::collection::count)::floor(d);
424
425 auto remainder = *this % time;
426
427 return { count, remainder };
428
429 }
430
431 constexpr time operator %(const class time & time) const;
432 constexpr ::f64 operator /(const class time & time) const;
433 constexpr time operator +(const class time & time) const { return { e_normalize, this->m_iSecond + time.m_iSecond, this->m_iNanosecond + time.m_iNanosecond }; }
434 constexpr time operator -(const class time & time) const { return { e_normalize, this->m_iSecond - time.m_iSecond, this->m_iNanosecond - time.m_iNanosecond }; }
435
436
437 constexpr time operator -() const { return { e_raw, -m_iSecond, -m_iNanosecond}; }
438
439
440
441
442
443 //_TIME_COMPARISON_WITH(::integral_nanosecond);
444 //_TIME_COMPARISON_WITH(::integral_microsecond);
445 //_TIME_COMPARISON_WITH(::integral_millisecond);
446 //_TIME_COMPARISON_WITH(::integral_second);
447 //_TIME_COMPARISON_WITH(::integral_minute);
448 //_TIME_COMPARISON_WITH(::integral_hour);
449 //_TIME_COMPARISON_WITH(::integral_day);
450
458
459
460 //_TIME_COMPARISON_WITH(::floating_nanosecond);
461 //_TIME_COMPARISON_WITH(::floating_microsecond);
462 //_TIME_COMPARISON_WITH(::floating_millisecond);
463 //_TIME_COMPARISON_WITH(::floating_second);
464 //_TIME_COMPARISON_WITH(::floating_minute);
465 //_TIME_COMPARISON_WITH(::floating_hour);
466 //_TIME_COMPARISON_WITH(::floating_day);
467
475
476
477 //inline bool operator == (const ::integral_nanosecond & integralnanosecond) const { return operator == (class ::time(integralnanosecond)); }
478 //inline bool operator != (const ::integral_nanosecond & integralnanosecond) const { return operator != (class ::time(integralnanosecond)); }
479 //inline bool operator < (const ::integral_nanosecond & integralnanosecond) const { return operator < (class ::time(integralnanosecond)); }
480 //inline bool operator <= (const ::integral_nanosecond & integralnanosecond) const { return operator <= (class ::time(integralnanosecond)); }
481 //inline bool operator > (const ::integral_nanosecond & integralnanosecond) const { return operator > (class ::time(integralnanosecond)); }
482 //inline bool operator >= (const ::integral_nanosecond & integralnanosecond) const { return operator >= (class ::time(integralnanosecond)); }
483
484 //inline bool operator == (const ::integral_microsecond & integralmicrosecond) const { return operator == (class ::time(integralmicrosecond)); }
485 //inline bool operator != (const ::integral_microsecond & integralmicrosecond) const { return operator != (class ::time(integralmicrosecond)); }
486 //inline bool operator < (const ::integral_microsecond & integralmicrosecond) const { return operator < (class ::time(integralmicrosecond)); }
487 //inline bool operator <= (const ::integral_microsecond & integralmicrosecond) const { return operator <= (class ::time(integralmicrosecond)); }
488 //inline bool operator > (const ::integral_microsecond & integralmicrosecond) const { return operator > (class ::time(integralmicrosecond)); }
489 //inline bool operator >= (const ::integral_microsecond & integralmicrosecond) const { return operator >= (class ::time(integralmicrosecond)); }
490
491 //inline bool operator == (const ::integral_millisecond & integralmillisecond) const { return operator == (class ::time(integralmillisecond)); }
492 //inline bool operator != (const ::integral_millisecond & integralmillisecond) const { return operator != (class ::time(integralmillisecond)); }
493 //inline bool operator < (const ::integral_millisecond & integralmillisecond) const { return operator < (class ::time(integralmillisecond)); }
494 //inline bool operator <= (const ::integral_millisecond & integralmillisecond) const { return operator <= (class ::time(integralmillisecond)); }
495 //inline bool operator > (const ::integral_millisecond & integralmillisecond) const { return operator > (class ::time(integralmillisecond)); }
496 //inline bool operator >= (const ::integral_millisecond & integralmillisecond) const { return operator >= (class ::time(integralmillisecond)); }
497
498 //inline bool operator == (const ::integral_second & integralsecond) const { return operator == (class ::time(integralsecond)); }
499 //inline bool operator != (const ::integral_second & integralsecond) const { return operator != (class ::time(integralsecond)); }
500 //inline bool operator < (const ::integral_second & integralsecond) const { return operator < (class ::time(integralsecond)); }
501 //inline bool operator <= (const ::integral_second & integralsecond) const { return operator <= (class ::time(integralsecond)); }
502 //inline bool operator > (const ::integral_second & integralsecond) const { return operator > (class ::time(integralsecond)); }
503 //inline bool operator >= (const ::integral_second & integralsecond) const { return operator >= (class ::time(integralsecond)); }
504
505 //inline bool operator == (const ::integral_minute & minute) const { return operator == (class ::time(minute)); }
506 //inline bool operator != (const ::integral_minute & minute) const { return operator != (class ::time(minute)); }
507 //inline bool operator < (const ::integral_minute & minute) const { return operator < (class ::time(minute)); }
508 //inline bool operator <= (const ::integral_minute & minute) const { return operator <= (class ::time(minute)); }
509 //inline bool operator > (const ::integral_minute & minute) const { return operator > (class ::time(minute)); }
510 //inline bool operator >= (const ::integral_minute & minute) const { return operator >= (class ::time(minute)); }
511
512 //inline bool operator == (const ::integral_hour & day) const { return operator == (class ::time(day)); }
513 //inline bool operator != (const ::integral_hour & day) const { return operator != (class ::time(day)); }
514 //inline bool operator < (const ::integral_hour & day) const { return operator < (class ::time(day)); }
515 //inline bool operator <= (const ::integral_hour & day) const { return operator <= (class ::time(day)); }
516 //inline bool operator > (const ::integral_hour & day) const { return operator > (class ::time(day)); }
517 //inline bool operator >= (const ::integral_hour & day) const { return operator >= (class ::time(day)); }
518
519 //inline bool operator == (const ::integral_day & day) const { return operator == (class ::time(day)); }
520 //inline bool operator != (const ::integral_day & day) const { return operator != (class ::time(day)); }
521 //inline bool operator < (const ::integral_day & day) const { return operator < (class ::time(day)); }
522 //inline bool operator <= (const ::integral_day & day) const { return operator <= (class ::time(day)); }
523 //inline bool operator > (const ::integral_day & day) const { return operator > (class ::time(day)); }
524 //inline bool operator >= (const ::integral_day & day) const { return operator >= (class ::time(day)); }
525
526
527
528
529
530
531
532
533 //inline bool operator == (const ::floating_nanosecond & floatingnanosecond) const { return operator == (class ::time(floatingnanosecond)); }
534 //inline bool operator != (const ::floating_nanosecond & floatingnanosecond) const { return operator != (class ::time(floatingnanosecond)); }
535 //inline bool operator < (const ::floating_nanosecond & floatingnanosecond) const { return operator < (class ::time(floatingnanosecond)); }
536 //inline bool operator <= (const ::floating_nanosecond & floatingnanosecond) const { return operator <= (class ::time(floatingnanosecond)); }
537 //inline bool operator > (const ::floating_nanosecond & floatingnanosecond) const { return operator > (class ::time(floatingnanosecond)); }
538 //inline bool operator >= (const ::floating_nanosecond & floatingnanosecond) const { return operator >= (class ::time(floatingnanosecond)); }
539
540 //inline bool operator == (const ::floating_microsecond & floatingmicrosecond) const { return operator == (class ::time(floatingmicrosecond)); }
541 //inline bool operator != (const ::floating_microsecond & floatingmicrosecond) const { return operator != (class ::time(floatingmicrosecond)); }
542 //inline bool operator < (const ::floating_microsecond & floatingmicrosecond) const { return operator < (class ::time(floatingmicrosecond)); }
543 //inline bool operator <= (const ::floating_microsecond & floatingmicrosecond) const { return operator <= (class ::time(floatingmicrosecond)); }
544 //inline bool operator > (const ::floating_microsecond & floatingmicrosecond) const { return operator > (class ::time(floatingmicrosecond)); }
545 //inline bool operator >= (const ::floating_microsecond & floatingmicrosecond) const { return operator >= (class ::time(floatingmicrosecond)); }
546
547 //inline bool operator == (const ::floating_millisecond & floatingmillisecond) const { return operator == (class ::time(floatingmillisecond)); }
548 //inline bool operator != (const ::floating_millisecond & floatingmillisecond) const { return operator != (class ::time(floatingmillisecond)); }
549 //inline bool operator < (const ::floating_millisecond & floatingmillisecond) const { return operator < (class ::time(floatingmillisecond)); }
550 //inline bool operator <= (const ::floating_millisecond & floatingmillisecond) const { return operator <= (class ::time(floatingmillisecond)); }
551 //inline bool operator > (const ::floating_millisecond & floatingmillisecond) const { return operator > (class ::time(floatingmillisecond)); }
552 //inline bool operator >= (const ::floating_millisecond & floatingmillisecond) const { return operator >= (class ::time(floatingmillisecond)); }
553
554 //inline bool operator == (const ::floating_second & floatingsecond) const { return operator == (class ::time(floatingsecond)); }
555 //inline bool operator != (const ::floating_second & floatingsecond) const { return operator != (class ::time(floatingsecond)); }
556 //inline bool operator < (const ::floating_second & floatingsecond) const { return operator < (class ::time(floatingsecond)); }
557 //inline bool operator <= (const ::floating_second & floatingsecond) const { return operator <= (class ::time(floatingsecond)); }
558 //inline bool operator > (const ::floating_second & floatingsecond) const { return operator > (class ::time(floatingsecond)); }
559 //inline bool operator >= (const ::floating_second & floatingsecond) const { return operator >= (class ::time(floatingsecond)); }
560
561 //inline bool operator == (const ::floating_minute & minute) const { return operator == (class ::time(minute)); }
562 //inline bool operator != (const ::floating_minute & minute) const { return operator != (class ::time(minute)); }
563 //inline bool operator < (const ::floating_minute & minute) const { return operator < (class ::time(minute)); }
564 //inline bool operator <= (const ::floating_minute & minute) const { return operator <= (class ::time(minute)); }
565 //inline bool operator > (const ::floating_minute & minute) const { return operator > (class ::time(minute)); }
566 //inline bool operator >= (const ::floating_minute & minute) const { return operator >= (class ::time(minute)); }
567
568 //inline bool operator == (const ::floating_hour & day) const { return operator == (class ::time(day)); }
569 //inline bool operator != (const ::floating_hour & day) const { return operator != (class ::time(day)); }
570 //inline bool operator < (const ::floating_hour & day) const { return operator < (class ::time(day)); }
571 //inline bool operator <= (const ::floating_hour & day) const { return operator <= (class ::time(day)); }
572 //inline bool operator > (const ::floating_hour & day) const { return operator > (class ::time(day)); }
573 //inline bool operator >= (const ::floating_hour & day) const { return operator >= (class ::time(day)); }
574
575 //inline bool operator == (const ::floating_day & day) const { return operator == (class ::time(day)); }
576 //inline bool operator != (const ::floating_day & day) const { return operator != (class ::time(day)); }
577 //inline bool operator < (const ::floating_day & day) const { return operator < (class ::time(day)); }
578 //inline bool operator <= (const ::floating_day & day) const { return operator <= (class ::time(day)); }
579 //inline bool operator > (const ::floating_day & day) const { return operator > (class ::time(day)); }
580 //inline bool operator >= (const ::floating_day & day) const { return operator >= (class ::time(day)); }
581
582
583 //inline bool operator == (const class time & time) const { return operator == (class ::time(floating_second(time.m_f64))); }
584 //inline bool operator != (const class time & time) const { return operator != (class ::time(floating_second(time.m_f64))); }
585 //inline bool operator < (const class time & time) const { return operator < (class ::time(floating_second(time.m_f64))); }
586 //inline bool operator <= (const class time & time) const { return operator <= (class ::time(floating_second(time.m_f64))); }
587 //inline bool operator > (const class time & time) const { return operator > (class ::time(floating_second(time.m_f64))); }
588 //inline bool operator >= (const class time & time) const { return operator >= (class ::time(floating_second(time.m_f64))); }
589
590
591
592
593
594
595 //time operator %(const ::integral_nanosecond & time) const { return operator % ((class ::time)time);}
596 //::f64 operator /(const ::integral_nanosecond & time) const { return operator / ((class ::time)time);}
597 //time operator +(const ::integral_nanosecond & time) const { return operator + ((class ::time)time); }
598 //time operator -(const ::integral_nanosecond & time) const { return operator - ((class ::time)time); }
599
600
601 //time operator %(const ::integral_microsecond & time) const { return operator % ((class ::time)time); }
602 //::f64 operator /(const ::integral_microsecond& time) const { return operator / ((class ::time)time); }
603 //time operator +(const ::integral_microsecond& time) const { return operator + ((class ::time)time); }
604 //time operator -(const ::integral_microsecond& time) const { return operator - ((class ::time)time); }
605
606
607 //time operator %(const ::integral_millisecond & time) const { return operator % ((class ::time)time); }
608 //::f64 operator /(const ::integral_millisecond& time) const { return operator / ((class ::time)time); }
609 //time operator +(const ::integral_millisecond& time) const { return operator + ((class ::time)time); }
610 //time operator -(const ::integral_millisecond& time) const { return operator - ((class ::time)time); }
611
612
613 //time operator %(const ::integral_second & time) const { return operator % ((class ::time)time); }
614 //::f64 operator /(const ::integral_second& time) const { return operator / ((class ::time)time); }
615 //time operator +(const ::integral_second& time) const { return operator + ((class ::time)time); }
616 //time operator -(const ::integral_second& time) const { return operator - ((class ::time)time); }
617
618
619 //time operator %(const ::integral_minute & time) const { return operator % ((class ::time)time); }
620 //::f64 operator /(const ::integral_minute& time) const { return operator / ((class ::time)time); }
621 //time operator +(const ::integral_minute& time) const { return operator + ((class ::time)time); }
622 //time operator -(const ::integral_minute& time) const { return operator - ((class ::time)time); }
623
624
625 //time operator %(const ::integral_hour & time) const { return operator % ((class ::time)time); }
626 //::f64 operator /(const ::integral_hour& time) const { return operator / ((class ::time)time); }
627 //time operator +(const ::integral_hour& time) const { return operator + ((class ::time)time); }
628 //time operator -(const ::integral_hour& time) const { return operator - ((class ::time)time); }
629
630
631 //time operator %(const ::integral_day & time) const { return operator % ((class ::time)time); }
632 //::f64 operator /(const ::integral_day& time) const { return operator / ((class ::time)time); }
633 //time operator +(const ::integral_day& time) const { return operator + ((class ::time)time); }
634 //time operator -(const ::integral_day& time) const { return operator - ((class ::time)time); }
635
636
637
638
639
640
641
642
643
644 //time operator %(const ::floating_nanosecond & time) const { return operator % ((class ::time)time); }
645 //::f64 operator /(const ::floating_nanosecond& time) const { return operator / ((class ::time)time); }
646 //time operator +(const ::floating_nanosecond& time) const { return operator + ((class ::time)time); }
647 //time operator -(const ::floating_nanosecond& time) const { return operator - ((class ::time)time); }
648
649
650 //time operator %(const ::floating_microsecond & time) const { return operator % ((class ::time)time); }
651 //::f64 operator /(const ::floating_microsecond& time) const { return operator / ((class ::time)time); }
652 //time operator +(const ::floating_microsecond& time) const { return operator + ((class ::time)time); }
653 //time operator -(const ::floating_microsecond& time) const { return operator - ((class ::time)time); }
654
655
656 //time operator %(const ::floating_millisecond & time) const { return operator % ((class ::time)time); }
657 //::f64 operator /(const ::floating_millisecond& time) const { return operator / ((class ::time)time); }
658 //time operator +(const ::floating_millisecond& time) const { return operator + ((class ::time)time); }
659 //time operator -(const ::floating_millisecond& time) const { return operator - ((class ::time)time); }
660
661
662 //time operator %(const ::floating_second & time) const { return operator % ((class ::time)time); }
663 //::f64 operator /(const ::floating_second& time) const { return operator / ((class ::time)time); }
664 //time operator +(const ::floating_second& time) const { return operator + ((class ::time)time); }
665 //time operator -(const ::floating_second& time) const { return operator - ((class ::time)time); }
666
667
668 //time operator %(const ::floating_minute & time) const { return operator % ((class ::time)time); }
669 //::f64 operator /(const ::floating_minute& time) const { return operator / ((class ::time)time); }
670 //time operator +(const ::floating_minute& time) const { return operator + ((class ::time)time); }
671 //time operator -(const ::floating_minute& time) const { return operator - ((class ::time)time); }
672
673
674 //time operator %(const ::floating_hour & time) const { return operator % ((class ::time)time); }
675 //::f64 operator /(const ::floating_hour& time) const { return operator / ((class ::time)time); }
676 //time operator +(const ::floating_hour& time) const { return operator + ((class ::time)time); }
677 //time operator -(const ::floating_hour& time) const { return operator - ((class ::time)time); }
678
679
680 //time operator %(const ::floating_day & time) const { return operator % ((class ::time)time); }
681 //::f64 operator /(const ::floating_day& time) const { return operator / ((class ::time)time); }
682 //time operator +(const ::floating_day& time) const { return operator + ((class ::time)time); }
683 //time operator -(const ::floating_day& time) const { return operator - ((class ::time)time); }
684
685
686
687
688
689
690
691
692 //time operator %(const class time & time) const { return *this % class ::time(time);}
693 //::f64 operator /(const class time & time) const { return *this / class ::time(time);}
694 //time operator +(const class time & time) const { return *this + class ::time(time); }
695 //time operator -(const class time & time) const { return *this - class ::time(time); }
696
697
698
699
700
701
702
703 //inline bool operator == (const ::integral_nanosecond& integralnanosecond) const { return operator == (class ::time(integralnanosecond)); }
704 //inline bool operator != (const ::integral_nanosecond& integralnanosecond) const { return operator != (class ::time(integralnanosecond)); }
705 //inline bool operator < (const ::integral_nanosecond& integralnanosecond) const { return operator < (class ::time(integralnanosecond)); }
706 //inline bool operator <= (const ::integral_nanosecond& integralnanosecond) const { return operator <= (class ::time(integralnanosecond)); }
707 //inline bool operator > (const ::integral_nanosecond& integralnanosecond) const { return operator > (class ::time(integralnanosecond)); }
708 //inline bool operator >= (const ::integral_nanosecond& integralnanosecond) const { return operator >= (class ::time(integralnanosecond)); }
709
710 //inline bool operator == (const ::integral_microsecond& integralmicrosecond) const { return operator == (class ::time(integralmicrosecond)); }
711 //inline bool operator != (const ::integral_microsecond& integralmicrosecond) const { return operator != (class ::time(integralmicrosecond)); }
712 //inline bool operator < (const ::integral_microsecond& integralmicrosecond) const { return operator < (class ::time(integralmicrosecond)); }
713 //inline bool operator <= (const ::integral_microsecond& integralmicrosecond) const { return operator <= (class ::time(integralmicrosecond)); }
714 //inline bool operator > (const ::integral_microsecond& integralmicrosecond) const { return operator > (class ::time(integralmicrosecond)); }
715 //inline bool operator >= (const ::integral_microsecond& integralmicrosecond) const { return operator >= (class ::time(integralmicrosecond)); }
716
717 //inline bool operator == (const ::integral_millisecond& integralmillisecond) const { return operator == (class ::time(integralmillisecond)); }
718 //inline bool operator != (const ::integral_millisecond& integralmillisecond) const { return operator != (class ::time(integralmillisecond)); }
719 //inline bool operator < (const ::integral_millisecond& integralmillisecond) const { return operator < (class ::time(integralmillisecond)); }
720 //inline bool operator <= (const ::integral_millisecond& integralmillisecond) const { return operator <= (class ::time(integralmillisecond)); }
721 //inline bool operator > (const ::integral_millisecond& integralmillisecond) const { return operator > (class ::time(integralmillisecond)); }
722 //inline bool operator >= (const ::integral_millisecond& integralmillisecond) const { return operator >= (class ::time(integralmillisecond)); }
723
724 //inline bool operator == (const ::integral_second& integralsecond) const { return operator == (class ::time(integralsecond)); }
725 //inline bool operator != (const ::integral_second& integralsecond) const { return operator != (class ::time(integralsecond)); }
726 //inline bool operator < (const ::integral_second& integralsecond) const { return operator < (class ::time(integralsecond)); }
727 //inline bool operator <= (const ::integral_second& integralsecond) const { return operator <= (class ::time(integralsecond)); }
728 //inline bool operator > (const ::integral_second& integralsecond) const { return operator > (class ::time(integralsecond)); }
729 //inline bool operator >= (const ::integral_second& integralsecond) const { return operator >= (class ::time(integralsecond)); }
730
731 //inline bool operator == (const ::integral_minute& minute) const { return operator == (class ::time(minute)); }
732 //inline bool operator != (const ::integral_minute& minute) const { return operator != (class ::time(minute)); }
733 //inline bool operator < (const ::integral_minute& minute) const { return operator < (class ::time(minute)); }
734 //inline bool operator <= (const ::integral_minute& minute) const { return operator <= (class ::time(minute)); }
735 //inline bool operator > (const ::integral_minute& minute) const { return operator > (class ::time(minute)); }
736 //inline bool operator >= (const ::integral_minute& minute) const { return operator >= (class ::time(minute)); }
737
738 //inline bool operator == (const ::integral_hour& day) const { return operator == (class ::time(day)); }
739 //inline bool operator != (const ::integral_hour& day) const { return operator != (class ::time(day)); }
740 //inline bool operator < (const ::integral_hour& day) const { return operator < (class ::time(day)); }
741 //inline bool operator <= (const ::integral_hour& day) const { return operator <= (class ::time(day)); }
742 //inline bool operator > (const ::integral_hour& day) const { return operator > (class ::time(day)); }
743 //inline bool operator >= (const ::integral_hour& day) const { return operator >= (class ::time(day)); }
744
745 //inline bool operator == (const ::integral_day& day) const { return operator == (class ::time(day)); }
746 //inline bool operator != (const ::integral_day& day) const { return operator != (class ::time(day)); }
747 //inline bool operator < (const ::integral_day& day) const { return operator < (class ::time(day)); }
748 //inline bool operator <= (const ::integral_day& day) const { return operator <= (class ::time(day)); }
749 //inline bool operator > (const ::integral_day& day) const { return operator > (class ::time(day)); }
750 //inline bool operator >= (const ::integral_day& day) const { return operator >= (class ::time(day)); }
751
752
753
754
755
756
757
758
759 //inline bool operator == (const ::floating_nanosecond& floatingnanosecond) const { return operator == (class ::time(floatingnanosecond)); }
760 //inline bool operator != (const ::floating_nanosecond& floatingnanosecond) const { return operator != (class ::time(floatingnanosecond)); }
761 //inline bool operator < (const ::floating_nanosecond& floatingnanosecond) const { return operator < (class ::time(floatingnanosecond)); }
762 //inline bool operator <= (const ::floating_nanosecond& floatingnanosecond) const { return operator <= (class ::time(floatingnanosecond)); }
763 //inline bool operator > (const ::floating_nanosecond& floatingnanosecond) const { return operator > (class ::time(floatingnanosecond)); }
764 //inline bool operator >= (const ::floating_nanosecond& floatingnanosecond) const { return operator >= (class ::time(floatingnanosecond)); }
765
766 //inline bool operator == (const ::floating_microsecond& floatingmicrosecond) const { return operator == (class ::time(floatingmicrosecond)); }
767 //inline bool operator != (const ::floating_microsecond& floatingmicrosecond) const { return operator != (class ::time(floatingmicrosecond)); }
768 //inline bool operator < (const ::floating_microsecond& floatingmicrosecond) const { return operator < (class ::time(floatingmicrosecond)); }
769 //inline bool operator <= (const ::floating_microsecond& floatingmicrosecond) const { return operator <= (class ::time(floatingmicrosecond)); }
770 //inline bool operator > (const ::floating_microsecond& floatingmicrosecond) const { return operator > (class ::time(floatingmicrosecond)); }
771 //inline bool operator >= (const ::floating_microsecond& floatingmicrosecond) const { return operator >= (class ::time(floatingmicrosecond)); }
772
773 //inline bool operator == (const ::floating_millisecond& floatingmillisecond) const { return operator == (class ::time(floatingmillisecond)); }
774 //inline bool operator != (const ::floating_millisecond& floatingmillisecond) const { return operator != (class ::time(floatingmillisecond)); }
775 //inline bool operator < (const ::floating_millisecond& floatingmillisecond) const { return operator < (class ::time(floatingmillisecond)); }
776 //inline bool operator <= (const ::floating_millisecond& floatingmillisecond) const { return operator <= (class ::time(floatingmillisecond)); }
777 //inline bool operator > (const ::floating_millisecond& floatingmillisecond) const { return operator > (class ::time(floatingmillisecond)); }
778 //inline bool operator >= (const ::floating_millisecond& floatingmillisecond) const { return operator >= (class ::time(floatingmillisecond)); }
779
780 //inline bool operator == (const ::floating_second& floatingsecond) const { return operator == (class ::time(floatingsecond)); }
781 //inline bool operator != (const ::floating_second& floatingsecond) const { return operator != (class ::time(floatingsecond)); }
782 //inline bool operator < (const ::floating_second& floatingsecond) const { return operator < (class ::time(floatingsecond)); }
783 //inline bool operator <= (const ::floating_second& floatingsecond) const { return operator <= (class ::time(floatingsecond)); }
784 //inline bool operator > (const ::floating_second& floatingsecond) const { return operator > (class ::time(floatingsecond)); }
785 //inline bool operator >= (const ::floating_second& floatingsecond) const { return operator >= (class ::time(floatingsecond)); }
786
787 //inline bool operator == (const ::floating_minute& minute) const { return operator == (class ::time(minute)); }
788 //inline bool operator != (const ::floating_minute& minute) const { return operator != (class ::time(minute)); }
789 //inline bool operator < (const ::floating_minute& minute) const { return operator < (class ::time(minute)); }
790 //inline bool operator <= (const ::floating_minute& minute) const { return operator <= (class ::time(minute)); }
791 //inline bool operator > (const ::floating_minute& minute) const { return operator > (class ::time(minute)); }
792 //inline bool operator >= (const ::floating_minute& minute) const { return operator >= (class ::time(minute)); }
793
794 //inline bool operator == (const ::floating_hour& day) const { return operator == (class ::time(day)); }
795 //inline bool operator != (const ::floating_hour& day) const { return operator != (class ::time(day)); }
796 //inline bool operator < (const ::floating_hour& day) const { return operator < (class ::time(day)); }
797 //inline bool operator <= (const ::floating_hour& day) const { return operator <= (class ::time(day)); }
798 //inline bool operator > (const ::floating_hour& day) const { return operator > (class ::time(day)); }
799 //inline bool operator >= (const ::floating_hour& day) const { return operator >= (class ::time(day)); }
800
801 //inline bool operator == (const ::floating_day& day) const { return operator == (class ::time(day)); }
802 //inline bool operator != (const ::floating_day& day) const { return operator != (class ::time(day)); }
803 //inline bool operator < (const ::floating_day& day) const { return operator < (class ::time(day)); }
804 //inline bool operator <= (const ::floating_day& day) const { return operator <= (class ::time(day)); }
805 //inline bool operator > (const ::floating_day& day) const { return operator > (class ::time(day)); }
806 //inline bool operator >= (const ::floating_day& day) const { return operator >= (class ::time(day)); }
807
808
809
810
811
812
813
814
815 //time operator %(const ::integral_nanosecond& time) const { return operator % ((class ::time)time); }
816 //::f64 operator /(const ::integral_nanosecond& time) const { return operator / ((class ::time)time); }
817 //time operator +(const ::integral_nanosecond& time) const { return operator + ((class ::time)time); }
818 //time operator -(const ::integral_nanosecond& time) const { return operator - ((class ::time)time); }
819
820
821 //time operator %(const ::integral_microsecond& time) const { return operator % ((class ::time)time); }
822 //::f64 operator /(const ::integral_microsecond& time) const { return operator / ((class ::time)time); }
823 //time operator +(const ::integral_microsecond& time) const { return operator + ((class ::time)time); }
824 //time operator -(const ::integral_microsecond& time) const { return operator - ((class ::time)time); }
825
826
827 //time operator %(const ::integral_millisecond& time) const { return operator % ((class ::time)time); }
828 //::f64 operator /(const ::integral_millisecond& time) const { return operator / ((class ::time)time); }
829 //time operator +(const ::integral_millisecond& time) const { return operator + ((class ::time)time); }
830 //time operator -(const ::integral_millisecond& time) const { return operator - ((class ::time)time); }
831
832
833 //time operator %(const ::integral_second& time) const { return operator % ((class ::time)time); }
834 //::f64 operator /(const ::integral_second& time) const { return operator / ((class ::time)time); }
835 //time operator +(const ::integral_second& time) const { return operator + ((class ::time)time); }
836 //time operator -(const ::integral_second& time) const { return operator - ((class ::time)time); }
837
838
839 //time operator %(const ::integral_minute& time) const { return operator % ((class ::time)time); }
840 //::f64 operator /(const ::integral_minute& time) const { return operator / ((class ::time)time); }
841 //time operator +(const ::integral_minute& time) const { return operator + ((class ::time)time); }
842 //time operator -(const ::integral_minute& time) const { return operator - ((class ::time)time); }
843
844
845 //time operator %(const ::integral_hour& time) const { return operator % ((class ::time)time); }
846 //::f64 operator /(const ::integral_hour& time) const { return operator / ((class ::time)time); }
847 //time operator +(const ::integral_hour& time) const { return operator + ((class ::time)time); }
848 //time operator -(const ::integral_hour& time) const { return operator - ((class ::time)time); }
849
850
851 //time operator %(const ::integral_day& time) const { return operator % ((class ::time)time); }
852 //::f64 operator /(const ::integral_day& time) const { return operator / ((class ::time)time); }
853 //time operator +(const ::integral_day& time) const { return operator + ((class ::time)time); }
854 //time operator -(const ::integral_day& time) const { return operator - ((class ::time)time); }
855
856
857
858
859
860
861
862
863
864 //time operator %(const ::floating_nanosecond& time) const { return operator % ((class ::time)time); }
865 //::f64 operator /(const ::floating_nanosecond& time) const { return operator / ((class ::time)time); }
866 //time operator +(const ::floating_nanosecond& time) const { return operator + ((class ::time)time); }
867 //time operator -(const ::floating_nanosecond& time) const { return operator - ((class ::time)time); }
868
869
870 //time operator %(const ::floating_microsecond& time) const { return operator % ((class ::time)time); }
871 //::f64 operator /(const ::floating_microsecond& time) const { return operator / ((class ::time)time); }
872 //time operator +(const ::floating_microsecond& time) const { return operator + ((class ::time)time); }
873 //time operator -(const ::floating_microsecond& time) const { return operator - ((class ::time)time); }
874
875
876 //time operator %(const ::floating_millisecond& time) const { return operator % ((class ::time)time); }
877 //::f64 operator /(const ::floating_millisecond& time) const { return operator / ((class ::time)time); }
878 //time operator +(const ::floating_millisecond& time) const { return operator + ((class ::time)time); }
879 //time operator -(const ::floating_millisecond& time) const { return operator - ((class ::time)time); }
880
881
882 //time operator %(const ::floating_second& time) const { return operator % ((class ::time)time); }
883 //::f64 operator /(const ::floating_second& time) const { return operator / ((class ::time)time); }
884 //time operator +(const ::floating_second& time) const { return operator + ((class ::time)time); }
885 //time operator -(const ::floating_second& time) const { return operator - ((class ::time)time); }
886
887
888 //time operator %(const ::floating_minute& time) const { return operator % ((class ::time)time); }
889 //::f64 operator /(const ::floating_minute& time) const { return operator / ((class ::time)time); }
890 //time operator +(const ::floating_minute& time) const { return operator + ((class ::time)time); }
891 //time operator -(const ::floating_minute& time) const { return operator - ((class ::time)time); }
892
893
894 //time operator %(const ::floating_hour& time) const { return operator % ((class ::time)time); }
895 //::f64 operator /(const ::floating_hour& time) const { return operator / ((class ::time)time); }
896 //time operator +(const ::floating_hour& time) const { return operator + ((class ::time)time); }
897 //time operator -(const ::floating_hour& time) const { return operator - ((class ::time)time); }
898
899
900 //time operator %(const ::floating_day& time) const { return operator % ((class ::time)time); }
901 //::f64 operator /(const ::floating_day& time) const { return operator / ((class ::time)time); }
902 //time operator +(const ::floating_day& time) const { return operator + ((class ::time)time); }
903 //time operator -(const ::floating_day& time) const { return operator - ((class ::time)time); }
904
905
906
907
908};
909
910
911//inline f64d floatingtime() { return ::get_floating_second(); }
912
913//template < prototype_integral INTEGRAL1, prototype_integral INTEGRAL2 >
914//constexpr time::time(enum_raw, INTEGRAL1 iSeconds, INTEGRAL2 iNanoseconds)
915//{
916//
917// m_iSecond = iSeconds;
918//
919// m_iNanosecond = iNanoseconds;
920//
921//}
922//
923//template < prototype_integral INTEGRAL1, prototype_integral INTEGRAL2 >
924//constexpr time::time(enum_normalize, INTEGRAL1 iSeconds, INTEGRAL2 iNanoseconds)
925//{
926//
927// m_iSecond = iSeconds + iNanoseconds / 1'000'000'000;
928//
929// m_iNanosecond = iNanoseconds % 1'000'000'000;
930//
931// while(m_iNanosecond < 0)
932// {
933//
934// m_iSecond--;
935//
936// m_iNanosecond += 1'000'000'000;
937//
938// }
939//
940//}
941
942
943//inline timeclass ::time(const class ::time& time) :
944// DURATION(time)
945//{
946//
947//}
948
949
950constexpr void time::raw_set(posix_time posixtime, nanosecond nanosecond)
951{
952
953 posix_time::operator = (posixtime);
954
955 nanosecond::operator = (nanosecond);
956
957}
958
959
960constexpr void time::set(posix_time posixtime, nanosecond nanosecond)
961{
962
963 raw_set(posixtime, nanosecond);
964
965 normalize();
966
967}
968
969
970constexpr void time::set_null()
971{
972
973 raw_set({ posix_time_t{}, 0 }, { nanosecond_t{}, 0 });
974
975}
976
977
978constexpr class ::time time::raw_create(posix_time posixtime, nanosecond nanosecond)
979{
980
981 time time;
982
983 time.raw_set(posixtime, nanosecond);
984
985 return time;
986
987}
988
989
990
991constexpr class ::time time::create(posix_time posixtime, nanosecond nanosecond)
992{
993
994 time time;
995
996 time.set(posixtime, nanosecond);
997
998 return time;
999
1000}
1001
1002
1003constexpr class ::time time::create_null()
1004{
1005
1006 time time;
1007
1008 time.set_null();
1009
1010 return time;
1011
1012}
1013
1014
1015//inline bool time::is_pos_infinity() const
1016//{
1017//
1018// return m_iSecond == ::numeric_info < decltype(m_iSecond) > ::maximum();
1019//
1020//}
1021//
1022
1023constexpr bool time::is_infinite() const
1024{
1025
1026 return m_iSecond == ::numeric_info < decltype(m_iSecond) > ::maximum();
1027
1028}
1029
1030constexpr bool time::is_null() const
1031{
1032
1033 return m_iSecond == 0 && m_iNanosecond == 0;
1034
1035}
1036
1037//constexpr bool time::is_zero() const
1038//{
1039//
1040// return m_iSecond < 0 || (m_iSecond == 0 && m_iNanosecond <= 0);
1041//
1042//}
1043
1044
1045constexpr class ::time time::infinity()
1046{
1047
1048 return {(::i64)I64_MAXIMUM,(::i64)0};
1049
1050}
1051
1052
1053//inline class ::time time::pos_infinity()
1054//{
1055//
1056// return {(::i64)I64_MAXIMUM, (::i64)0};
1057//
1058//}
1059
1060
1061//constexpr class ::time time::zero()
1062//{
1063//
1064// return {(::i64)0,(::i64) 0};
1065//
1066//}
1067
1068
1069constexpr posix_time time::GetTimeSpan() const
1070{
1071
1072 return *this;
1073
1074}
1075
1076
1077//constexpr time::operator bool() const
1078//{
1079//
1080// return m_iSecond != 0 || m_iNanosecond != 0;
1081//
1082//}
1083
1084
1085//CLASS_DECL_ACME class ::time random(const class ::time & d1, const class ::time & d2);
1086
1087
1088
1089//inline class ::time time::wait() const
1090//{
1091//
1092// return is_infinite() ? ::time::infinite() : ::wait(m_iSecond, m_iNanosecond);
1093//
1094//}
1095
1096
1097template < prototype_floating FLOATING >
1098class time operator * (FLOATING d, const class time & time)
1099{
1100
1101 auto nanosecond = d * (time.m_iSecond * 1'000'000'000.0 + time.m_iNanosecond);
1102
1103 return { e_raw, (::i64)(nanosecond / 1'000'000'000.0), (long)fmod(nanosecond, 1'000'000'000.0) };
1104
1105}
1106
1107
1108template < prototype_integral INTEGRAL >
1109class time operator * (INTEGRAL i, const class time & time)
1110{
1111
1112 auto nanosecond = i * (time.m_iSecond * 1'000'000'000 + time.m_iNanosecond);
1113
1114 return { e_raw, (::i64)(nanosecond / 1'000'000'000), (long)(nanosecond % 1'000'000'000) };
1115
1116}
1117
1118
1119//template < typename DURATION >
1120//inline ::wait integral_time < DURATION >::wait() const
1121//{
1122//
1123// class time time(*this);
1124//
1125// return time.integral_nanosecond().m_i32;
1126//
1127//}
1128
1129
1130constexpr bool time::timeout(const class time & time, const class time & timeNow)
1131{
1132
1133 if (elapsed(timeNow) < time)
1134 {
1135
1136 return false;
1137
1138 }
1139
1140 operator =(timeNow);
1141
1142 return true;
1143
1144}
1145
1146
1147inline class time time::remaining(const class time & time, const class time & timeNow)
1148{
1149
1150 auto timeRemaining = time - elapsed(timeNow);
1151
1152 return timeRemaining;
1153
1154}
1155
1156
1157
1158
1159
1160//constexpr struct ::timespec & copy(struct ::timespec & timespec, const class ::time & time)
1161//{
1162//
1163// timespec.tv_sec = (decltype(timespec.tv_sec))time.m_iSecond;
1164// timespec.tv_nsec = (decltype(timespec.tv_nsec))time.m_iNanosecond;
1165//
1166// return timespec;
1167//
1168//}
1169//
1170//
1171//constexpr struct ::timespec & add(struct ::timespec & timespec1, const struct ::timespec & timespec2)
1172//{
1173//
1174// add_second_nanosecond(timespec1.tv_sec, timespec1.tv_nsec, timespec2.tv_sec, timespec2.tv_nsec);
1175//
1176// return timespec1;
1177//
1178//}
1179//
1180//
1181//constexpr struct ::timespec addition(const struct ::timespec & timespec1, const struct ::timespec & timespec2)
1182//{
1183//
1184// timespec timespec = timespec1;
1185//
1186// add_second_nanosecond(timespec.tv_sec, timespec.tv_nsec, timespec2.tv_sec, timespec2.tv_nsec);
1187//
1188// return timespec;
1189//
1190//}
1191//
1192//
1193//constexpr struct ::timespec & subtract(struct ::timespec & timespec1, const struct ::timespec & timespec2)
1194//{
1195//
1196// subtract_second_nanosecond(timespec1.tv_sec, timespec1.tv_nsec, timespec2.tv_sec, timespec2.tv_nsec);
1197//
1198// return timespec1;
1199//
1200//}
1201//
1202//
1203//constexpr struct ::timespec subtraction(const struct ::timespec & timespec1, const struct ::timespec & timespec2)
1204//{
1205//
1206// timespec timespec = timespec1;
1207//
1208// return subtract(timespec, timespec2);
1209//
1210//}
1211//
1212//
1213//constexpr bool operator >(const struct ::timespec & timespec1, const struct ::timespec & timespec2)
1214//{
1215//
1216// return timespec1.tv_sec > timespec2.tv_sec || (timespec1.tv_sec == timespec2.tv_sec && timespec1.tv_nsec > timespec2.tv_nsec);
1217//
1218//}
1219//
1220
1221
1222//DEFINE_COMPARISON_WITH_TIME(inline, integral_nanosecond)
1223//DEFINE_COMPARISON_WITH_TIME(inline, integral_microsecond)
1224//DEFINE_COMPARISON_WITH_TIME(inline, integral_millisecond)
1225//DEFINE_COMPARISON_WITH_TIME(inline, integral_second)
1226//DEFINE_COMPARISON_WITH_TIME(inline, integral_minute)
1227//DEFINE_COMPARISON_WITH_TIME(inline, integral_hour)
1228//DEFINE_COMPARISON_WITH_TIME(inline, integral_day)
1229//
1230//
1231//DEFINE_COMPARISON_WITH_TIME(inline, floating_nanosecond)
1232//DEFINE_COMPARISON_WITH_TIME(inline, floating_microsecond)
1233//DEFINE_COMPARISON_WITH_TIME(inline, floating_millisecond)
1234//DEFINE_COMPARISON_WITH_TIME(inline, floating_second)
1235//DEFINE_COMPARISON_WITH_TIME(inline, floating_minute)
1236//DEFINE_COMPARISON_WITH_TIME(inline, floating_hour)
1237//DEFINE_COMPARISON_WITH_TIME(inline, floating_day)
1238
1239
1240
1241
1242
1243template < prototype_integral INTEGRAL >
1244constexpr class time nanosecond_time(INTEGRAL i) { return { (INTEGRAL)i / 1'000'000'000, (long)(i % 1'000'000'000) }; }
1245template < prototype_floating FLOATING >
1246constexpr class time nanosecond_time(FLOATING f) { return { (::i64)(f / 1'000'000'000.0), (long)(fmod(f, 1'000'000'000.0)) }; }
1247template < prototype_integral INTEGRAL >
1248constexpr class time microsecond_time(INTEGRAL i) { return { i / 1'000'000, (long)((i % 1'000'000) * 1'000) }; }
1249template < prototype_floating FLOATING >
1250constexpr class time microsecond_time(FLOATING f) { return { (::i64)(f / 1'000'000.0), (long)(fmod(f, 1'000'000.0) * 1'000.0) }; }
1251template < prototype_integral INTEGRAL >
1252constexpr class time millisecond_time(INTEGRAL i) { return { i / 1'000, (long)((i % 1'000) * 1'000'000) }; }
1253template < prototype_floating FLOATING >
1254constexpr class time millisecond_time(FLOATING f) { return { (::i64)(f / 1'000.0), (long)(fmod(f, 1'000.0) * 1'000'000.0) }; }
1255template < prototype_integral INTEGRAL >
1256constexpr class time second_time(INTEGRAL i) { return { i }; }
1257template < prototype_integral NUMERATOR, prototype_integral DENOMINATOR >
1258constexpr class time second_time(NUMERATOR numerator, DENOMINATOR denominator)
1259{
1260 return
1261 {
1262 (::i64) (numerator / denominator),
1263 (::i64) muldiv64((numerator % denominator), 1'000'000'000 , denominator)
1264 };
1265}
1266template < prototype_floating FLOATING >
1267constexpr class time second_time(FLOATING f) { return { (FLOATING)(f), (long)(fmod(f, 1.0) * 1'000'000'000.0) }; }
1268template < prototype_integral INTEGRAL >
1269constexpr class time minute_time(INTEGRAL i) { return { i * 60 }; }
1270template < prototype_floating FLOATING >
1271constexpr class time minute_time(FLOATING f) { return { (FLOATING)(f * 60.0), (long)(fmod(f * 60.0, 1.0) * 1'000'000'000.0) }; }
1272template < prototype_integral INTEGRAL >
1273constexpr class time hour_time(INTEGRAL i) { return { i * 3'600 }; }
1274template < prototype_floating FLOATING >
1275constexpr class time hour_time(FLOATING f) { return { (FLOATING)(f * 3'600.0), (long)(fmod(f * 3'600.0, 1.0) * 1'000'000'000.0) }; }
1276template < prototype_integral INTEGRAL >
1277constexpr class time day_time(INTEGRAL i) { return { i * 86'400 }; }
1278template < prototype_floating FLOATING >
1279constexpr class time day_time(FLOATING f) { return { (FLOATING)(f * 86'400.0), (long)(fmod(f * 86'400.0, 1.0) * 1'000'000'000.0) }; }
1280
1281
1282
1283
1284constexpr void time::normalize()
1285{
1286
1287 m_iSecond += m_iNanosecond / SECOND_NANOS;
1288
1289 m_iNanosecond %= SECOND_NANOS;
1290
1291 ::i32 iSecondSign = ::numeric::sign(m_iSecond);
1292
1293 ::i32 iNanosecondSign = ::numeric::sign(m_iNanosecond);
1294
1295 if (iSecondSign == -iNanosecondSign && iSecondSign != 0)
1296 {
1297
1298 m_iSecond -= iSecondSign;
1299
1300 m_iNanosecond += iSecondSign * SECOND_NANOS;
1301
1302 }
1303
1304}
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316constexpr class ::time time::half() const
1317{
1318
1319 auto nanosecond = (m_iSecond * 1'000'000'000 + m_iNanosecond);
1320
1321 auto iSecond = (::i64)(nanosecond / 1'000'000'000);
1322
1323 auto iNanosecond = (long)(nanosecond % 1'000'000'000);
1324
1325 return { e_raw, iSecond, iNanosecond };
1326
1327}
1328
1329
1330
1331constexpr class ::time & time::operator %= (const class time & time)
1332{
1333
1334 auto nanosecondThis = m_iSecond * 1'000'000'000 + m_iNanosecond;
1335
1336 auto nanosecond = time.m_iSecond * 1'000'000'000 + time.m_iNanosecond;
1337
1338 nanosecondThis %= nanosecond;
1339
1340 m_iSecond = nanosecondThis / 1'000'000'000;
1341
1342 m_iNanosecond = nanosecondThis % 1'000'000'000;
1343
1344 return *this;
1345
1346}
1347
1348
1349constexpr class ::time time::operator % (const class time & time) const
1350{
1351
1352 class ::time timeResult(*this);
1353
1354 timeResult %= time;
1355
1356 return timeResult;
1357
1358}
1359
1360
1361constexpr ::f64 time::operator / (const class time & time) const
1362{
1363
1364 auto nanosecondThis = m_iSecond * 1'000'000'000 + m_iNanosecond;
1365
1366 auto nanosecond = time.m_iSecond * 1'000'000'000 + time.m_iNanosecond;
1367
1368 return (::f64)nanosecondThis / (::f64)nanosecond;
1369
1370}
1371
1372
1373
1374
1375constexpr void time::set(::i64 i, enum_unit eunit)
1376{
1377
1378 switch (eunit)
1379 {
1380 case unit_nanos:
1381 raw_set({ posix_time_t{}, i / (1000 * 1000 * 1000) }, { nanosecond_t{}, i % (1000 * 1000 * 1000) });
1382 break;
1383 case unit_micros:
1384 raw_set({ posix_time_t{},i / (1000 * 1000) }, { nanosecond_t{},(i / 1000) % (1000 * 1000 * 1000) });
1385 break;
1386 case unit_millis:
1387 raw_set({ posix_time_t{}, i / 1000 }, { nanosecond_t{},(i / (1000 * 1000)) % (1000 * 1000 * 1000) });
1388 break;
1389 case unit_seconds:
1390 raw_set({ posix_time_t{}, i }, { nanosecond_t{},0});
1391 break;
1392 case unit_minutes:
1393 raw_set({ posix_time_t{},i * 60 },{ nanosecond_t{},0});
1394 break;
1395 case unit_hours:
1396 raw_set({ posix_time_t{},i * 60 * 60 }, { nanosecond_t{}, 0 });
1397 break;
1398 default:
1399 throw_exception(error_bad_argument);
1400
1401 };
1402
1403}
1404
1405
1406
1407
1408
1409
Definition earth_gregorian_time.h:15
Definition aaa_nanosecond.h:9
Definition aaa_time.h:13
Definition posix_time.h:8