AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
dateTime.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 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 <ctime>
28
29#include "date/date.hpp"
30#include "date/time.hpp"
31#include "date/offsetTime.hpp"
32
33
34namespace anch::date {
35
41 struct ANCH_DATE_EXPORT DateFields {
43 int32_t year = 1970;
44
46 uint16_t month = 1;
47
49 uint16_t day = 1;
50
52 uint16_t hour = 0;
53
55 uint16_t minute = 0;
56
58 uint16_t second = 0;
59
61 uint16_t millisecond = 0;
62
64 uint16_t microsecond = 0;
65
67 uint16_t nanosecond = 0;
68
70 uint16_t weekday = 4;
71
73 uint16_t yearday = 1;
74 };
75
89 class ANCH_DATE_EXPORT DateTime {
90
91 // Attributes +
92 private:
94 std::chrono::sys_time<std::chrono::nanoseconds> _time;
95 // Attributes -
96
97 // Constructors +
98 public:
102 constexpr DateTime() noexcept;
103
111 explicit DateTime(const std::chrono::system_clock::time_point& time);
112
120 explicit DateTime(const std::time_t& time);
121
130 explicit DateTime(const std::tm* const time);
131
139 explicit DateTime(const std::timespec& time);
140
151 explicit DateTime(const anch::date::DateFields& fields);
152 // Constructors -
153
154 // Methods +
155 public:
163 static DateTime now();
164
174 anch::date::DateFields fields(anch::date::Zone zone = anch::date::Zone::LOCAL) const;
175
183 bool after(const DateTime& date) const noexcept;
184
192 bool before(const DateTime& date) const noexcept;
193
201 bool equals(const DateTime& date) const noexcept;
202
212 anch::date::Date date(anch::date::Zone zone = anch::date::Zone::LOCAL) const;
213
223 anch::date::Time time(anch::date::Zone zone = anch::date::Zone::LOCAL) const;
224
235 anch::date::OffsetTime offsetTime(anch::date::Zone zone = anch::date::Zone::LOCAL) const;
236 // Methods -
237
238 // Operators +
239 public:
247 std::strong_ordering operator<=>(const DateTime& date) const noexcept;
248
256 bool operator==(const DateTime& date) const noexcept;
257
265 explicit operator std::chrono::system_clock::time_point() const noexcept;
266
272 explicit operator std::time_t() const noexcept;
273
279 explicit operator std::tm() const noexcept;
280
286 explicit operator std::timespec() const noexcept;
287 // Operators -
288
289 };
290
291} // anch::date
292
293#include "date/impl/dateTime.hpp"
Calendar day (RFC 3339 full-date , JSON schema and OpenAPI date format, XSD xs:date ).
Definition date.hpp:63
static DateTime now()
anch::date::Time time(anch::date::Zone zone=anch::date::Zone::LOCAL) const
operator std::timespec() const noexcept
anch::date::Date date(anch::date::Zone zone=anch::date::Zone::LOCAL) const
operator std::chrono::system_clock::time_point() const noexcept
operator std::time_t() const noexcept
anch::date::OffsetTime offsetTime(anch::date::Zone zone=anch::date::Zone::LOCAL) const
bool before(const DateTime &date) const noexcept
operator std::tm() const noexcept
bool equals(const DateTime &date) const noexcept
bool after(const DateTime &date) const noexcept
anch::date::DateFields fields(anch::date::Zone zone=anch::date::Zone::LOCAL) const
constexpr DateTime() noexcept
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
AnCH framework base namespace.
Definition app.hpp:30
Broken down date and time ( DateTime::fields ): local time or UTC.
Definition dateTime.hpp:41
uint16_t nanosecond
Definition dateTime.hpp:67
uint16_t millisecond
Definition dateTime.hpp:61
uint16_t microsecond
Definition dateTime.hpp:64
uint16_t month
Definition dateTime.hpp:46
uint16_t second
Definition dateTime.hpp:58
uint16_t day
Definition dateTime.hpp:49
int32_t year
Definition dateTime.hpp:43
uint16_t minute
Definition dateTime.hpp:55
uint16_t weekday
Definition dateTime.hpp:70
uint16_t hour
Definition dateTime.hpp:52
uint16_t yearday
Definition dateTime.hpp:73