| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/times.hpp" | ||
| 30 | #include "gate/results.hpp" | ||
| 31 | #include "gate/exceptions.hpp" | ||
| 32 | |||
| 33 | namespace gate | ||
| 34 | { | ||
| 35 | |||
| 36 | |||
| 37 | 27 | Time::Time(timestamp_t microsince1601, int32_t biasminutes) | |
| 38 | { | ||
| 39 | 27 | gate_time_t& t = *this; | |
| 40 | 27 | gate_mem_clear(&t, sizeof(t)); | |
| 41 | 27 | t.timestamp = microsince1601; | |
| 42 | 27 | t.bias = biasminutes; | |
| 43 | 27 | } | |
| 44 | 25 | Time::Time(gate_time_t const& src) | |
| 45 | 25 | : gate_time_t(src) | |
| 46 | { | ||
| 47 | 25 | } | |
| 48 | |||
| 49 | |||
| 50 | 6 | Time Time::now() | |
| 51 | { | ||
| 52 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | Time tm; |
| 53 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | result_t result = gate_time_now(&tm); |
| 54 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6 | GATEXX_CHECK_ERROR(result); |
| 55 | 6 | return tm; | |
| 56 | } | ||
| 57 | |||
| 58 | 1 | DateTime Time::toDateTime() const | |
| 59 | { | ||
| 60 | 1 | DateTime ret; | |
| 61 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_time_to_datetime(this, static_cast<gate_datetime_t*>(&ret)); |
| 62 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 63 | 1 | return ret; | |
| 64 | } | ||
| 65 | |||
| 66 | 1 | String Time::toString() const | |
| 67 | { | ||
| 68 | char buffer[1024]; | ||
| 69 | 1 | size_t bufferlen = sizeof(buffer); | |
| 70 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_time_to_string(this, NULL, buffer, &bufferlen); |
| 71 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 72 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, bufferlen); |
| 73 | } | ||
| 74 | 1 | String Time::toString(String const& format) const | |
| 75 | { | ||
| 76 | char pattern[1024]; | ||
| 77 | char buffer[1024]; | ||
| 78 | 1 | size_t bufferlen = sizeof(buffer); | |
| 79 | 1 | gate_time_t const* ptr_time = this; | |
| 80 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | format.copyTo(pattern, sizeof(pattern)); |
| 81 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_time_to_string(ptr_time, pattern, buffer, &bufferlen); |
| 82 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, bufferlen); |
| 84 | } | ||
| 85 | |||
| 86 | 2 | int64_t Time::toUnix() const | |
| 87 | { | ||
| 88 | 2 | int64_t ret = 0; | |
| 89 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_time_to_unix(this->timestamp, &ret); |
| 90 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_ERROR(result); |
| 91 | 2 | return ret; | |
| 92 | } | ||
| 93 | |||
| 94 | 2 | Time Time::add(int64_t microseconds) const | |
| 95 | { | ||
| 96 | 2 | return Time(this->timestamp + microseconds, this->bias); | |
| 97 | } | ||
| 98 | 3 | int64_t Time::diff(Time const& t) const | |
| 99 | { | ||
| 100 | 3 | return this->timestamp - t.timestamp; | |
| 101 | } | ||
| 102 | 3 | bool_t Time::empty() const | |
| 103 | { | ||
| 104 | 3 | return this->timestamp == 0; | |
| 105 | } | ||
| 106 | |||
| 107 | 1 | time::Microseconds Time::operator-(Time const& t) const | |
| 108 | { | ||
| 109 | 1 | return time::Microseconds(this->diff(t)); | |
| 110 | } | ||
| 111 | 1 | bool Time::operator!() const | |
| 112 | { | ||
| 113 | 1 | return this->empty(); | |
| 114 | } | ||
| 115 | |||
| 116 | |||
| 117 | 2 | Result<Time> Time::tryParse(String const& text) | |
| 118 | { | ||
| 119 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | Time tm; |
| 120 |
1/2✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | result_t result = gate_time_parse_string(text.c_str(), text.size(), &tm); |
| 121 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return makeResult(result, tm); |
| 122 | } | ||
| 123 | 1 | Time Time::parse(String const& text) | |
| 124 | { | ||
| 125 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Result<Time> result = Time::tryParse(text); |
| 126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (result.hasError()) |
| 127 | { | ||
| 128 | ✗ | GATEXX_CHECK_EXCEPTION(result.error()); | |
| 129 | } | ||
| 130 | 2 | return result.value(); | |
| 131 | } | ||
| 132 | 1 | Time Time::fromUnix(int64_t unixSeconds) | |
| 133 | { | ||
| 134 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Time ret; |
| 135 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_time_from_unix(unixSeconds, &ret.timestamp); |
| 136 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 137 | 1 | return ret; | |
| 138 | } | ||
| 139 | 3 | Time Time::fromTimestamp(gate_timestamp_t source) | |
| 140 | { | ||
| 141 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | Time ret; |
| 142 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t result = gate_time_from_timestamp(source, &ret); |
| 143 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
3 | GATEXX_CHECK_ERROR(result); |
| 144 | 3 | return ret; | |
| 145 | } | ||
| 146 | |||
| 147 | 2 | bool Time::operator==(gate_timestamp_t const& src) const { return this->timestamp == src; } | |
| 148 | 2 | bool Time::operator!=(gate_timestamp_t const& src) const { return this->timestamp != src; } | |
| 149 | 1 | bool Time::operator< (gate_timestamp_t const& src) const { return this->timestamp < src; } | |
| 150 | 2 | bool Time::operator<=(gate_timestamp_t const& src) const { return this->timestamp <= src; } | |
| 151 | 1 | bool Time::operator> (gate_timestamp_t const& src) const { return this->timestamp > src; } | |
| 152 | 2 | bool Time::operator>=(gate_timestamp_t const& src) const { return this->timestamp >= src; } | |
| 153 | |||
| 154 | 2 | bool Time::operator==(Time const& src) const { return *this == src.timestamp; } | |
| 155 | 2 | bool Time::operator!=(Time const& src) const { return *this != src.timestamp; } | |
| 156 | 1 | bool Time::operator< (Time const& src) const { return *this < src.timestamp; } | |
| 157 | 2 | bool Time::operator<=(Time const& src) const { return *this <= src.timestamp; } | |
| 158 | 1 | bool Time::operator> (Time const& src) const { return *this > src.timestamp; } | |
| 159 | 2 | bool Time::operator>=(Time const& src) const { return *this >= src.timestamp; } | |
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | 3 | Date::Date(uint16_t years, uint8_t months, uint8_t days) | |
| 164 | 3 | : gate_date_t() | |
| 165 | { | ||
| 166 | 3 | this->year = years; | |
| 167 | 3 | this->month = months; | |
| 168 | 3 | this->day = days; | |
| 169 | 3 | } | |
| 170 | 1 | Date::Date(uint16_t years, MonthEnum months, uint8_t days) | |
| 171 | 1 | : gate_date_t() | |
| 172 | { | ||
| 173 | 1 | this->year = years; | |
| 174 | 1 | this->month = (gate_uint8_t)months; | |
| 175 | 1 | this->day = days; | |
| 176 | 1 | } | |
| 177 | 19 | Date::Date(gate_date_t const& date) | |
| 178 | 19 | : gate_date_t(date) | |
| 179 | { | ||
| 180 | 19 | } | |
| 181 | |||
| 182 | 14 | int Date::compare(Date const& that) const | |
| 183 | { | ||
| 184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (this->year < that.year) return -1; |
| 185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (this->year > that.year) return +1; |
| 186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (this->month < that.month) return -1; |
| 187 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (this->month > that.month) return +1; |
| 188 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
|
14 | if (this->day < that.day) return -1; |
| 189 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
|
12 | if (this->day > that.day) return +1; |
| 190 | 9 | return 0; | |
| 191 | } | ||
| 192 | 1 | bool_t Date::operator< (Date const& that) const | |
| 193 | { | ||
| 194 | 1 | return this->compare(that) < 0; | |
| 195 | } | ||
| 196 | 1 | bool_t Date::operator<=(Date const& that) const | |
| 197 | { | ||
| 198 | 1 | return this->compare(that) <= 0; | |
| 199 | } | ||
| 200 | 1 | bool_t Date::operator> (Date const& that) const | |
| 201 | { | ||
| 202 | 1 | return this->compare(that) > 0; | |
| 203 | } | ||
| 204 | 1 | bool_t Date::operator>=(Date const& that) const | |
| 205 | { | ||
| 206 | 1 | return this->compare(that) >= 0; | |
| 207 | } | ||
| 208 | 1 | bool_t Date::operator==(Date const& that) const | |
| 209 | { | ||
| 210 | 1 | return (this->day == that.day) | |
| 211 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | && (this->month == that.month) |
| 212 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | && (this->year == that.year); |
| 213 | } | ||
| 214 | 1 | bool_t Date::operator!=(Date const& that) const | |
| 215 | { | ||
| 216 | 1 | return (this->year != that.year) | |
| 217 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | || (this->month != that.month) |
| 218 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | || (this->day != that.day); |
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | 4 | DayTime::DayTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds) | |
| 224 | { | ||
| 225 | 4 | gate_daytime_t& dt = *this; | |
| 226 | 4 | gate_mem_clear(&dt, sizeof(dt)); | |
| 227 | 4 | dt.hour = hours; | |
| 228 | 4 | dt.minute = minutes; | |
| 229 | 4 | dt.second = seconds; | |
| 230 | 4 | dt.microsecond = microseconds; | |
| 231 | 4 | } | |
| 232 | |||
| 233 | 19 | DayTime::DayTime(gate_daytime_t const& dtime) | |
| 234 | { | ||
| 235 | 19 | gate_daytime_t& dt = *this; | |
| 236 | 19 | gate_mem_clear(&dt, sizeof(dt)); | |
| 237 | 19 | dt.hour = dtime.hour; | |
| 238 | 19 | dt.minute = dtime.minute; | |
| 239 | 19 | dt.second = dtime.second; | |
| 240 | 19 | dt.microsecond = dtime.microsecond; | |
| 241 | 19 | } | |
| 242 | |||
| 243 | 14 | int DayTime::compare(DayTime const& that) const | |
| 244 | { | ||
| 245 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
|
14 | if (this->hour < that.hour) return -1; |
| 246 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
|
12 | if (this->hour > that.hour) return +1; |
| 247 | |||
| 248 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (this->minute < that.minute) return -1; |
| 249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (this->minute > that.minute) return +1; |
| 250 | |||
| 251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (this->second < that.second) return -1; |
| 252 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (this->second > that.second) return +1; |
| 253 | |||
| 254 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
9 | if (this->microsecond < that.microsecond) return -1; |
| 255 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if (this->microsecond > that.microsecond) return +1; |
| 256 | |||
| 257 | 4 | return 0; | |
| 258 | } | ||
| 259 | |||
| 260 | 1 | bool_t DayTime::operator< (DayTime const& that) const | |
| 261 | { | ||
| 262 | 1 | return this->compare(that) < 0; | |
| 263 | } | ||
| 264 | 1 | bool_t DayTime::operator<=(DayTime const& that) const | |
| 265 | { | ||
| 266 | 1 | return this->compare(that) <= 0; | |
| 267 | } | ||
| 268 | 1 | bool_t DayTime::operator> (DayTime const& that) const | |
| 269 | { | ||
| 270 | 1 | return this->compare(that) > 0; | |
| 271 | } | ||
| 272 | 1 | bool_t DayTime::operator>=(DayTime const& that) const | |
| 273 | { | ||
| 274 | 1 | return this->compare(that) >= 0; | |
| 275 | } | ||
| 276 | 2 | bool_t DayTime::operator==(DayTime const& that) const | |
| 277 | { | ||
| 278 | 2 | return (this->second == that.second) | |
| 279 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | && (this->minute == that.minute) |
| 280 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | && (this->hour == that.hour) |
| 281 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
4 | && (this->microsecond == that.microsecond); |
| 282 | } | ||
| 283 | 1 | bool_t DayTime::operator!=(DayTime const& that) const | |
| 284 | { | ||
| 285 | 1 | return !(*this == that); | |
| 286 | } | ||
| 287 | |||
| 288 | |||
| 289 | 3 | DateTime::DateTime(uint16_t years, uint8_t months, uint8_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds) | |
| 290 | 3 | : gate_datetime_t() | |
| 291 | { | ||
| 292 | 3 | this->date.year = years; | |
| 293 | 3 | this->date.month = months; | |
| 294 | 3 | this->date.day = days; | |
| 295 | 3 | this->time.hour = hours; | |
| 296 | 3 | this->time.minute = minutes; | |
| 297 | 3 | this->time.second = seconds; | |
| 298 | 3 | this->time.microsecond = microseconds; | |
| 299 | 3 | } | |
| 300 | 1 | DateTime::DateTime(Date const& date, DayTime const& dt) | |
| 301 | 1 | : gate_datetime_t() | |
| 302 | { | ||
| 303 | 1 | this->date.year = date.year; | |
| 304 | 1 | this->date.month = date.month; | |
| 305 | 1 | this->date.day = date.day; | |
| 306 | 1 | this->time.hour = dt.hour; | |
| 307 | 1 | this->time.minute = dt.minute; | |
| 308 | 1 | this->time.second = dt.second; | |
| 309 | 1 | this->time.microsecond = dt.microsecond; | |
| 310 | 1 | } | |
| 311 | 2 | DateTime::DateTime(gate_time_t const& time) | |
| 312 | 2 | : gate_datetime_t() | |
| 313 | { | ||
| 314 | 2 | result_t result = gate_time_to_datetime(&time, this); | |
| 315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
| 316 | 2 | } | |
| 317 | 6 | DateTime::DateTime(gate_timestamp_t const& timestamp, bool addSystemBias) | |
| 318 | 6 | : gate_datetime_t() | |
| 319 | { | ||
| 320 | gate_time_t time; | ||
| 321 | 6 | time.timestamp = timestamp; | |
| 322 | 6 | time.bias = 0; | |
| 323 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | if (addSystemBias && (timestamp != 0)) |
| 324 | { | ||
| 325 | gate_time_t now; | ||
| 326 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
6 | if (GATE_SUCCEEDED(gate_time_now(&now))) |
| 327 | { | ||
| 328 | 6 | time.bias = now.bias; | |
| 329 | } | ||
| 330 | } | ||
| 331 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | result_t result = gate_time_to_datetime(&time, this); |
| 332 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6 | GATEXX_CHECK_ERROR(result); |
| 333 | 6 | } | |
| 334 | |||
| 335 | 1 | DateTime::DateTime(String const& text) | |
| 336 | 1 | : gate_datetime_t() | |
| 337 | { | ||
| 338 | gate_time_t tm; | ||
| 339 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | result_t result = gate_time_parse_string(text.c_str(), text.length(), &tm); |
| 340 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 341 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result = gate_time_to_datetime(&tm, this); |
| 342 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 343 | 1 | } | |
| 344 | |||
| 345 | 2 | bool_t DateTime::empty() const | |
| 346 | { | ||
| 347 | 2 | return this->toTime().timestamp == 0; | |
| 348 | } | ||
| 349 | |||
| 350 | |||
| 351 | 19 | Date DateTime::getDate() const | |
| 352 | { | ||
| 353 | 19 | return Date(this->date); | |
| 354 | } | ||
| 355 | 19 | DayTime DateTime::getDayTime() const | |
| 356 | { | ||
| 357 | 19 | return DayTime(this->time); | |
| 358 | } | ||
| 359 | |||
| 360 | |||
| 361 | 1 | DateTime DateTime::add(int64_t microseconds) const | |
| 362 | { | ||
| 363 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | return DateTime(this->toTime().add(microseconds)); |
| 364 | } | ||
| 365 | |||
| 366 | 2 | int64_t DateTime::diff(DateTime const& dt) const | |
| 367 | { | ||
| 368 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | return this->toTime().diff(dt.toTime()); |
| 369 | } | ||
| 370 | |||
| 371 | 9 | int DateTime::compare(DateTime const& that) const | |
| 372 | { | ||
| 373 | 9 | int result = this->getDate().compare(that.getDate()); | |
| 374 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (result != 0) return result; |
| 375 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | return this->getDayTime().compare(that.getDayTime()); |
| 376 | } | ||
| 377 | |||
| 378 | |||
| 379 | 1 | time::Microseconds DateTime::operator-(DateTime const& dt) const | |
| 380 | { | ||
| 381 | 1 | return time::Microseconds(this->diff(dt)); | |
| 382 | } | ||
| 383 | |||
| 384 | |||
| 385 | 10 | Time DateTime::toTime() const | |
| 386 | { | ||
| 387 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | Time ret; |
| 388 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | result_t result = gate_date_to_time(this, &ret); |
| 389 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
10 | GATEXX_CHECK_ERROR(result); |
| 390 | 10 | return ret; | |
| 391 | } | ||
| 392 | 2 | String DateTime::toString(String const& format) const | |
| 393 | { | ||
| 394 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | Time tm = this->toTime(); |
| 395 | char buffer[1024]; | ||
| 396 | 2 | size_t buffersz = sizeof(buffer); | |
| 397 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 | result_t result = gate_time_to_string(&tm, format.empty() ? NULL : format.c_str(), buffer, &buffersz); |
| 398 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_ERROR(result); |
| 399 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return String(buffer, buffersz); |
| 400 | } | ||
| 401 | 1 | bool DateTime::operator<(DateTime const& that) const { return this->compare(that) < 0; } | |
| 402 | 1 | bool DateTime::operator<=(DateTime const& that) const { return this->compare(that) <= 0; } | |
| 403 | 1 | bool DateTime::operator>(DateTime const& that) const { return this->compare(that) > 0; } | |
| 404 | 1 | bool DateTime::operator>=(DateTime const& that) const { return this->compare(that) >= 0; } | |
| 405 | 4 | bool DateTime::operator==(DateTime const& that) const { return this->compare(that) == 0; } | |
| 406 | 1 | bool DateTime::operator!=(DateTime const& that) const { return this->compare(that) != 0; } | |
| 407 | |||
| 408 | |||
| 409 | |||
| 410 | 7 | TimeCounter TimeCounter::now() | |
| 411 | { | ||
| 412 | 7 | TimeCounter tc; | |
| 413 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | result_t result = gate_timecounter_now(&tc.tc); |
| 414 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
7 | GATEXX_CHECK_ERROR(result); |
| 415 | 7 | return tc; | |
| 416 | } | ||
| 417 | |||
| 418 | 8 | TimeCounter::TimeCounter() noexcept | |
| 419 | 8 | : tc(0) | |
| 420 | { | ||
| 421 | 8 | } | |
| 422 | 3 | TimeCounter::TimeCounter(gate_timecounter_t src) noexcept | |
| 423 | 3 | : tc(src) | |
| 424 | { | ||
| 425 | 3 | } | |
| 426 | 3 | TimeCounter::TimeCounter(TimeCounter const& src) noexcept | |
| 427 | 3 | : tc(src.tc) | |
| 428 | { | ||
| 429 | 3 | } | |
| 430 | 1 | TimeCounter& TimeCounter::operator=(TimeCounter const& src) noexcept | |
| 431 | { | ||
| 432 | 1 | this->tc = src.tc; | |
| 433 | 1 | return *this; | |
| 434 | } | ||
| 435 | 14 | TimeCounter::~TimeCounter() noexcept | |
| 436 | { | ||
| 437 | 14 | } | |
| 438 | |||
| 439 | 3 | TimeCounter TimeCounter::add(int64_t microseconds) const noexcept | |
| 440 | { | ||
| 441 | 3 | return TimeCounter(gate_timecounter_add(this->tc, microseconds)); | |
| 442 | } | ||
| 443 | |||
| 444 | 18 | int64_t TimeCounter::diff(gate_timecounter_t other) const noexcept | |
| 445 | { | ||
| 446 | 18 | return gate_timecounter_diff(this->tc, other); | |
| 447 | } | ||
| 448 | 12 | int64_t TimeCounter::diff(TimeCounter const& other) const noexcept | |
| 449 | { | ||
| 450 | 12 | return this->diff(other.tc); | |
| 451 | } | ||
| 452 | |||
| 453 | 1 | void TimeCounter::swap(TimeCounter& other) noexcept | |
| 454 | { | ||
| 455 | 1 | gate_timecounter_t tmp = this->tc; | |
| 456 | 1 | this->tc = other.tc; | |
| 457 | 1 | other.tc = tmp; | |
| 458 | 1 | } | |
| 459 | |||
| 460 | 2 | bool_t TimeCounter::empty() const noexcept | |
| 461 | { | ||
| 462 | 2 | return this->tc == 0; | |
| 463 | } | ||
| 464 | |||
| 465 | 7 | gate_timecounter_t const* TimeCounter::c_impl() const noexcept | |
| 466 | { | ||
| 467 | 7 | return &this->tc; | |
| 468 | } | ||
| 469 | |||
| 470 | 1 | bool TimeCounter::operator!() const noexcept | |
| 471 | { | ||
| 472 | 1 | return this->empty(); | |
| 473 | } | ||
| 474 | |||
| 475 | |||
| 476 | 1 | time::Microseconds TimeCounter::operator-(TimeCounter const& that) const noexcept | |
| 477 | { | ||
| 478 | 1 | return time::Microseconds(this->diff(that)); | |
| 479 | } | ||
| 480 | |||
| 481 | 1 | bool TimeCounter::operator==(gate_timecounter_t that) const noexcept { return this->diff(that) == 0; }; | |
| 482 | 2 | bool TimeCounter::operator==(TimeCounter const& that) const noexcept { return this->diff(that) == 0; }; | |
| 483 | |||
| 484 | 1 | bool TimeCounter::operator!=(gate_timecounter_t that) const noexcept { return this->diff(that) != 0; }; | |
| 485 | 1 | bool TimeCounter::operator!=(TimeCounter const& that) const noexcept { return this->diff(that) != 0; }; | |
| 486 | |||
| 487 | 1 | bool TimeCounter::operator< (gate_timecounter_t that) const noexcept { return this->diff(that) < 0; }; | |
| 488 | 3 | bool TimeCounter::operator< (TimeCounter const& that) const noexcept { return this->diff(that) < 0; }; | |
| 489 | |||
| 490 | 1 | bool TimeCounter::operator> (gate_timecounter_t that) const noexcept { return this->diff(that) > 0; }; | |
| 491 | 1 | bool TimeCounter::operator> (TimeCounter const& that) const noexcept { return this->diff(that) > 0; }; | |
| 492 | |||
| 493 | 1 | bool TimeCounter::operator<=(gate_timecounter_t that) const noexcept { return this->diff(that) <= 0; }; | |
| 494 | 1 | bool TimeCounter::operator<=(TimeCounter const& that) const noexcept { return this->diff(that) <= 0; }; | |
| 495 | |||
| 496 | 1 | bool TimeCounter::operator>=(gate_timecounter_t that) const noexcept { return this->diff(that) >= 0; }; | |
| 497 | 1 | bool TimeCounter::operator>=(TimeCounter const& that) const noexcept { return this->diff(that) >= 0; }; | |
| 498 | |||
| 499 | |||
| 500 | |||
| 501 | } // end of namespace gate | ||
| 502 | |||
| 503 |