AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
date.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 <cstdint>
27#include <ostream>
28#include <string>
29#include <string_view>
30
31namespace anch::date {
32
33 class DateTime;
34 class Time;
35 class OffsetTime;
36
42 enum class Zone {
47 };
48
63 class ANCH_DATE_EXPORT Date {
64
65 // Attributes +
66 private:
68 std::chrono::year_month_day _date;
69 // Attributes -
70
71 // Constructors +
72 public:
76 constexpr Date() noexcept;
77
87 Date(int32_t year, unsigned month, unsigned day);
88
96 explicit Date(const std::chrono::year_month_day& date);
97
105 explicit Date(const std::chrono::sys_days& days);
106 // Constructors -
107
108 // Methods +
109 public:
117 static Date today(anch::date::Zone zone = anch::date::Zone::LOCAL);
118
128 static Date parse(std::string_view text);
129
135 std::string format() const;
136
142 constexpr int32_t year() const noexcept;
143
149 constexpr unsigned month() const noexcept;
150
156 constexpr unsigned day() const noexcept;
157
163 unsigned weekday() const noexcept;
164
170 unsigned dayOfYear() const noexcept;
171
177 constexpr bool isLeapYear() const noexcept;
178
188 Date plusDays(int64_t days) const;
189
200 Date plusMonths(int64_t months) const;
201
211 Date plusYears(int64_t years) const;
212
220 int64_t daysUntil(const Date& other) const noexcept;
221
232 anch::date::DateTime startOfDay(anch::date::Zone zone = anch::date::Zone::LOCAL) const;
233
247 anch::date::DateTime at(const anch::date::Time& time, anch::date::Zone zone = anch::date::Zone::LOCAL) const;
248
260 anch::date::DateTime at(const anch::date::OffsetTime& time) const;
261 // Methods -
262
263 // Operators +
264 public:
272 constexpr std::strong_ordering operator<=>(const Date& other) const noexcept;
273
281 constexpr bool operator==(const Date& other) const noexcept;
282
288 constexpr explicit operator std::chrono::year_month_day() const noexcept;
289
295 explicit operator std::chrono::sys_days() const noexcept;
296 // Operators -
297
298 };
299
310 ANCH_DATE_EXPORT std::ostream& operator<<(std::ostream& out, const anch::date::Date& date);
311
312} // anch::date
313
314#include "date/impl/date.hpp"
Calendar day (RFC 3339 full-date , JSON schema and OpenAPI date format, XSD xs:date ).
Definition date.hpp:63
constexpr Date() noexcept
std::string format() const
int64_t daysUntil(const Date &other) const noexcept
constexpr bool isLeapYear() const noexcept
constexpr unsigned month() const noexcept
unsigned weekday() const noexcept
static Date parse(std::string_view text)
constexpr unsigned day() const noexcept
constexpr operator std::chrono::year_month_day() const noexcept
Date plusMonths(int64_t months) const
Date plusDays(int64_t days) const
Date plusYears(int64_t years) const
constexpr int32_t year() const noexcept
operator std::chrono::sys_days() const noexcept
anch::date::DateTime startOfDay(anch::date::Zone zone=anch::date::Zone::LOCAL) const
anch::date::DateTime at(const anch::date::Time &time, anch::date::Zone zone=anch::date::Zone::LOCAL) const
static Date today(anch::date::Zone zone=anch::date::Zone::LOCAL)
unsigned dayOfYear() const noexcept
Point in time.
Definition dateTime.hpp:89
Time of day with an offset from UTC (RFC 3339 full-time , time format of JSON schema and OpenAPI).
Definition offsetTime.hpp:49
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
@ LOCAL
Definition date.hpp:46
@ UTC
Definition date.hpp:44
AnCH framework base namespace.
Definition app.hpp:30