diff options
Diffstat (limited to 'server/src/time.cppm')
| -rw-r--r-- | server/src/time.cppm | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/server/src/time.cppm b/server/src/time.cppm index 32df737..61f399b 100644 --- a/server/src/time.cppm +++ b/server/src/time.cppm | |||
| @@ -4,12 +4,12 @@ import std; | |||
| 4 | 4 | ||
| 5 | export namespace routemon::time { | 5 | export namespace routemon::time { |
| 6 | 6 | ||
| 7 | template <class Duration = std::chrono::utc_clock::duration> | 7 | template <typename Duration = std::chrono::utc_clock::duration> |
| 8 | using timestamp = std::chrono::time_point<std::chrono::utc_clock, Duration>; | 8 | using timestamp = std::chrono::time_point<std::chrono::utc_clock, Duration>; |
| 9 | 9 | ||
| 10 | auto iso8601_secs(timestamp<std::chrono::seconds> ts) -> std::string; | 10 | auto iso8601_secs(timestamp<std::chrono::seconds> ts) -> std::string; |
| 11 | 11 | ||
| 12 | template <class Duration> | 12 | template <typename Duration> |
| 13 | class period | 13 | class period |
| 14 | { | 14 | { |
| 15 | // Assuming [start, end). Unfortunately the DATEX II model is not | 15 | // Assuming [start, end). Unfortunately the DATEX II model is not |
| @@ -27,7 +27,7 @@ public: | |||
| 27 | [[nodiscard]] auto end() const -> timestamp<Duration>; | 27 | [[nodiscard]] auto end() const -> timestamp<Duration>; |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | template <class Duration> | 30 | template <typename Duration> |
| 31 | class period_seq | 31 | class period_seq |
| 32 | { | 32 | { |
| 33 | std::vector<period<Duration>> periods_; | 33 | std::vector<period<Duration>> periods_; |
| @@ -110,10 +110,10 @@ public: | |||
| 110 | [[nodiscard]] auto periods() const -> std::vector<period<Duration>> const&; | 110 | [[nodiscard]] auto periods() const -> std::vector<period<Duration>> const&; |
| 111 | }; | 111 | }; |
| 112 | 112 | ||
| 113 | template <class Duration> | 113 | template <typename Duration> |
| 114 | auto operator<<(std::ostream& os, period<Duration> const& p) -> std::ostream&; | 114 | auto operator<<(std::ostream& os, period<Duration> const& p) -> std::ostream&; |
| 115 | 115 | ||
| 116 | template <class Duration> | 116 | template <typename Duration> |
| 117 | auto operator<<(std::ostream& os, period_seq<Duration> const& ps) | 117 | auto operator<<(std::ostream& os, period_seq<Duration> const& ps) |
| 118 | -> std::ostream&; | 118 | -> std::ostream&; |
| 119 | 119 | ||
| @@ -121,7 +121,7 @@ auto operator<<(std::ostream& os, period_seq<Duration> const& ps) | |||
| 121 | 121 | ||
| 122 | namespace routemon::time { | 122 | namespace routemon::time { |
| 123 | 123 | ||
| 124 | template <class Duration> | 124 | template <typename Duration> |
| 125 | period<Duration>::period(timestamp<Duration> start, timestamp<Duration> end) | 125 | period<Duration>::period(timestamp<Duration> start, timestamp<Duration> end) |
| 126 | : start_{start}, end_{end} | 126 | : start_{start}, end_{end} |
| 127 | { | 127 | { |
| @@ -131,7 +131,7 @@ period<Duration>::period(timestamp<Duration> start, timestamp<Duration> end) | |||
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | template <class Duration> | 134 | template <typename Duration> |
| 135 | auto period<Duration>::intersect(period other) const -> std::optional<period> | 135 | auto period<Duration>::intersect(period other) const -> std::optional<period> |
| 136 | { | 136 | { |
| 137 | auto const new_start = start_ < other.start() ? other.start() : start_; | 137 | auto const new_start = start_ < other.start() ? other.start() : start_; |
| @@ -140,7 +140,7 @@ auto period<Duration>::intersect(period other) const -> std::optional<period> | |||
| 140 | : std::nullopt; | 140 | : std::nullopt; |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | template <class Duration> | 143 | template <typename Duration> |
| 144 | auto period<Duration>::except(period other) const | 144 | auto period<Duration>::except(period other) const |
| 145 | -> std::pair<std::optional<period>, std::optional<period>> | 145 | -> std::pair<std::optional<period>, std::optional<period>> |
| 146 | { | 146 | { |
| @@ -156,19 +156,19 @@ auto period<Duration>::except(period other) const | |||
| 156 | return std::make_pair(before, after); | 156 | return std::make_pair(before, after); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | template <class Duration> | 159 | template <typename Duration> |
| 160 | auto period<Duration>::start() const -> timestamp<Duration> | 160 | auto period<Duration>::start() const -> timestamp<Duration> |
| 161 | { | 161 | { |
| 162 | return start_; | 162 | return start_; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | template <class Duration> | 165 | template <typename Duration> |
| 166 | auto period<Duration>::end() const -> timestamp<Duration> | 166 | auto period<Duration>::end() const -> timestamp<Duration> |
| 167 | { | 167 | { |
| 168 | return end_; | 168 | return end_; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | template <class Duration> | 171 | template <typename Duration> |
| 172 | period_seq<Duration>::period_seq(std::vector<period<Duration>> periods) | 172 | period_seq<Duration>::period_seq(std::vector<period<Duration>> periods) |
| 173 | : periods_{std::move(periods)} | 173 | : periods_{std::move(periods)} |
| 174 | { | 174 | { |
| @@ -185,13 +185,13 @@ period_seq<Duration>::period_seq(std::vector<period<Duration>> periods) | |||
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | template <class Duration> | 188 | template <typename Duration> |
| 189 | period_seq<Duration>::period_seq(period<Duration> singleton) | 189 | period_seq<Duration>::period_seq(period<Duration> singleton) |
| 190 | : periods_{singleton} | 190 | : periods_{singleton} |
| 191 | { | 191 | { |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | template <class Duration> | 194 | template <typename Duration> |
| 195 | auto period_seq<Duration>::intersect(period_seq const& other) const | 195 | auto period_seq<Duration>::intersect(period_seq const& other) const |
| 196 | -> period_seq | 196 | -> period_seq |
| 197 | { | 197 | { |
| @@ -232,7 +232,7 @@ auto period_seq<Duration>::intersect(period_seq const& other) const | |||
| 232 | return period_seq{res}; | 232 | return period_seq{res}; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | template <class Duration> | 235 | template <typename Duration> |
| 236 | auto period_seq<Duration>::except(period_seq const& other) const -> period_seq | 236 | auto period_seq<Duration>::except(period_seq const& other) const -> period_seq |
| 237 | { | 237 | { |
| 238 | // This code was pretty tricky to write, I wouldn't be surprised if it | 238 | // This code was pretty tricky to write, I wouldn't be surprised if it |
| @@ -281,20 +281,20 @@ auto period_seq<Duration>::except(period_seq const& other) const -> period_seq | |||
| 281 | return period_seq{res}; | 281 | return period_seq{res}; |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | template <class Duration> | 284 | template <typename Duration> |
| 285 | auto period_seq<Duration>::periods() const | 285 | auto period_seq<Duration>::periods() const |
| 286 | -> std::vector<period<Duration>> const& | 286 | -> std::vector<period<Duration>> const& |
| 287 | { | 287 | { |
| 288 | return periods_; | 288 | return periods_; |
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | template <class Duration> | 291 | template <typename Duration> |
| 292 | auto operator<<(std::ostream& os, period<Duration> const& p) -> std::ostream& | 292 | auto operator<<(std::ostream& os, period<Duration> const& p) -> std::ostream& |
| 293 | { | 293 | { |
| 294 | return os << "[" << p.start() << ", " << p.end() << ")"; | 294 | return os << "[" << p.start() << ", " << p.end() << ")"; |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | template <class Duration> | 297 | template <typename Duration> |
| 298 | auto operator<<(std::ostream& os, period_seq<Duration> const& ps) | 298 | auto operator<<(std::ostream& os, period_seq<Duration> const& ps) |
| 299 | -> std::ostream& | 299 | -> std::ostream& |
| 300 | { | 300 | { |