Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
date_time.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
8#include "header_start.hpp"
9#include "print_to_stream.hpp"
10
13 struct TOML_TRIVIAL_ABI date {
15 uint16_t year;
16
18 uint8_t month;
19
21 uint8_t day;
22
25 date() noexcept = default;
26
28 TOML_CONSTRAINED_TEMPLATE((impl::all_integral<Y, M, D>), typename Y, typename M, typename D)
30 constexpr date(Y y, M m, D d) noexcept //
31 : year{static_cast<uint16_t>(y)},
32 month{static_cast<uint8_t>(m)},
33 day{static_cast<uint8_t>(d)} {}
34
37 friend constexpr bool operator==(const date& lhs, const date& rhs) noexcept {
38 return lhs.year == rhs.year //
39 && lhs.month == rhs.month //
40 && lhs.day == rhs.day;
41 }
42
45 friend constexpr bool operator!=(const date& lhs, const date& rhs) noexcept {
46 return !(lhs == rhs);
47 }
48
49 private:
51
53 static constexpr uint32_t pack(const date& d) noexcept {
54 return (static_cast<uint32_t>(d.year) << 16) | (static_cast<uint32_t>(d.month) << 8) |
55 static_cast<uint32_t>(d.day);
56 }
57
59
60 public:
63 friend constexpr bool operator<(const date& lhs, const date& rhs) noexcept {
64 return pack(lhs) < pack(rhs);
65 }
66
69 friend constexpr bool operator<=(const date& lhs, const date& rhs) noexcept {
70 return pack(lhs) <= pack(rhs);
71 }
72
75 friend constexpr bool operator>(const date& lhs, const date& rhs) noexcept {
76 return pack(lhs) > pack(rhs);
77 }
78
81 friend constexpr bool operator>=(const date& lhs, const date& rhs) noexcept {
82 return pack(lhs) >= pack(rhs);
83 }
84
94 friend std::ostream& operator<<(std::ostream& lhs, const date& rhs) {
95 impl::print_to_stream(lhs, rhs);
96 return lhs;
97 }
98 };
99
103 uint8_t hour;
104
106 uint8_t minute;
107
109 uint8_t second;
110
112 uint32_t nanosecond;
113
116 time() noexcept = default;
117
119 TOML_CONSTRAINED_TEMPLATE((impl::all_integral<H, M, S, NS>), typename H, typename M,
120 typename S = uint8_t, typename NS = uint32_t)
122 constexpr time(H h, M m, S s = S{}, NS ns = NS{}) noexcept //
123 : hour{static_cast<uint8_t>(h)},
124 minute{static_cast<uint8_t>(m)},
125 second{static_cast<uint8_t>(s)},
126 nanosecond{static_cast<uint32_t>(ns)} {}
127
130 friend constexpr bool operator==(const time& lhs, const time& rhs) noexcept {
131 return lhs.hour == rhs.hour //
132 && lhs.minute == rhs.minute //
133 && lhs.second == rhs.second //
134 && lhs.nanosecond == rhs.nanosecond;
135 }
136
139 friend constexpr bool operator!=(const time& lhs, const time& rhs) noexcept {
140 return !(lhs == rhs);
141 }
142
143 private:
145
147 static constexpr uint64_t pack(const time& t) noexcept {
148 return static_cast<uint64_t>(t.hour) << 48 | static_cast<uint64_t>(t.minute) << 40 |
149 static_cast<uint64_t>(t.second) << 32 | static_cast<uint64_t>(t.nanosecond);
150 }
151
153
154 public:
157 friend constexpr bool operator<(const time& lhs, const time& rhs) noexcept {
158 return pack(lhs) < pack(rhs);
159 }
160
163 friend constexpr bool operator<=(const time& lhs, const time& rhs) noexcept {
164 return pack(lhs) <= pack(rhs);
165 }
166
169 friend constexpr bool operator>(const time& lhs, const time& rhs) noexcept {
170 return pack(lhs) > pack(rhs);
171 }
172
175 friend constexpr bool operator>=(const time& lhs, const time& rhs) noexcept {
176 return pack(lhs) >= pack(rhs);
177 }
178
189 friend std::ostream& operator<<(std::ostream& lhs, const time& rhs) {
190 impl::print_to_stream(lhs, rhs);
191 return lhs;
192 }
193 };
194
198 int16_t minutes;
199
202 time_offset() noexcept = default;
203
225 TOML_CONSTRAINED_TEMPLATE((impl::all_integral<H, M>), typename H, typename M)
227 constexpr time_offset(H h, M m) noexcept //
228 : minutes{static_cast<int16_t>(static_cast<impl::common_signed_type<H, M>>(h) *
229 impl::common_signed_type<H, M>{60} +
230 static_cast<impl::common_signed_type<H, M>>(m))} {}
231
234 friend constexpr bool operator==(time_offset lhs, time_offset rhs) noexcept {
235 return lhs.minutes == rhs.minutes;
236 }
237
240 friend constexpr bool operator!=(time_offset lhs, time_offset rhs) noexcept {
241 return lhs.minutes != rhs.minutes;
242 }
243
246 friend constexpr bool operator<(time_offset lhs, time_offset rhs) noexcept {
247 return lhs.minutes < rhs.minutes;
248 }
249
252 friend constexpr bool operator<=(time_offset lhs, time_offset rhs) noexcept {
253 return lhs.minutes <= rhs.minutes;
254 }
255
258 friend constexpr bool operator>(time_offset lhs, time_offset rhs) noexcept {
259 return lhs.minutes > rhs.minutes;
260 }
261
264 friend constexpr bool operator>=(time_offset lhs, time_offset rhs) noexcept {
265 return lhs.minutes >= rhs.minutes;
266 }
267
284 friend std::ostream& operator<<(std::ostream& lhs, const time_offset& rhs) {
285 impl::print_to_stream(lhs, rhs);
286 return lhs;
287 }
288 };
289
290#ifdef __linux__
291#define TOML_STD std::
292#else
293#define TOML_STD
294#endif
295
297
299 struct date_time {
301 toml::date date;
302
304 toml::time time;
305
309 TOML_STD optional<toml::time_offset> offset;
310
313 date_time() noexcept = default;
314
320 constexpr date_time(const toml::date& d, const toml::time& t) noexcept //
321 : date{d},
322 time{t},
323 offset{} // TINAE - icc bugfix
324 {}
325
330 explicit constexpr date_time(const toml::date& d) noexcept //
331 : date{d},
332 time{},
333 offset{} // TINAE - icc bugfix
334 {}
335
340 explicit constexpr date_time(const toml::time& t) noexcept //
341 : date{},
342 time{t},
343 offset{} // TINAE - icc bugfix
344 {}
345
352 constexpr date_time(const toml::date& d, const toml::time& t,
353 const toml::time_offset& off) noexcept
354 : date{d}, time{t}, offset{off} {}
355
358 constexpr bool is_local() const noexcept { return !offset.has_value(); }
359
362 friend constexpr bool operator==(const date_time& lhs, const date_time& rhs) noexcept {
363 return lhs.date == rhs.date //
364 && lhs.time == rhs.time //
365 && lhs.offset == rhs.offset;
366 }
367
370 friend constexpr bool operator!=(const date_time& lhs, const date_time& rhs) noexcept {
371 return !(lhs == rhs);
372 }
373
376 friend constexpr bool operator<(const date_time& lhs, const date_time& rhs) noexcept {
377 if (lhs.date != rhs.date) return lhs.date < rhs.date;
378 if (lhs.time != rhs.time) return lhs.time < rhs.time;
379 return lhs.offset < rhs.offset;
380 }
381
384 friend constexpr bool operator<=(const date_time& lhs, const date_time& rhs) noexcept {
385 if (lhs.date != rhs.date) return lhs.date < rhs.date;
386 if (lhs.time != rhs.time) return lhs.time < rhs.time;
387 return lhs.offset <= rhs.offset;
388 }
389
392 friend constexpr bool operator>(const date_time& lhs, const date_time& rhs) noexcept {
393 return !(lhs <= rhs);
394 }
395
398 friend constexpr bool operator>=(const date_time& lhs, const date_time& rhs) noexcept {
399 return !(lhs < rhs);
400 }
401
414 friend std::ostream& operator<<(std::ostream& lhs, const date_time& rhs) {
415 impl::print_to_stream(lhs, rhs);
416 return lhs;
417 }
418 };
419
420 TOML_ABI_NAMESPACE_END; // TOML_HAS_CUSTOM_OPTIONAL_TYPE
421}
423
424#include "header_end.hpp"
#define m
Definition 17.names.cpp:129
#define y
Definition 17.names.cpp:141
#define rhs
Definition 17.names.cpp:536
#define t
Definition 17.names.cpp:136
#define d
Definition 17.names.cpp:115
#define M
Definition 17.names.cpp:156
#define lhs
Definition 17.names.cpp:489
#define off
Definition 17.names.cpp:507
#define s
TOML_NAMESPACE_START
Definition date_time.hpp:11
TOML_ABI_NAMESPACE_END
#define TOML_STD
TOML_NAMESPACE_END
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.
bool operator>(const DistancePair &lhs, const DistancePair &rhs)
Definition graph.cpp:47
#define TOML_HAS_CUSTOM_OPTIONAL_TYPE
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14787
The root namespace for all toml++ functions and types.
#define TOML_NODISCARD_CTOR
#define TOML_TRIVIAL_ABI
#define TOML_ABI_NAMESPACE_BOOL(cond, T, F)
#define TOML_CONSTRAINED_TEMPLATE(condition,...)
#define TOML_PURE_GETTER
#define TOML_PURE_INLINE_GETTER
A date-time.
TOML_NODISCARD_CTOR constexpr date_time(const toml::date &d) noexcept
Constructs a local date-time.
toml::date date
The date component.
TOML_PURE_INLINE_GETTER friend constexpr bool operator>(const date_time &lhs, const date_time &rhs) noexcept
Greater-than operator.
TOML_PURE_INLINE_GETTER friend constexpr bool operator!=(const date_time &lhs, const date_time &rhs) noexcept
Inequality operator.
TOML_PURE_GETTER friend constexpr bool operator==(const date_time &lhs, const date_time &rhs) noexcept
Equality operator.
toml::time time
The time component.
TOML_STD optional< toml::time_offset > offset
The timezone offset component.
TOML_PURE_GETTER friend constexpr bool operator<(const date_time &lhs, const date_time &rhs) noexcept
Less-than operator.
TOML_PURE_GETTER friend constexpr bool operator<=(const date_time &lhs, const date_time &rhs) noexcept
Less-than-or-equal-to operator.
TOML_NODISCARD_CTOR date_time() noexcept=default
Default constructor. Does not initialize the members.
TOML_PURE_INLINE_GETTER constexpr bool is_local() const noexcept
Returns true if this date_time does not contain timezone offset information.
TOML_PURE_INLINE_GETTER friend constexpr bool operator>=(const date_time &lhs, const date_time &rhs) noexcept
Greater-than-or-equal-to operator.
friend std::ostream & operator<<(std::ostream &lhs, const date_time &rhs)
Prints a date_time out to a stream in RFC 3339 format. \detail \cpp std::cout << toml::date_time{ { 1...
TOML_NODISCARD_CTOR constexpr date_time(const toml::date &d, const toml::time &t, const toml::time_offset &off) noexcept
Constructs an offset date-time.
TOML_NODISCARD_CTOR constexpr date_time(const toml::time &t) noexcept
Constructs a local date-time.
A timezone offset.
TOML_PURE_INLINE_GETTER friend constexpr bool operator<=(time_offset lhs, time_offset rhs) noexcept
Less-than-or-equal-to operator.
friend std::ostream & operator<<(std::ostream &lhs, const time_offset &rhs)
Prints a time_offset out to a stream as +-HH:MM or Z (per RFC 3339). \detail \cpp std::cout << toml::...
TOML_PURE_INLINE_GETTER friend constexpr bool operator>(time_offset lhs, time_offset rhs) noexcept
Greater-than operator.
TOML_PURE_INLINE_GETTER friend constexpr bool operator<(time_offset lhs, time_offset rhs) noexcept
Less-than operator.
TOML_PURE_INLINE_GETTER friend constexpr bool operator>=(time_offset lhs, time_offset rhs) noexcept
Greater-than-or-equal-to operator.
int16_t minutes
Offset from UTC+0, in minutes.
TOML_PURE_INLINE_GETTER friend constexpr bool operator==(time_offset lhs, time_offset rhs) noexcept
Equality operator.
TOML_PURE_INLINE_GETTER friend constexpr bool operator!=(time_offset lhs, time_offset rhs) noexcept
Inequality operator.
TOML_NODISCARD_CTOR time_offset() noexcept=default
Default constructor. Does not initialize the members.
A local time-of-day.
uint8_t minute
The minute component, from 0 - 59.
uint32_t nanosecond
The fractional nanoseconds component, from 0 - 999999999.
uint8_t hour
The hour component, from 0 - 23.
uint8_t second
The second component, from 0 - 59.
TOML_NODISCARD_CTOR time() noexcept=default
Default constructor. Does not initialize the members.