acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
earth_time_span.h
1
#pragma once
2
3
//
4
//#define _EARTH_TIME_SPAN_COMPARISON_WITH(TYPE) \
5
// inline bool operator == (const TYPE & t) const { return operator == (class ::time(t)); } \
6
// inline ::std::strong_ordering operator <=> (const TYPE & t) const { return operator <=> (class ::time(t)); }
7
8
9
#define _TIME_COMPARISON_WITH(TYPE) \
10
inline bool operator == (const TYPE & t) const { return operator == ((class ::time) t); } \
11
inline ::std::strong_ordering operator <=> (const TYPE & t) const { return operator <=> ((class ::time) t); }
12
13
14
namespace
earth
15
{
16
17
18
class
CLASS_DECL_ACME time_span :
19
public
posix_time
20
{
21
public
:
22
23
24
//posix_time m_posixtime;
25
26
27
constexpr
time_span()
noexcept
;
28
constexpr
time_span(::i64 lDays,::i32 nHours,::i32 nMins,::i32 nSecs)
noexcept
;
29
constexpr
time_span(
const
posix_time & posixtime) noexcept : posix_time(posixtime) {}
30
constexpr
time_span(
const
class ::time &
time
) noexcept : posix_time(
time
) {}
31
32
33
constexpr ::i64 days()
const
noexcept
;
34
constexpr ::i64 hours()
const
noexcept
;
35
constexpr ::i32 hour()
const
noexcept
;
36
constexpr ::i64 minutes()
const
noexcept
;
37
constexpr ::i32 minute()
const
noexcept
;
38
constexpr ::i64 seconds()
const
noexcept
;
39
constexpr ::i32 second()
const
noexcept
;
40
41
constexpr
posix_time GetTimeSpan()
const
noexcept
;
42
43
constexpr
time_span operator +(time_span span)
const
noexcept
;
44
constexpr
time_span operator-(time_span span)
const
noexcept
;
45
constexpr
time_span& operator +=(time_span span)
noexcept
;
46
constexpr
time_span& operator-=(time_span span)
noexcept
;
47
48
constexpr
operator
time
()
const
49
{
50
51
return ::earth::time({
posix_time_t
{}, seconds() });
52
53
}
54
55
56
//DECLARE_COMPARISON_WITH_TIME(inline)
57
58
59
// _TIME_COMPARISON_WITH(::integral_nanosecond);
60
// _TIME_COMPARISON_WITH(::integral_microsecond);
61
// _TIME_COMPARISON_WITH(::integral_millisecond);
62
// //_TIME_COMPARISON_WITH(::integral_second);
63
// _TIME_COMPARISON_WITH(::integral_minute);
64
// _TIME_COMPARISON_WITH(::integral_hour);
65
// _TIME_COMPARISON_WITH(::integral_day);
66
//
67
// _TIME_COMPARISON_WITH(::integral_nanosecond);
68
// _TIME_COMPARISON_WITH(::integral_microsecond);
69
// _TIME_COMPARISON_WITH(::integral_millisecond);
70
// //_TIME_COMPARISON_WITH(::integral_second);
71
// _TIME_COMPARISON_WITH(::integral_minute);
72
// _TIME_COMPARISON_WITH(::integral_hour);
73
// _TIME_COMPARISON_WITH(::integral_day);
74
75
76
// _TIME_COMPARISON_WITH(::floating_nanosecond);
77
// _TIME_COMPARISON_WITH(::floating_microsecond);
78
// _TIME_COMPARISON_WITH(::floating_millisecond);
79
// _TIME_COMPARISON_WITH(::floating_second);
80
// _TIME_COMPARISON_WITH(::floating_minute);
81
// _TIME_COMPARISON_WITH(::floating_hour);
82
// _TIME_COMPARISON_WITH(::floating_day);
83
//
84
// _TIME_COMPARISON_WITH(::floating_nanosecond);
85
// _TIME_COMPARISON_WITH(::floating_microsecond);
86
// _TIME_COMPARISON_WITH(::floating_millisecond);
87
// _TIME_COMPARISON_WITH(::floating_second);
88
// _TIME_COMPARISON_WITH(::floating_minute);
89
// _TIME_COMPARISON_WITH(::floating_hour);
90
// _TIME_COMPARISON_WITH(::floating_day);
91
92
93
constexpr
class ::time operator % (class ::time &
time
)
const
noexcept
94
{
95
96
return
((class ::time) *
this
) %
time
;
97
98
}
99
100
101
102
constexpr ::std::strong_ordering operator <=>(
const
class ::time &
time
)
const
;
103
constexpr ::std::strong_ordering operator <=>(
const
time_span & timespan)
const
{
return
m_iSecond <=> timespan.m_iSecond; }
104
105
};
106
107
108
constexpr
time_span::time_span() noexcept
109
{
110
111
}
112
113
114
constexpr
time_span::time_span(::i64 lDays, ::i32 nHours, ::i32 nMins, ::i32 nSecs)
noexcept
115
{
116
117
m_iSecond = nSecs + 60 * (nMins + 60 * (nHours + 24ll * lDays));
118
119
}
120
121
122
constexpr ::i64 time_span::days() const noexcept
123
{
124
125
return
m_iSecond / (24 * 3600);
126
127
}
128
129
130
constexpr ::i64 time_span::hours() const noexcept
131
{
132
133
return
m_iSecond / 3600;
134
135
}
136
137
138
constexpr ::i32 time_span::hour() const noexcept
139
{
140
141
return
hours() % 24;
142
143
}
144
145
146
constexpr ::i64 time_span::minutes() const noexcept
147
{
148
149
return
m_iSecond / 60;
150
151
}
152
153
154
constexpr ::i32 time_span::minute() const noexcept
155
{
156
157
return
minutes() % 60;
158
159
}
160
161
162
constexpr ::i64 time_span::seconds() const noexcept
163
{
164
165
return
m_iSecond;
166
167
}
168
169
170
constexpr ::i32 time_span::second() const noexcept
171
{
172
173
return
m_iSecond % 60;
174
175
}
176
177
178
constexpr
posix_time time_span::GetTimeSpan() const noexcept
179
{
180
181
return
*
this
;
182
183
}
184
185
186
constexpr
time_span
time_span::operator +(
time_span
span)
const
noexcept
187
{
188
189
return
posix_time::operator +(span);
190
191
}
192
193
194
constexpr
time_span
time_span::operator-(
time_span
span)
const
noexcept
195
{
196
197
return
posix_time::operator-(span);
198
199
}
200
201
202
constexpr
time_span
& time_span::operator +=(
time_span
span)
noexcept
203
{
204
205
posix_time::operator +=(span);
206
207
return
*
this
;
208
209
}
210
211
212
constexpr
time_span
& time_span::operator-=(
time_span
span)
noexcept
213
{
214
215
posix_time::operator -=(span);
216
217
return
*
this
;
218
219
}
220
221
//DEFINE_COMPARISON_WITH_TIME(inline, time_span);
222
223
}
// namespace earth
224
225
226
227
228
229
earth::time_span
Definition
earth_time_span.h:20
earth::time
Definition
earth_time.h:33
posix_time_t
Definition
posix_time.h:5
prototype
datetime
earth_time_span.h
Generated by
1.17.0