annotate dep/toml11/toml/datetime.hpp @ 353:2f094656e775

sys/x11/settings: misc fixups
author Paper <paper@paper.us.eu.org>
date Sun, 14 Jul 2024 23:27:43 -0400
parents 3b355fa948c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
318
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
1 // Copyright Toru Niina 2017.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
2 // Distributed under the MIT License.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
3 #ifndef TOML11_DATETIME_HPP
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
4 #define TOML11_DATETIME_HPP
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
5 #include <cstdint>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
6 #include <cstdlib>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
7 #include <ctime>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
8
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
9 #include <array>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10 #include <chrono>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
11 #include <iomanip>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
12 #include <ostream>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
13 #include <tuple>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15 namespace toml
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
16 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
17
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
18 // To avoid non-threadsafe std::localtime. In C11 (not C++11!), localtime_s is
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
19 // provided in the absolutely same purpose, but C++11 is actually not compatible
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
20 // with C11. We need to dispatch the function depending on the OS.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21 namespace detail
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 // TODO: find more sophisticated way to handle this
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24 #if defined(_MSC_VER)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25 inline std::tm localtime_s(const std::time_t* src)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27 std::tm dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 const auto result = ::localtime_s(&dst, src);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 if (result) { throw std::runtime_error("localtime_s failed."); }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30 return dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 inline std::tm gmtime_s(const std::time_t* src)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
33 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
34 std::tm dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35 const auto result = ::gmtime_s(&dst, src);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 if (result) { throw std::runtime_error("gmtime_s failed."); }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37 return dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39 #elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40 inline std::tm localtime_s(const std::time_t* src)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42 std::tm dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43 const auto result = ::localtime_r(src, &dst);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44 if (!result) { throw std::runtime_error("localtime_r failed."); }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
45 return dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
46 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
47 inline std::tm gmtime_s(const std::time_t* src)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49 std::tm dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50 const auto result = ::gmtime_r(src, &dst);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 if (!result) { throw std::runtime_error("gmtime_r failed."); }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
52 return dst;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 #else // fallback. not threadsafe
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
55 inline std::tm localtime_s(const std::time_t* src)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57 const auto result = std::localtime(src);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
58 if (!result) { throw std::runtime_error("localtime failed."); }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
59 return *result;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61 inline std::tm gmtime_s(const std::time_t* src)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63 const auto result = std::gmtime(src);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 if (!result) { throw std::runtime_error("gmtime failed."); }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
65 return *result;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 #endif
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 } // detail
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
70 enum class month_t : std::uint8_t
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
71 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
72 Jan = 0,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
73 Feb = 1,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
74 Mar = 2,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
75 Apr = 3,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
76 May = 4,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
77 Jun = 5,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
78 Jul = 6,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
79 Aug = 7,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
80 Sep = 8,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
81 Oct = 9,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
82 Nov = 10,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
83 Dec = 11
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
84 };
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
85
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
86 struct local_date
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
87 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
88 std::int16_t year{}; // A.D. (like, 2018)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
89 std::uint8_t month{}; // [0, 11]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
90 std::uint8_t day{}; // [1, 31]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
91
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
92 local_date(int y, month_t m, int d)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
93 : year (static_cast<std::int16_t>(y)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
94 month(static_cast<std::uint8_t>(m)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
95 day (static_cast<std::uint8_t>(d))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
96 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
97
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
98 explicit local_date(const std::tm& t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
99 : year (static_cast<std::int16_t>(t.tm_year + 1900)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
100 month(static_cast<std::uint8_t>(t.tm_mon)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
101 day (static_cast<std::uint8_t>(t.tm_mday))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
102 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
103
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
104 explicit local_date(const std::chrono::system_clock::time_point& tp)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
105 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
106 const auto t = std::chrono::system_clock::to_time_t(tp);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
107 const auto time = detail::localtime_s(&t);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
108 *this = local_date(time);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
109 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
110
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
111 explicit local_date(const std::time_t t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
112 : local_date(std::chrono::system_clock::from_time_t(t))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
113 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
114
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
115 operator std::chrono::system_clock::time_point() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
116 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
117 // std::mktime returns date as local time zone. no conversion needed
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
118 std::tm t;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
119 t.tm_sec = 0;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
120 t.tm_min = 0;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
121 t.tm_hour = 0;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
122 t.tm_mday = static_cast<int>(this->day);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
123 t.tm_mon = static_cast<int>(this->month);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
124 t.tm_year = static_cast<int>(this->year) - 1900;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
125 t.tm_wday = 0; // the value will be ignored
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
126 t.tm_yday = 0; // the value will be ignored
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
127 t.tm_isdst = -1;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
128 return std::chrono::system_clock::from_time_t(std::mktime(&t));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
129 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
130
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
131 operator std::time_t() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
132 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
133 return std::chrono::system_clock::to_time_t(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
134 std::chrono::system_clock::time_point(*this));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
135 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
136
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
137 local_date() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
138 ~local_date() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
139 local_date(local_date const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
140 local_date(local_date&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
141 local_date& operator=(local_date const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
142 local_date& operator=(local_date&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
143 };
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
144
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
145 inline bool operator==(const local_date& lhs, const local_date& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
146 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
147 return std::make_tuple(lhs.year, lhs.month, lhs.day) ==
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
148 std::make_tuple(rhs.year, rhs.month, rhs.day);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
149 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
150 inline bool operator!=(const local_date& lhs, const local_date& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
151 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
152 return !(lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
153 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
154 inline bool operator< (const local_date& lhs, const local_date& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
155 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
156 return std::make_tuple(lhs.year, lhs.month, lhs.day) <
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
157 std::make_tuple(rhs.year, rhs.month, rhs.day);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
158 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
159 inline bool operator<=(const local_date& lhs, const local_date& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
160 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
161 return (lhs < rhs) || (lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
162 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
163 inline bool operator> (const local_date& lhs, const local_date& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
164 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
165 return !(lhs <= rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
166 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
167 inline bool operator>=(const local_date& lhs, const local_date& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
168 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
169 return !(lhs < rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
170 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
171
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
172 template<typename charT, typename traits>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
173 std::basic_ostream<charT, traits>&
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
174 operator<<(std::basic_ostream<charT, traits>& os, const local_date& date)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
175 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
176 os << std::setfill('0') << std::setw(4) << static_cast<int>(date.year ) << '-';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
177 os << std::setfill('0') << std::setw(2) << static_cast<int>(date.month) + 1 << '-';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
178 os << std::setfill('0') << std::setw(2) << static_cast<int>(date.day ) ;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
179 return os;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
180 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
181
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
182 struct local_time
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
183 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
184 std::uint8_t hour{}; // [0, 23]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
185 std::uint8_t minute{}; // [0, 59]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
186 std::uint8_t second{}; // [0, 60]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
187 std::uint16_t millisecond{}; // [0, 999]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
188 std::uint16_t microsecond{}; // [0, 999]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
189 std::uint16_t nanosecond{}; // [0, 999]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
190
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
191 local_time(int h, int m, int s,
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
192 int ms = 0, int us = 0, int ns = 0)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
193 : hour (static_cast<std::uint8_t>(h)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
194 minute(static_cast<std::uint8_t>(m)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
195 second(static_cast<std::uint8_t>(s)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
196 millisecond(static_cast<std::uint16_t>(ms)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
197 microsecond(static_cast<std::uint16_t>(us)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
198 nanosecond (static_cast<std::uint16_t>(ns))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
199 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
200
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
201 explicit local_time(const std::tm& t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
202 : hour (static_cast<std::uint8_t>(t.tm_hour)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
203 minute(static_cast<std::uint8_t>(t.tm_min)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
204 second(static_cast<std::uint8_t>(t.tm_sec)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
205 millisecond(0), microsecond(0), nanosecond(0)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
206 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
207
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
208 template<typename Rep, typename Period>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
209 explicit local_time(const std::chrono::duration<Rep, Period>& t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
210 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
211 const auto h = std::chrono::duration_cast<std::chrono::hours>(t);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
212 this->hour = static_cast<std::uint8_t>(h.count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
213 const auto t2 = t - h;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
214 const auto m = std::chrono::duration_cast<std::chrono::minutes>(t2);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
215 this->minute = static_cast<std::uint8_t>(m.count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
216 const auto t3 = t2 - m;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
217 const auto s = std::chrono::duration_cast<std::chrono::seconds>(t3);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
218 this->second = static_cast<std::uint8_t>(s.count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
219 const auto t4 = t3 - s;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
220 const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(t4);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
221 this->millisecond = static_cast<std::uint16_t>(ms.count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
222 const auto t5 = t4 - ms;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
223 const auto us = std::chrono::duration_cast<std::chrono::microseconds>(t5);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
224 this->microsecond = static_cast<std::uint16_t>(us.count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
225 const auto t6 = t5 - us;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
226 const auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(t6);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
227 this->nanosecond = static_cast<std::uint16_t>(ns.count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
228 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
229
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
230 operator std::chrono::nanoseconds() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
231 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
232 return std::chrono::nanoseconds (this->nanosecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
233 std::chrono::microseconds(this->microsecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
234 std::chrono::milliseconds(this->millisecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
235 std::chrono::seconds(this->second) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
236 std::chrono::minutes(this->minute) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
237 std::chrono::hours(this->hour);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
238 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
239
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
240 local_time() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
241 ~local_time() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
242 local_time(local_time const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
243 local_time(local_time&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
244 local_time& operator=(local_time const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
245 local_time& operator=(local_time&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
246 };
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
247
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
248 inline bool operator==(const local_time& lhs, const local_time& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
249 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
250 return std::make_tuple(lhs.hour, lhs.minute, lhs.second, lhs.millisecond, lhs.microsecond, lhs.nanosecond) ==
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
251 std::make_tuple(rhs.hour, rhs.minute, rhs.second, rhs.millisecond, rhs.microsecond, rhs.nanosecond);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
252 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
253 inline bool operator!=(const local_time& lhs, const local_time& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
254 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
255 return !(lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
256 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
257 inline bool operator< (const local_time& lhs, const local_time& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
258 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
259 return std::make_tuple(lhs.hour, lhs.minute, lhs.second, lhs.millisecond, lhs.microsecond, lhs.nanosecond) <
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
260 std::make_tuple(rhs.hour, rhs.minute, rhs.second, rhs.millisecond, rhs.microsecond, rhs.nanosecond);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
261 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
262 inline bool operator<=(const local_time& lhs, const local_time& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
263 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
264 return (lhs < rhs) || (lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
265 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
266 inline bool operator> (const local_time& lhs, const local_time& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
267 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
268 return !(lhs <= rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
269 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
270 inline bool operator>=(const local_time& lhs, const local_time& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
271 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
272 return !(lhs < rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
273 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
274
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
275 template<typename charT, typename traits>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
276 std::basic_ostream<charT, traits>&
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
277 operator<<(std::basic_ostream<charT, traits>& os, const local_time& time)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
278 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
279 os << std::setfill('0') << std::setw(2) << static_cast<int>(time.hour ) << ':';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
280 os << std::setfill('0') << std::setw(2) << static_cast<int>(time.minute) << ':';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
281 os << std::setfill('0') << std::setw(2) << static_cast<int>(time.second);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
282 if(time.millisecond != 0 || time.microsecond != 0 || time.nanosecond != 0)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
283 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
284 os << '.';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
285 os << std::setfill('0') << std::setw(3) << static_cast<int>(time.millisecond);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
286 if(time.microsecond != 0 || time.nanosecond != 0)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
287 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
288 os << std::setfill('0') << std::setw(3) << static_cast<int>(time.microsecond);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
289 if(time.nanosecond != 0)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
290 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
291 os << std::setfill('0') << std::setw(3) << static_cast<int>(time.nanosecond);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
292 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
293 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
294 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
295 return os;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
296 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
297
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
298 struct time_offset
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
299 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
300 std::int8_t hour{}; // [-12, 12]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
301 std::int8_t minute{}; // [-59, 59]
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
302
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
303 time_offset(int h, int m)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
304 : hour (static_cast<std::int8_t>(h)),
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
305 minute(static_cast<std::int8_t>(m))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
306 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
307
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
308 operator std::chrono::minutes() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
309 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
310 return std::chrono::minutes(this->minute) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
311 std::chrono::hours(this->hour);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
312 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
313
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
314 time_offset() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
315 ~time_offset() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
316 time_offset(time_offset const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
317 time_offset(time_offset&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
318 time_offset& operator=(time_offset const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
319 time_offset& operator=(time_offset&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
320 };
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
321
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
322 inline bool operator==(const time_offset& lhs, const time_offset& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
323 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
324 return std::make_tuple(lhs.hour, lhs.minute) ==
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
325 std::make_tuple(rhs.hour, rhs.minute);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
326 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
327 inline bool operator!=(const time_offset& lhs, const time_offset& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
328 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
329 return !(lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
330 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
331 inline bool operator< (const time_offset& lhs, const time_offset& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
332 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
333 return std::make_tuple(lhs.hour, lhs.minute) <
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
334 std::make_tuple(rhs.hour, rhs.minute);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
335 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
336 inline bool operator<=(const time_offset& lhs, const time_offset& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
337 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
338 return (lhs < rhs) || (lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
339 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
340 inline bool operator> (const time_offset& lhs, const time_offset& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
341 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
342 return !(lhs <= rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
343 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
344 inline bool operator>=(const time_offset& lhs, const time_offset& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
345 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
346 return !(lhs < rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
347 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
348
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
349 template<typename charT, typename traits>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
350 std::basic_ostream<charT, traits>&
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
351 operator<<(std::basic_ostream<charT, traits>& os, const time_offset& offset)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
352 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
353 if(offset.hour == 0 && offset.minute == 0)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
354 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
355 os << 'Z';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
356 return os;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
357 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
358 int minute = static_cast<int>(offset.hour) * 60 + offset.minute;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
359 if(minute < 0){os << '-'; minute = std::abs(minute);} else {os << '+';}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
360 os << std::setfill('0') << std::setw(2) << minute / 60 << ':';
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
361 os << std::setfill('0') << std::setw(2) << minute % 60;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
362 return os;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
363 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
364
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
365 struct local_datetime
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
366 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
367 local_date date{};
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
368 local_time time{};
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
369
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
370 local_datetime(local_date d, local_time t): date(d), time(t) {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
371
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
372 explicit local_datetime(const std::tm& t): date(t), time(t){}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
373
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
374 explicit local_datetime(const std::chrono::system_clock::time_point& tp)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
375 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
376 const auto t = std::chrono::system_clock::to_time_t(tp);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
377 std::tm ltime = detail::localtime_s(&t);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
378
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
379 this->date = local_date(ltime);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
380 this->time = local_time(ltime);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
381
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
382 // std::tm lacks subsecond information, so diff between tp and tm
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
383 // can be used to get millisecond & microsecond information.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
384 const auto t_diff = tp -
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
385 std::chrono::system_clock::from_time_t(std::mktime(&ltime));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
386 this->time.millisecond = static_cast<std::uint16_t>(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
387 std::chrono::duration_cast<std::chrono::milliseconds>(t_diff).count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
388 this->time.microsecond = static_cast<std::uint16_t>(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
389 std::chrono::duration_cast<std::chrono::microseconds>(t_diff).count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
390 this->time.nanosecond = static_cast<std::uint16_t>(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
391 std::chrono::duration_cast<std::chrono::nanoseconds >(t_diff).count());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
392 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
393
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
394 explicit local_datetime(const std::time_t t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
395 : local_datetime(std::chrono::system_clock::from_time_t(t))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
396 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
397
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
398 operator std::chrono::system_clock::time_point() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
399 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
400 using internal_duration =
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
401 typename std::chrono::system_clock::time_point::duration;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
402
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
403 // Normally DST begins at A.M. 3 or 4. If we re-use conversion operator
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
404 // of local_date and local_time independently, the conversion fails if
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
405 // it is the day when DST begins or ends. Since local_date considers the
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
406 // time is 00:00 A.M. and local_time does not consider DST because it
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
407 // does not have any date information. We need to consider both date and
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
408 // time information at the same time to convert it correctly.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
409
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
410 std::tm t;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
411 t.tm_sec = static_cast<int>(this->time.second);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
412 t.tm_min = static_cast<int>(this->time.minute);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
413 t.tm_hour = static_cast<int>(this->time.hour);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
414 t.tm_mday = static_cast<int>(this->date.day);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
415 t.tm_mon = static_cast<int>(this->date.month);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
416 t.tm_year = static_cast<int>(this->date.year) - 1900;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
417 t.tm_wday = 0; // the value will be ignored
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
418 t.tm_yday = 0; // the value will be ignored
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
419 t.tm_isdst = -1;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
420
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
421 // std::mktime returns date as local time zone. no conversion needed
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
422 auto dt = std::chrono::system_clock::from_time_t(std::mktime(&t));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
423 dt += std::chrono::duration_cast<internal_duration>(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
424 std::chrono::milliseconds(this->time.millisecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
425 std::chrono::microseconds(this->time.microsecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
426 std::chrono::nanoseconds (this->time.nanosecond));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
427 return dt;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
428 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
429
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
430 operator std::time_t() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
431 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
432 return std::chrono::system_clock::to_time_t(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
433 std::chrono::system_clock::time_point(*this));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
434 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
435
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
436 local_datetime() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
437 ~local_datetime() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
438 local_datetime(local_datetime const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
439 local_datetime(local_datetime&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
440 local_datetime& operator=(local_datetime const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
441 local_datetime& operator=(local_datetime&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
442 };
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
443
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
444 inline bool operator==(const local_datetime& lhs, const local_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
445 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
446 return std::make_tuple(lhs.date, lhs.time) ==
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
447 std::make_tuple(rhs.date, rhs.time);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
448 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
449 inline bool operator!=(const local_datetime& lhs, const local_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
450 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
451 return !(lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
452 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
453 inline bool operator< (const local_datetime& lhs, const local_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
454 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
455 return std::make_tuple(lhs.date, lhs.time) <
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
456 std::make_tuple(rhs.date, rhs.time);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
457 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
458 inline bool operator<=(const local_datetime& lhs, const local_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
459 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
460 return (lhs < rhs) || (lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
461 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
462 inline bool operator> (const local_datetime& lhs, const local_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
463 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
464 return !(lhs <= rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
465 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
466 inline bool operator>=(const local_datetime& lhs, const local_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
467 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
468 return !(lhs < rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
469 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
470
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
471 template<typename charT, typename traits>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
472 std::basic_ostream<charT, traits>&
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
473 operator<<(std::basic_ostream<charT, traits>& os, const local_datetime& dt)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
474 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
475 os << dt.date << 'T' << dt.time;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
476 return os;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
477 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
478
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
479 struct offset_datetime
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
480 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
481 local_date date{};
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
482 local_time time{};
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
483 time_offset offset{};
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
484
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
485 offset_datetime(local_date d, local_time t, time_offset o)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
486 : date(d), time(t), offset(o)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
487 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
488 offset_datetime(const local_datetime& dt, time_offset o)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
489 : date(dt.date), time(dt.time), offset(o)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
490 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
491 explicit offset_datetime(const local_datetime& ld)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
492 : date(ld.date), time(ld.time), offset(get_local_offset(nullptr))
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
493 // use the current local timezone offset
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
494 {}
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
495 explicit offset_datetime(const std::chrono::system_clock::time_point& tp)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
496 : offset(0, 0) // use gmtime
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
497 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
498 const auto timet = std::chrono::system_clock::to_time_t(tp);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
499 const auto tm = detail::gmtime_s(&timet);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
500 this->date = local_date(tm);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
501 this->time = local_time(tm);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
502 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
503 explicit offset_datetime(const std::time_t& t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
504 : offset(0, 0) // use gmtime
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
505 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
506 const auto tm = detail::gmtime_s(&t);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
507 this->date = local_date(tm);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
508 this->time = local_time(tm);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
509 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
510 explicit offset_datetime(const std::tm& t)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
511 : offset(0, 0) // assume gmtime
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
512 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
513 this->date = local_date(t);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
514 this->time = local_time(t);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
515 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
516
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
517 operator std::chrono::system_clock::time_point() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
518 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
519 // get date-time
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
520 using internal_duration =
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
521 typename std::chrono::system_clock::time_point::duration;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
522
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
523 // first, convert it to local date-time information in the same way as
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
524 // local_datetime does. later we will use time_t to adjust time offset.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
525 std::tm t;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
526 t.tm_sec = static_cast<int>(this->time.second);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
527 t.tm_min = static_cast<int>(this->time.minute);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
528 t.tm_hour = static_cast<int>(this->time.hour);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
529 t.tm_mday = static_cast<int>(this->date.day);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
530 t.tm_mon = static_cast<int>(this->date.month);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
531 t.tm_year = static_cast<int>(this->date.year) - 1900;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
532 t.tm_wday = 0; // the value will be ignored
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
533 t.tm_yday = 0; // the value will be ignored
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
534 t.tm_isdst = -1;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
535 const std::time_t tp_loc = std::mktime(std::addressof(t));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
536
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
537 auto tp = std::chrono::system_clock::from_time_t(tp_loc);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
538 tp += std::chrono::duration_cast<internal_duration>(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
539 std::chrono::milliseconds(this->time.millisecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
540 std::chrono::microseconds(this->time.microsecond) +
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
541 std::chrono::nanoseconds (this->time.nanosecond));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
542
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
543 // Since mktime uses local time zone, it should be corrected.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
544 // `12:00:00+09:00` means `03:00:00Z`. So mktime returns `03:00:00Z` if
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
545 // we are in `+09:00` timezone. To represent `12:00:00Z` there, we need
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
546 // to add `+09:00` to `03:00:00Z`.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
547 // Here, it uses the time_t converted from date-time info to handle
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
548 // daylight saving time.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
549 const auto ofs = get_local_offset(std::addressof(tp_loc));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
550 tp += std::chrono::hours (ofs.hour);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
551 tp += std::chrono::minutes(ofs.minute);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
552
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
553 // We got `12:00:00Z` by correcting local timezone applied by mktime.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
554 // Then we will apply the offset. Let's say `12:00:00-08:00` is given.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
555 // And now, we have `12:00:00Z`. `12:00:00-08:00` means `20:00:00Z`.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
556 // So we need to subtract the offset.
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
557 tp -= std::chrono::minutes(this->offset);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
558 return tp;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
559 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
560
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
561 operator std::time_t() const
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
562 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
563 return std::chrono::system_clock::to_time_t(
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
564 std::chrono::system_clock::time_point(*this));
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
565 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
566
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
567 offset_datetime() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
568 ~offset_datetime() = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
569 offset_datetime(offset_datetime const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
570 offset_datetime(offset_datetime&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
571 offset_datetime& operator=(offset_datetime const&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
572 offset_datetime& operator=(offset_datetime&&) = default;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
573
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
574 private:
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
575
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
576 static time_offset get_local_offset(const std::time_t* tp)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
577 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
578 // get local timezone with the same date-time information as mktime
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
579 const auto t = detail::localtime_s(tp);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
580
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
581 std::array<char, 6> buf;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
582 const auto result = std::strftime(buf.data(), 6, "%z", &t); // +hhmm\0
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
583 if(result != 5)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
584 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
585 throw std::runtime_error("toml::offset_datetime: cannot obtain "
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
586 "timezone information of current env");
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
587 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
588 const int ofs = std::atoi(buf.data());
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
589 const int ofs_h = ofs / 100;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
590 const int ofs_m = ofs - (ofs_h * 100);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
591 return time_offset(ofs_h, ofs_m);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
592 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
593 };
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
594
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
595 inline bool operator==(const offset_datetime& lhs, const offset_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
596 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
597 return std::make_tuple(lhs.date, lhs.time, lhs.offset) ==
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
598 std::make_tuple(rhs.date, rhs.time, rhs.offset);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
599 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
600 inline bool operator!=(const offset_datetime& lhs, const offset_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
601 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
602 return !(lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
603 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
604 inline bool operator< (const offset_datetime& lhs, const offset_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
605 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
606 return std::make_tuple(lhs.date, lhs.time, lhs.offset) <
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
607 std::make_tuple(rhs.date, rhs.time, rhs.offset);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
608 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
609 inline bool operator<=(const offset_datetime& lhs, const offset_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
610 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
611 return (lhs < rhs) || (lhs == rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
612 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
613 inline bool operator> (const offset_datetime& lhs, const offset_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
614 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
615 return !(lhs <= rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
616 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
617 inline bool operator>=(const offset_datetime& lhs, const offset_datetime& rhs)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
618 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
619 return !(lhs < rhs);
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
620 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
621
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
622 template<typename charT, typename traits>
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
623 std::basic_ostream<charT, traits>&
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
624 operator<<(std::basic_ostream<charT, traits>& os, const offset_datetime& dt)
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
625 {
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
626 os << dt.date << 'T' << dt.time << dt.offset;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
627 return os;
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
628 }
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
629
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
630 }//toml
3b355fa948c7 config: use TOML instead of INI
Paper <paper@paper.us.eu.org>
parents:
diff changeset
631 #endif// TOML11_DATETIME