nfx-datetime 0.1.1
Cross-platform C++ DateTime library with 100-nanosecond precision and ISO 8601 support
Loading...
Searching...
No Matches
Constants.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 nfx
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
31
32#pragma once
33
34#include <cstdint>
35#include <limits>
36#include <string_view>
37
38namespace nfx::time::constants
39{
40 //=====================================================================
41 // Basic time conversion constants
42 //=====================================================================
43
45 inline constexpr std::int32_t MILLISECONDS_PER_SECOND{ 1000 };
46
48 inline constexpr std::int32_t SECONDS_PER_MINUTE{ 60 };
49
51 inline constexpr std::int32_t SECONDS_PER_HOUR{ SECONDS_PER_MINUTE * 60 };
52
54 inline constexpr std::int32_t SECONDS_PER_DAY{ SECONDS_PER_HOUR * 24 };
55
57 inline constexpr std::int32_t MINUTES_PER_HOUR{ 60 };
58
60 inline constexpr std::int32_t MINUTES_PER_DAY{ MINUTES_PER_HOUR * 24 };
61
63 inline constexpr std::int32_t HOURS_PER_DAY{ 24 };
64
65 //=====================================================================
66 // DateTime value boundaries
67 //=====================================================================
68
70 inline constexpr std::int64_t MIN_DATETIME_TICKS{ 0LL };
71
73 inline constexpr std::int64_t MAX_DATETIME_TICKS{ 3155378975999999999LL };
74
76 inline constexpr std::int64_t UNIX_EPOCH_TICKS{ 621355968000000000LL };
77
79 inline constexpr std::int64_t MICROSOFT_FILETIME_EPOCH_TICKS{ 504911232000000000LL };
80
81 //=====================================================================
82 // Time unit conversion constants
83 //=====================================================================
84
86 inline constexpr std::int64_t NANOSECONDS_PER_TICK{ 100LL };
87
89 inline constexpr std::int64_t TICKS_PER_MICROSECOND{ 10LL };
90
92 inline constexpr std::int64_t TICKS_PER_MILLISECOND{ 10000LL };
93
95 inline constexpr std::int64_t TICKS_PER_SECOND{ TICKS_PER_MILLISECOND * 1000LL };
96
98 inline constexpr std::int64_t TICKS_PER_MINUTE{ TICKS_PER_SECOND * 60LL };
99
101 inline constexpr std::int64_t TICKS_PER_HOUR{ TICKS_PER_MINUTE * 60LL };
102
104 inline constexpr std::int64_t TICKS_PER_DAY{ TICKS_PER_HOUR * 24LL };
105
106 //=====================================================================
107 // Timezone offset limits (ISO 8601)
108 //=====================================================================
109
111 inline constexpr std::int32_t MIN_OFFSET_MINUTES{ -14 * 60 };
112
114 inline constexpr std::int32_t MAX_OFFSET_MINUTES{ 14 * 60 };
115
117 inline constexpr std::int32_t MIN_OFFSET_SECONDS{ MIN_OFFSET_MINUTES * 60 };
118
120 inline constexpr std::int32_t MAX_OFFSET_SECONDS{ MAX_OFFSET_MINUTES * 60 };
121
123 inline constexpr std::int32_t UTC_OFFSET{ 0 };
124
125 //=====================================================================
126 // Calendar system constants (Gregorian)
127 //=====================================================================
128
129 //----------------------------------------------
130 // Year boundaries
131 //----------------------------------------------
132
134 inline constexpr std::int32_t MIN_YEAR{ 1 };
135
137 inline constexpr std::int32_t MAX_YEAR{ 9999 };
138
139 //----------------------------------------------
140 // Calendar cycle constants for date calculations
141 //----------------------------------------------
142
144 inline constexpr std::int32_t DAYS_PER_400_YEARS{ 146097 };
145
147 inline constexpr std::int32_t DAYS_PER_100_YEARS{ 36524 };
148
150 inline constexpr std::int32_t DAYS_PER_4_YEARS{ 1461 };
151
153 inline constexpr std::int32_t DAYS_PER_YEAR{ 365 };
154
155 //=====================================================================
156 // ISO 8601 string formats
157 //=====================================================================
158
159 //----------------------------------------------
160 // String format patterns
161 //----------------------------------------------
162
164 inline constexpr std::string_view ISO8601_BASIC_PATTERN{ "yyyy-MM-ddTHH:mm:ssZ" };
165
167 inline constexpr std::string_view ISO8601_EXTENDED_PATTERN{ "yyyy-MM-ddTHH:mm:ss.fffffffK" };
168
170 inline constexpr std::string_view ISO8601_DATE_PATTERN{ "yyyy-MM-dd" };
171
173 inline constexpr std::string_view ISO8601_TIME_PATTERN{ "HH:mm:ss" };
174
175 //----------------------------------------------
176 // String format limits (for buffer allocation)
177 //----------------------------------------------
178
183 inline constexpr std::size_t MAX_ISO8601_LENGTH{ 35 };
184
189 inline constexpr std::size_t MIN_ISO8601_LENGTH{ 20 };
190
191 //----------------------------------------------
192 // Unix epoch format limits
193 //----------------------------------------------
194
196 inline constexpr std::size_t MAX_UNIX_SECONDS_LENGTH{ 10 };
197
199 inline constexpr std::size_t MAX_UNIX_MILLISECONDS_LENGTH{ 13 };
200
202 inline constexpr std::size_t CURRENT_UNIX_SECONDS_LENGTH{ 10 };
203} // namespace nfx::time::constants
constexpr std::int32_t DAYS_PER_4_YEARS
Days per 4-year cycle (Gregorian calendar).
Definition Constants.h:150
constexpr std::int64_t TICKS_PER_HOUR
Ticks per hour (100-nanosecond units).
Definition Constants.h:101
constexpr std::int32_t DAYS_PER_100_YEARS
Days per 100-year cycle (Gregorian calendar).
Definition Constants.h:147
constexpr std::int32_t SECONDS_PER_HOUR
Number of seconds in an hour (60 minutes × 60 seconds).
Definition Constants.h:51
constexpr std::int32_t MILLISECONDS_PER_SECOND
Number of milliseconds in a second.
Definition Constants.h:45
constexpr std::int32_t DAYS_PER_YEAR
Days per year (non-leap).
Definition Constants.h:153
constexpr std::size_t MAX_ISO8601_LENGTH
Maximum length of ISO 8601 datetime string.
Definition Constants.h:183
constexpr std::int64_t TICKS_PER_MILLISECOND
Ticks per millisecond (100-nanosecond units).
Definition Constants.h:92
constexpr std::int32_t DAYS_PER_400_YEARS
Days per 400-year cycle (Gregorian calendar).
Definition Constants.h:144
constexpr std::int64_t MIN_DATETIME_TICKS
Minimum DateTime value: January 1, 0001 00:00:00.000 UTC (100-nanosecond ticks).
Definition Constants.h:70
constexpr std::size_t MAX_UNIX_MILLISECONDS_LENGTH
Maximum length of Unix timestamp in milliseconds (13 digits).
Definition Constants.h:199
constexpr std::int64_t MICROSOFT_FILETIME_EPOCH_TICKS
Microsoft Windows FILETIME epoch: January 1, 1601 00:00:00.000 UTC (100-nanosecond ticks).
Definition Constants.h:79
constexpr std::int64_t TICKS_PER_MINUTE
Ticks per minute (100-nanosecond units).
Definition Constants.h:98
constexpr std::int32_t MAX_OFFSET_MINUTES
Maximum timezone offset in minutes: +14:00 (UTC+14).
Definition Constants.h:114
constexpr std::string_view ISO8601_TIME_PATTERN
ISO 8601 time-only format pattern.
Definition Constants.h:173
constexpr std::size_t MIN_ISO8601_LENGTH
Minimum length of ISO 8601 datetime string.
Definition Constants.h:189
constexpr std::int32_t SECONDS_PER_DAY
Number of seconds in a day (24 hours × 60 minutes × 60 seconds).
Definition Constants.h:54
constexpr std::string_view ISO8601_EXTENDED_PATTERN
Extended ISO 8601 datetime format pattern with fractional seconds.
Definition Constants.h:167
constexpr std::int32_t MINUTES_PER_HOUR
Number of minutes in an hour.
Definition Constants.h:57
constexpr std::size_t MAX_UNIX_SECONDS_LENGTH
Maximum length of Unix timestamp in seconds (10 digits for year 2286).
Definition Constants.h:196
constexpr std::int32_t SECONDS_PER_MINUTE
Number of seconds in a minute.
Definition Constants.h:48
constexpr std::int32_t MINUTES_PER_DAY
Number of minutes in a day (24 hours × 60 minutes).
Definition Constants.h:60
constexpr std::int64_t MAX_DATETIME_TICKS
Maximum DateTime value: December 31, 9999 23:59:59.999 UTC (100-nanosecond ticks).
Definition Constants.h:73
constexpr std::int32_t MAX_OFFSET_SECONDS
Maximum timezone offset in seconds: +14:00:00 (UTC+14).
Definition Constants.h:120
constexpr std::int32_t MIN_OFFSET_MINUTES
Minimum timezone offset in minutes: -14:00 (UTC-14).
Definition Constants.h:111
constexpr std::size_t CURRENT_UNIX_SECONDS_LENGTH
Current typical length of Unix timestamp in seconds (10 digits until 2286).
Definition Constants.h:202
constexpr std::int32_t MIN_OFFSET_SECONDS
Minimum timezone offset in seconds: -14:00:00 (UTC-14).
Definition Constants.h:117
constexpr std::string_view ISO8601_BASIC_PATTERN
Basic ISO 8601 datetime format pattern.
Definition Constants.h:164
constexpr std::int64_t TICKS_PER_DAY
Ticks per day (100-nanosecond units).
Definition Constants.h:104
constexpr std::int32_t MIN_YEAR
Minimum year value.
Definition Constants.h:134
constexpr std::int64_t TICKS_PER_MICROSECOND
Ticks per microsecond (100-nanosecond units).
Definition Constants.h:89
constexpr std::string_view ISO8601_DATE_PATTERN
ISO 8601 date-only format pattern.
Definition Constants.h:170
constexpr std::int32_t HOURS_PER_DAY
Number of hours in a day.
Definition Constants.h:63
constexpr std::int32_t MAX_YEAR
Maximum year value.
Definition Constants.h:137
constexpr std::int32_t UTC_OFFSET
UTC offset (zero).
Definition Constants.h:123
constexpr std::int64_t TICKS_PER_SECOND
Ticks per second (100-nanosecond units).
Definition Constants.h:95
constexpr std::int64_t NANOSECONDS_PER_TICK
Nanoseconds per tick (1 tick = 100 nanoseconds).
Definition Constants.h:86
constexpr std::int64_t UNIX_EPOCH_TICKS
Unix epoch: January 1, 1970 00:00:00.000 UTC (100-nanosecond ticks).
Definition Constants.h:76