AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
offsetTime.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-date-export.hpp"
23
24#include <chrono>
25#include <compare>
26#include <ostream>
27#include <string>
28#include <string_view>
29
30#include "date/date.hpp"
31#include "date/time.hpp"
32
33namespace anch::date {
34
49 class ANCH_DATE_EXPORT OffsetTime {
50
51 // Attributes +
52 private:
54 anch::date::Time _time;
55
57 std::chrono::minutes _offset;
58 // Attributes -
59
60 // Constructors +
61 public:
65 constexpr OffsetTime() noexcept;
66
75 OffsetTime(const anch::date::Time& time, std::chrono::minutes offset);
76 // Constructors -
77
78 // Methods +
79 public:
87 static OffsetTime now(anch::date::Zone zone = anch::date::Zone::LOCAL);
88
98 static OffsetTime parse(std::string_view text);
99
105 std::string format() const;
106
112 constexpr const anch::date::Time& time() const noexcept;
113
119 constexpr std::chrono::minutes offset() const noexcept;
120
126 anch::date::Time utc() const noexcept;
127
137 OffsetTime withOffset(std::chrono::minutes offset) const;
138
146 constexpr bool isSameInstant(const OffsetTime& other) const noexcept;
147 // Methods -
148
149 private:
155 constexpr std::chrono::nanoseconds instant() const noexcept;
156
157 // Operators +
158 public:
166 constexpr std::strong_ordering operator<=>(const OffsetTime& other) const noexcept;
167
175 constexpr bool operator==(const OffsetTime& other) const noexcept;
176 // Operators -
177
178 };
179
190 ANCH_DATE_EXPORT std::ostream& operator<<(std::ostream& out, const anch::date::OffsetTime& time);
191
192} // anch::date
193
194#include "date/impl/offsetTime.hpp"
Time of day with an offset from UTC (RFC 3339 full-time , time format of JSON schema and OpenAPI).
Definition offsetTime.hpp:49
anch::date::Time utc() const noexcept
constexpr std::chrono::minutes offset() const noexcept
static OffsetTime now(anch::date::Zone zone=anch::date::Zone::LOCAL)
std::string format() const
constexpr bool isSameInstant(const OffsetTime &other) const noexcept
OffsetTime withOffset(std::chrono::minutes offset) const
constexpr OffsetTime() noexcept
static OffsetTime parse(std::string_view text)
constexpr const anch::date::Time & time() const noexcept
Time of day (RFC 3339 partial-time , SQL TIME , XSD xs:time without time zone).
Definition time.hpp:48
Dates namespace.
Zone
Time zone of conversions between days and points in time.
Definition date.hpp:42
AnCH framework base namespace.
Definition app.hpp:30