Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_zone_conversions.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3#ifndef _TIME_SHIELD_TIME_ZONE_CONVERSIONS_HPP_INCLUDED
4#define _TIME_SHIELD_TIME_ZONE_CONVERSIONS_HPP_INCLUDED
5
9
10#include "date_time_struct.hpp"
11#include "time_conversions.hpp"
12#include "time_zone_offset.hpp"
14
15namespace time_shield {
16
19
20 ts_t zone_to_gmt(ts_t local, TimeZone zone);
21 ts_t gmt_to_zone(ts_t gmt, TimeZone zone);
22
23 namespace detail {
24
27 int max_days = num_days_in_month(dt.year, dt.mon);
28 const int OLD_START_SUMMER_HOUR = 2;
29 const int OLD_STOP_SUMMER_HOUR = 3;
30 const int NEW_SUMMER_HOUR = 1;
31
32 if(dt.year < 2002) {
33 if(dt.mon > MAR && dt.mon < OCT) {
34 return cet - SEC_PER_HOUR * 2;
35 } else if(dt.mon == MAR) {
36 for(int d = max_days; d >= dt.day; --d) {
37 if(day_of_week_date(dt.year, MAR, d) == SUN) {
38 if(d == dt.day) {
39 if(dt.hour >= OLD_START_SUMMER_HOUR) {
40 return cet - SEC_PER_HOUR * 2;
41 }
42 return cet - SEC_PER_HOUR;
43 }
44 return cet - SEC_PER_HOUR;
45 }
46 }
47 return cet - SEC_PER_HOUR * 2;
48 } else if(dt.mon == OCT) {
49 for(int d = max_days; d >= dt.day; --d) {
50 if(day_of_week_date(dt.year, OCT, d) == SUN) {
51 if(d == dt.day) {
52 if(dt.hour >= OLD_STOP_SUMMER_HOUR) {
53 return cet - SEC_PER_HOUR;
54 }
55 return cet - SEC_PER_HOUR;
56 }
57 return cet - SEC_PER_HOUR * 2;
58 }
59 }
60 return cet - SEC_PER_HOUR;
61 }
62 return cet - SEC_PER_HOUR;
63 }
64
65 if(dt.mon > MAR && dt.mon < OCT) {
66 return cet - SEC_PER_HOUR * 2;
67 }
68 if(dt.mon == MAR) {
69 for(int d = max_days; d >= dt.day; --d) {
70 if(day_of_week_date(dt.year, MAR, d) == SUN) {
71 if(d == dt.day) {
72 if(dt.hour >= (NEW_SUMMER_HOUR + 2)) {
73 return cet - SEC_PER_HOUR * 2;
74 }
75 return cet - SEC_PER_HOUR;
76 }
77 return cet - SEC_PER_HOUR;
78 }
79 }
80 return cet - SEC_PER_HOUR * 2;
81 }
82 if(dt.mon == OCT) {
83 for(int d = max_days; d >= dt.day; --d) {
84 if(day_of_week_date(dt.year, OCT, d) == SUN) {
85 if(d == dt.day) {
86 if(dt.hour >= (NEW_SUMMER_HOUR + 1)) {
87 return cet - SEC_PER_HOUR;
88 }
89 return cet - SEC_PER_HOUR * 2;
90 }
91 return cet - SEC_PER_HOUR * 2;
92 }
93 }
94 }
95 return cet - SEC_PER_HOUR;
96 }
97
100 const int SWITCH_HOUR = 1;
101
102 if(dt.mon > MAR && dt.mon < OCT) {
103 return gmt + SEC_PER_HOUR * 2;
104 }
105 if(dt.mon == MAR) {
106 int last = last_sunday_month_day(dt.year, MAR);
107 if(dt.day > last) {
108 return gmt + SEC_PER_HOUR * 2;
109 }
110 if(dt.day < last) {
111 return gmt + SEC_PER_HOUR;
112 }
113 if(dt.hour >= SWITCH_HOUR) {
114 return gmt + SEC_PER_HOUR * 2;
115 }
116 return gmt + SEC_PER_HOUR;
117 }
118 if(dt.mon == OCT) {
119 int last = last_sunday_month_day(dt.year, OCT);
120 if(dt.day > last) {
121 return gmt + SEC_PER_HOUR;
122 }
123 if(dt.day < last) {
124 return gmt + SEC_PER_HOUR * 2;
125 }
126 if(dt.hour >= SWITCH_HOUR) {
127 return gmt + SEC_PER_HOUR;
128 }
129 return gmt + SEC_PER_HOUR * 2;
130 }
131 return gmt + SEC_PER_HOUR;
132 }
133
134 inline ts_t european_local_to_gmt(ts_t local, int standard_offset_hours) {
135 return cet_to_gmt_impl(local - SEC_PER_HOUR * (standard_offset_hours - 1));
136 }
137
138 inline ts_t gmt_to_european_local(ts_t gmt, int standard_offset_hours) {
139 return gmt_to_cet_impl(gmt) + SEC_PER_HOUR * (standard_offset_hours - 1);
140 }
141
143 const int SWITCH_HOUR = 2;
144 int start_day = 0;
145 int end_day = 0;
146 int start_month = 0;
147 int end_month = 0;
148
149 if(dt.year >= 2007) {
150 start_month = MAR;
151 end_month = NOV;
152 int first_sunday_march = static_cast<int>(
154 start_day = first_sunday_march + 7;
155 end_day = static_cast<int>(
157 } else {
158 start_month = APR;
159 end_month = OCT;
160 start_day = static_cast<int>(
162 end_day = last_sunday_month_day(dt.year, OCT);
163 }
164
165 if(dt.mon > start_month && dt.mon < end_month) {
166 return true;
167 }
168 if(dt.mon < start_month || dt.mon > end_month) {
169 return false;
170 }
171 if(dt.mon == start_month) {
172 if(dt.day > start_day) {
173 return true;
174 }
175 if(dt.day < start_day) {
176 return false;
177 }
178 return dt.hour >= SWITCH_HOUR;
179 }
180 if(dt.mon == end_month) {
181 if(dt.day < end_day) {
182 return true;
183 }
184 if(dt.day > end_day) {
185 return false;
186 }
187 return dt.hour < SWITCH_HOUR;
188 }
189 return false;
190 }
191
192 inline bool fixed_zone_offset(TimeZone zone, tz_t& utc_offset) {
193 switch(zone) {
194 case GMT:
195 case UTC:
196 case WET:
197 utc_offset = 0;
198 return true;
199 case WEST:
200 utc_offset = static_cast<tz_t>(SEC_PER_HOUR);
201 return true;
202 case CET:
203 utc_offset = static_cast<tz_t>(SEC_PER_HOUR);
204 return true;
205 case CEST:
206 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 2);
207 return true;
208 case EET:
209 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 2);
210 return true;
211 case EEST:
212 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 3);
213 return true;
214 case IST:
215 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 5 + SEC_PER_MIN * 30);
216 return true;
217 case MYT:
218 case WITA:
219 case SGT:
220 case PHT:
221 case HKT:
222 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 8);
223 return true;
224 case WIB:
225 case ICT:
226 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 7);
227 return true;
228 case WIT:
229 case JST:
230 case KST:
231 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 9);
232 return true;
233 case KZT:
234 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 5);
235 return true;
236 case TRT:
237 case BYT:
238 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 3);
239 return true;
240 case GST:
241 utc_offset = static_cast<tz_t>(SEC_PER_HOUR * 4);
242 return true;
243 default:
244 utc_offset = 0;
245 return false;
246 }
247 }
248
250 if(local_ms == ERROR_TIMESTAMP) {
251 return ERROR_TIMESTAMP;
252 }
253 const ts_t local_sec = ms_to_sec<ts_t>(local_ms);
254 const ts_ms_t remainder_ms = local_ms - sec_to_ms<ts_ms_t>(local_sec);
255 const ts_t gmt_sec = zone_to_gmt(local_sec, zone);
256 if(gmt_sec == ERROR_TIMESTAMP) {
257 return ERROR_TIMESTAMP;
258 }
259 return sec_to_ms<ts_ms_t>(gmt_sec) + remainder_ms;
260 }
261
263 if(gmt_ms == ERROR_TIMESTAMP) {
264 return ERROR_TIMESTAMP;
265 }
266 const ts_t gmt_sec = ms_to_sec<ts_t>(gmt_ms);
267 const ts_ms_t remainder_ms = gmt_ms - sec_to_ms<ts_ms_t>(gmt_sec);
268 const ts_t local_sec = gmt_to_zone(gmt_sec, zone);
269 if(local_sec == ERROR_TIMESTAMP) {
270 return ERROR_TIMESTAMP;
271 }
272 return sec_to_ms<ts_ms_t>(local_sec) + remainder_ms;
273 }
274
275 } // namespace detail
276
280 inline ts_t cet_to_gmt(ts_t cet) {
281 return detail::cet_to_gmt_impl(cet);
282 }
283
287 inline ts_t eet_to_gmt(ts_t eet) {
288 return detail::european_local_to_gmt(eet, 2);
289 }
290
296 }
297
301 inline ts_t et_to_gmt(ts_t et) {
303 bool is_dst = detail::is_us_eastern_dst_local(dt);
304 return et + SEC_PER_HOUR * (is_dst ? 4 : 5);
305 }
306
310 inline ts_t gmt_to_et(ts_t gmt) {
311 ts_t et_standard = gmt - SEC_PER_HOUR * 5;
312 DateTimeStruct dt_local = to_date_time(et_standard);
313 bool is_dst = detail::is_us_eastern_dst_local(dt_local);
314 return gmt - SEC_PER_HOUR * (is_dst ? 4 : 5);
315 }
316
320 inline ts_t ny_to_gmt(ts_t ny) {
321 return et_to_gmt(ny);
322 }
323
327 inline ts_t gmt_to_ny(ts_t gmt) {
328 return gmt_to_et(gmt);
329 }
330
334 inline ts_t ct_to_gmt(ts_t ct) {
335 return et_to_gmt(ct + SEC_PER_HOUR);
336 }
337
341 inline ts_t gmt_to_ct(ts_t gmt) {
342 return gmt_to_et(gmt) - SEC_PER_HOUR;
343 }
344
348 inline ts_t gmt_to_cet(ts_t gmt) {
349 return detail::gmt_to_cet_impl(gmt);
350 }
351
355 inline ts_t gmt_to_eet(ts_t gmt) {
356 return detail::gmt_to_european_local(gmt, 2);
357 }
358
363 inline ts_t zone_to_gmt(ts_t local, TimeZone zone) {
364 if(local == ERROR_TIMESTAMP) {
365 return ERROR_TIMESTAMP;
366 }
367
368 tz_t utc_offset = 0;
369 switch(zone) {
370 case GMT:
371 case UTC:
372 return local;
373 case WET:
374 return detail::european_local_to_gmt(local, 0);
375 case CET:
376 return cet_to_gmt(local);
377 case EET:
378 return eet_to_gmt(local);
379 case WEST:
380 case CEST:
381 case EEST:
382 detail::fixed_zone_offset(zone, utc_offset);
383 return to_utc(local, utc_offset);
384 case ET:
385 return et_to_gmt(local);
386 case CT:
387 return ct_to_gmt(local);
388 case UNKNOWN:
389 return ERROR_TIMESTAMP;
390 default:
391 if(detail::fixed_zone_offset(zone, utc_offset)) {
392 return to_utc(local, utc_offset);
393 }
394 return ERROR_TIMESTAMP;
395 }
396 }
397
402 inline ts_t gmt_to_zone(ts_t gmt, TimeZone zone) {
403 if(gmt == ERROR_TIMESTAMP) {
404 return ERROR_TIMESTAMP;
405 }
406
407 tz_t utc_offset = 0;
408 switch(zone) {
409 case GMT:
410 case UTC:
411 return gmt;
412 case WET:
413 return detail::gmt_to_european_local(gmt, 0);
414 case CET:
415 return gmt_to_cet(gmt);
416 case EET:
417 return gmt_to_eet(gmt);
418 case WEST:
419 case CEST:
420 case EEST:
421 detail::fixed_zone_offset(zone, utc_offset);
422 return to_local(gmt, utc_offset);
423 case ET:
424 return gmt_to_et(gmt);
425 case CT:
426 return gmt_to_ct(gmt);
427 case UNKNOWN:
428 return ERROR_TIMESTAMP;
429 default:
430 if(detail::fixed_zone_offset(zone, utc_offset)) {
431 return to_local(gmt, utc_offset);
432 }
433 return ERROR_TIMESTAMP;
434 }
435 }
436
442 inline ts_t convert_time_zone(ts_t local, TimeZone from, TimeZone to) {
443 ts_t gmt = zone_to_gmt(local, from);
444 return gmt == ERROR_TIMESTAMP ? ERROR_TIMESTAMP
445 : gmt_to_zone(gmt, to);
446 }
447
452 inline ts_ms_t zone_to_gmt_ms(ts_ms_t local_ms, TimeZone zone) {
453 if(local_ms == ERROR_TIMESTAMP) {
454 return ERROR_TIMESTAMP;
455 }
456
457 tz_t utc_offset = 0;
458 switch(zone) {
459 case GMT:
460 case UTC:
461 return local_ms;
462 case WET:
463 case CET:
464 case EET:
465 case ET:
466 case CT:
467 return detail::zone_to_gmt_ms_by_seconds(local_ms, zone);
468 case WEST:
469 case CEST:
470 case EEST:
471 detail::fixed_zone_offset(zone, utc_offset);
472 return to_utc_ms(local_ms, utc_offset);
473 case UNKNOWN:
474 return ERROR_TIMESTAMP;
475 default:
476 if(detail::fixed_zone_offset(zone, utc_offset)) {
477 return to_utc_ms(local_ms, utc_offset);
478 }
479 return ERROR_TIMESTAMP;
480 }
481 }
482
487 inline ts_ms_t gmt_to_zone_ms(ts_ms_t gmt_ms, TimeZone zone) {
488 if(gmt_ms == ERROR_TIMESTAMP) {
489 return ERROR_TIMESTAMP;
490 }
491
492 tz_t utc_offset = 0;
493 switch(zone) {
494 case GMT:
495 case UTC:
496 return gmt_ms;
497 case WET:
498 case CET:
499 case EET:
500 case ET:
501 case CT:
502 return detail::gmt_to_zone_ms_by_seconds(gmt_ms, zone);
503 case WEST:
504 case CEST:
505 case EEST:
506 detail::fixed_zone_offset(zone, utc_offset);
507 return to_local_ms(gmt_ms, utc_offset);
508 case UNKNOWN:
509 return ERROR_TIMESTAMP;
510 default:
511 if(detail::fixed_zone_offset(zone, utc_offset)) {
512 return to_local_ms(gmt_ms, utc_offset);
513 }
514 return ERROR_TIMESTAMP;
515 }
516 }
517
524 ts_ms_t gmt_ms = zone_to_gmt_ms(local_ms, from);
525 return gmt_ms == ERROR_TIMESTAMP ? ERROR_TIMESTAMP
526 : gmt_to_zone_ms(gmt_ms, to);
527 }
528
529 inline ts_t ist_to_gmt(ts_t ist) { return zone_to_gmt(ist, IST); }
530 inline ts_t gmt_to_ist(ts_t gmt) { return gmt_to_zone(gmt, IST); }
531
532 inline ts_t myt_to_gmt(ts_t myt) { return zone_to_gmt(myt, MYT); }
533 inline ts_t gmt_to_myt(ts_t gmt) { return gmt_to_zone(gmt, MYT); }
534
535 inline ts_t wib_to_gmt(ts_t wib) { return zone_to_gmt(wib, WIB); }
536 inline ts_t gmt_to_wib(ts_t gmt) { return gmt_to_zone(gmt, WIB); }
537
538 inline ts_t wita_to_gmt(ts_t wita) { return zone_to_gmt(wita, WITA); }
539 inline ts_t gmt_to_wita(ts_t gmt) { return gmt_to_zone(gmt, WITA); }
540
541 inline ts_t wit_to_gmt(ts_t wit) { return zone_to_gmt(wit, WIT); }
542 inline ts_t gmt_to_wit(ts_t gmt) { return gmt_to_zone(gmt, WIT); }
543
544 inline ts_t kzt_to_gmt(ts_t kzt) { return zone_to_gmt(kzt, KZT); }
545 inline ts_t gmt_to_kzt(ts_t gmt) { return gmt_to_zone(gmt, KZT); }
546
547 inline ts_t trt_to_gmt(ts_t trt) { return zone_to_gmt(trt, TRT); }
548 inline ts_t gmt_to_trt(ts_t gmt) { return gmt_to_zone(gmt, TRT); }
549
550 inline ts_t byt_to_gmt(ts_t byt) { return zone_to_gmt(byt, BYT); }
551 inline ts_t gmt_to_byt(ts_t gmt) { return gmt_to_zone(gmt, BYT); }
552
553 inline ts_t sgt_to_gmt(ts_t sgt) { return zone_to_gmt(sgt, SGT); }
554 inline ts_t gmt_to_sgt(ts_t gmt) { return gmt_to_zone(gmt, SGT); }
555
556 inline ts_t ict_to_gmt(ts_t ict) { return zone_to_gmt(ict, ICT); }
557 inline ts_t gmt_to_ict(ts_t gmt) { return gmt_to_zone(gmt, ICT); }
558
559 inline ts_t pht_to_gmt(ts_t pht) { return zone_to_gmt(pht, PHT); }
560 inline ts_t gmt_to_pht(ts_t gmt) { return gmt_to_zone(gmt, PHT); }
561
562 inline ts_t gst_to_gmt(ts_t gst) { return zone_to_gmt(gst, GST); }
563 inline ts_t gmt_to_gst(ts_t gmt) { return gmt_to_zone(gmt, GST); }
564
565 inline ts_t hkt_to_gmt(ts_t hkt) { return zone_to_gmt(hkt, HKT); }
566 inline ts_t gmt_to_hkt(ts_t gmt) { return gmt_to_zone(gmt, HKT); }
567
568 inline ts_t jst_to_gmt(ts_t jst) { return zone_to_gmt(jst, JST); }
569 inline ts_t gmt_to_jst(ts_t gmt) { return gmt_to_zone(gmt, JST); }
570
571 inline ts_t kst_to_gmt(ts_t kst) { return zone_to_gmt(kst, KST); }
572 inline ts_t gmt_to_kst(ts_t gmt) { return gmt_to_zone(gmt, KST); }
573
575 inline ts_t kyiv_to_gmt(ts_t kyiv) { return eet_to_gmt(kyiv); }
576
578 inline ts_t gmt_to_kyiv(ts_t gmt) { return gmt_to_eet(gmt); }
579
581
582} // namespace time_shield
583
584#endif // _TIME_SHIELD_TIME_ZONE_CONVERSIONS_HPP_INCLUDED
Header for date and time structure and related functions.
constexpr int64_t ERROR_TIMESTAMP
Error timestamp value.
constexpr int64_t DAYS_PER_WEEK
Days per week.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
constexpr int64_t SEC_PER_MIN
Seconds per minute.
ts_t gmt_to_et(ts_t gmt)
Convert GMT (UTC) to US Eastern Time (New York, EST/EDT).
ts_t kzt_to_gmt(ts_t kzt)
ts_t eet_to_gmt(ts_t eet)
Convert Eastern European Time to Greenwich Mean Time.
ts_t gmt_to_gst(ts_t gmt)
ts_t gmt_to_hkt(ts_t gmt)
ts_t gmt_to_eet(ts_t gmt)
Convert Greenwich Mean Time to Eastern European Time.
ts_t gst_to_gmt(ts_t gst)
ts_t byt_to_gmt(ts_t byt)
ts_ms_t zone_to_gmt_ms(ts_ms_t local_ms, TimeZone zone)
Convert supported local civil time in milliseconds to GMT (UTC).
ts_t gmt_to_kyiv(ts_t gmt)
Convert GMT to Kyiv civil time using the EET/EEST rules.
ts_t gmt_to_ist(ts_t gmt)
ts_t ct_to_gmt(ts_t ct)
Convert US Central Time (America/Chicago, CST/CDT) to GMT (UTC).
ts_t gmt_to_jst(ts_t gmt)
bool is_us_eastern_dst_local(const DateTimeStruct &dt)
Check if local US Eastern time uses DST.
ts_t ict_to_gmt(ts_t ict)
ts_t gmt_to_wit(ts_t gmt)
TIME_SHIELD_CONSTEXPR ts_t to_utc(ts_t local, tz_t utc_offset) noexcept
Convert local timestamp (seconds) to UTC using UTC offset.
ts_t gmt_to_kzt(ts_t gmt)
ts_t kyiv_to_gmt(ts_t kyiv)
Convert Kyiv civil time to GMT using the EET/EEST rules.
ts_t wita_to_gmt(ts_t wita)
ts_t cet_to_gmt(ts_t cet)
Convert Central European Time to Greenwich Mean Time.
ts_t convert_time_zone(ts_t local, TimeZone from, TimeZone to)
Convert a timestamp between two supported local civil time zones.
ts_t gmt_to_byt(ts_t gmt)
ts_ms_t gmt_to_zone_ms(ts_ms_t gmt_ms, TimeZone zone)
Convert GMT (UTC) in milliseconds to a supported local civil time zone.
ts_t gmt_to_pht(ts_t gmt)
TIME_SHIELD_CONSTEXPR ts_t to_local(ts_t utc, tz_t utc_offset) noexcept
Convert UTC timestamp (seconds) to local time using UTC offset.
ts_t gmt_to_ny(ts_t gmt)
Convert GMT (UTC) to New York Time.
ts_t gmt_to_cet(ts_t gmt)
Convert Greenwich Mean Time to Central European Time.
ts_t gmt_to_sgt(ts_t gmt)
ts_t kst_to_gmt(ts_t kst)
ts_t gmt_to_trt(ts_t gmt)
TIME_SHIELD_CONSTEXPR ts_ms_t to_local_ms(ts_ms_t utc_ms, tz_t utc_offset) noexcept
Convert UTC timestamp (milliseconds) to local time using UTC offset.
ts_t zone_to_gmt(ts_t local, TimeZone zone)
Convert supported local civil time to GMT (UTC).
ts_t wit_to_gmt(ts_t wit)
ts_t hkt_to_gmt(ts_t hkt)
ts_t gmt_to_ict(ts_t gmt)
ts_t ist_to_gmt(ts_t ist)
ts_t gmt_to_wib(ts_t gmt)
ts_t gmt_to_myt(ts_t gmt)
ts_t wib_to_gmt(ts_t wib)
ts_t trt_to_gmt(ts_t trt)
ts_t gmt_to_zone(ts_t gmt, TimeZone zone)
Convert GMT (UTC) to a supported local civil time zone.
ts_t pht_to_gmt(ts_t pht)
ts_t sgt_to_gmt(ts_t sgt)
ts_t ny_to_gmt(ts_t ny)
Convert New York Time to GMT (UTC).
ts_t gmt_to_wita(ts_t gmt)
ts_t et_to_gmt(ts_t et)
Convert US Eastern Time (New York, EST/EDT) to GMT (UTC).
ts_ms_t convert_time_zone_ms(ts_ms_t local_ms, TimeZone from, TimeZone to)
Convert a millisecond timestamp between two supported local civil time zones.
ts_t gmt_to_ct(ts_t gmt)
Convert GMT (UTC) to US Central Time (America/Chicago, CST/CDT).
TIME_SHIELD_CONSTEXPR ts_ms_t to_utc_ms(ts_ms_t local_ms, tz_t utc_offset) noexcept
Convert local timestamp (milliseconds) to UTC using UTC offset.
ts_t gmt_to_kst(ts_t gmt)
ts_t jst_to_gmt(ts_t jst)
ts_t myt_to_gmt(ts_t myt)
TIME_SHIELD_CONSTEXPR T1 ms_to_sec(T2 ts_ms) noexcept
Converts a timestamp from milliseconds to seconds.
TIME_SHIELD_CONSTEXPR T1 day_of_week_date(T2 year, T3 month, T4 day)
Get the day of the week.
TIME_SHIELD_CONSTEXPR T1 sec_to_ms(T2 ts) noexcept
Converts a timestamp from seconds to milliseconds.
@ OCT
October.
Definition enums.hpp:103
@ NOV
November.
Definition enums.hpp:104
@ MAR
March.
Definition enums.hpp:96
@ APR
April.
Definition enums.hpp:97
@ JST
Japan Standard Time.
Definition enums.hpp:200
@ GST
Gulf Standard Time.
Definition enums.hpp:198
@ PHT
Philippine Time.
Definition enums.hpp:197
@ BYT
Belarus Time.
Definition enums.hpp:194
@ KST
Korea Standard Time.
Definition enums.hpp:201
@ ET
US Eastern Time.
Definition enums.hpp:185
@ EET
Eastern European Time.
Definition enums.hpp:179
@ CEST
Central European Summer Time.
Definition enums.hpp:183
@ WIT
Eastern Indonesia Time.
Definition enums.hpp:191
@ WEST
Western European Summer Time.
Definition enums.hpp:184
@ WITA
Central Indonesia Time.
Definition enums.hpp:190
@ MYT
Malaysia Time.
Definition enums.hpp:188
@ HKT
Hong Kong Time.
Definition enums.hpp:199
@ WET
Western European Time.
Definition enums.hpp:181
@ KZT
Kazakhstan Time.
Definition enums.hpp:192
@ UNKNOWN
Unknown Time Zone.
Definition enums.hpp:202
@ TRT
Turkey Time.
Definition enums.hpp:193
@ UTC
Coordinated Universal Time.
Definition enums.hpp:178
@ ICT
Indochina Time.
Definition enums.hpp:196
@ GMT
Greenwich Mean Time.
Definition enums.hpp:177
@ SGT
Singapore Time.
Definition enums.hpp:195
@ WIB
Western Indonesia Time.
Definition enums.hpp:189
@ EEST
Eastern European Summer Time.
Definition enums.hpp:182
@ CT
US Central Time.
Definition enums.hpp:186
@ CET
Central European Time.
Definition enums.hpp:180
@ IST
India Standard Time.
Definition enums.hpp:187
@ SUN
Sunday.
Definition enums.hpp:28
TIME_SHIELD_CONSTEXPR T1 last_sunday_month_day(T2 year, T3 month)
Get the day of the last Sunday of the given month and year.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
TIME_SHIELD_CONSTEXPR T1 num_days_in_month(T2 year, T3 month) noexcept
Get the number of days in a month.
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition types.hpp:49
int32_t tz_t
Time zone offset in minutes from UTC (e.g., +180 = UTC+3).
Definition types.hpp:61
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
Definition types.hpp:50
bool fixed_zone_offset(TimeZone zone, tz_t &utc_offset)
ts_t gmt_to_european_local(ts_t gmt, int standard_offset_hours)
bool is_us_eastern_dst_local(const DateTimeStruct &dt)
ts_ms_t gmt_to_zone_ms_by_seconds(ts_ms_t gmt_ms, TimeZone zone)
ts_t european_local_to_gmt(ts_t local, int standard_offset_hours)
ts_ms_t zone_to_gmt_ms_by_seconds(ts_ms_t local_ms, TimeZone zone)
Main namespace for the Time Shield library.
Structure to represent date and time.
int hour
Hour component of time (0-23).
int64_t year
Year component of the date.
int day
Day component of the date (1-31).
int mon
Month component of the date (1-12).
Umbrella header for time conversion functions.
Helper functions for unit conversions between seconds, minutes, hours, and milliseconds.
UTC offset arithmetic helpers (UTC <-> local) and TimeZoneStruct offset extraction.