acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
earth_gregorian_time.h
1//
2// Created by camilo on 2022-10-12 10:11 <3ThomasBorregaardSorensen!!
3//
4#pragma once
5
6
7#include "earth_time_shift.h"
8
9
10namespace earth
11{
12
13
14 class CLASS_DECL_ACME gregorian_time
15 {
16 public:
17
18
19 ::i32 m_iDayOfWeek;
20
21
22 ::i64 m_iNanoSecond;
23 ::i32 m_iSecond; /* Seconds. [0-60] (1 leap second) */
24 ::i32 m_iMinute; /* Minutes. [0-59] */
25 ::i32 m_iHour; /* Hours. [0-23] */
26 ::i32 m_iDay; /* Day. [1-31] */
27 ::i32 m_iMonth; /* Month. [0-11] */
28 ::i32 m_iYear;
29
30
31 inline gregorian_time()
32 {
33
34 m_iDayOfWeek = 0;
35
36
37 m_iNanoSecond = 0;
38 m_iSecond =0; /* Seconds. [0-60] (1 leap second) */
39 m_iMinute =0 ; /* Minutes. [0-59] */
40 m_iHour=0; /* Hours. [0-23] */
41 m_iDay=0; /* Day. [1-31] */
42 m_iMonth=0; /* Month. [0-11] */
43 m_iYear=0;
44
45 }
46
47
48 explicit gregorian_time(const ::posix_time & posixtime, ::i64 iNanosecond = 0, const class ::time & timeshift = {});
49 explicit gregorian_time(const class ::time & time, const class ::time & timeshift = {});
50 explicit gregorian_time(const ::system_time & systemtime, const class ::time & timeshift = {});
51 explicit gregorian_time(const ::file_time & filetime, const class ::time & timeshift = {});
52
53
54 void set(const ::posix_time & time, ::i64 iNanosecond, const class ::time & timeshift);
55
56 void set(const class ::time & time, const class ::time & timeshift);
57
58 //void set(const ::earth::time & time, const class ::time & timeshift);
59
60 ::posix_time get_posix_time();
61
62
63 // inline void get(struct ::tm *ptm)
64 // {
65 //
66 // ptm->tm_sec = m_iSecond;
67 // ptm->tm_min = m_iMinute;
68 // ptm->tm_hour = m_iHour;
69 // ptm->tm_mday = m_iDay;
70 // ptm->tm_mon = m_iMonth;
71 // ptm->tm_year = m_iYear - 1900;
72 //
73 // }
74
75
76 //void get(system_time_t * psystemtime);
77
78 //void get(file_time & filetime);
79
80
81
82 //void Now(const class ::time &timeshift = {});
83
84
85 posix_time make_utc_time() const;
86
87
88 };
89
90 constexpr int32_t is_leap_year(::i32 year)
91 {
92 if (year % 400 == 0)
93 return 1;
94 if (year % 100 == 0)
95 return 0;
96 if (year % 4 == 0)
97 return 1;
98 return 0;
99 }
100
101
102 constexpr ::i32 days_from_0(::i32 year)
103 {
104 year--;
105 return 365 * year + (year / 400) - (year / 100) + (year / 4);
106 }
107
108
109 constexpr ::i32 days_from_1970(::i32 year)
110 {
111 const auto days_from_0_to_1970 = days_from_0(1970);
112 return days_from_0(year) - days_from_0_to_1970;
113 }
114
115
116 CLASS_DECL_ACME ::i32 days_from_1jan(::i32 year, ::i32 month, ::i32 day);
117
118
119
120
121} // namespace earth
122
123
Definition earth_time.h:33
Definition posix_time.h:8