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#pragma once
2#ifndef _TIME_SHIELD_TIME_ZONE_CONVERSIONS_HPP_INCLUDED
3#define _TIME_SHIELD_TIME_ZONE_CONVERSIONS_HPP_INCLUDED
4
8
10#include "time_conversions.hpp"
11
12namespace time_shield {
13
16
20 inline const ts_t cet_to_gmt(ts_t cet) {
22 int max_days = num_days_in_month(dt.year, dt.mon);
23 const int OLD_START_SUMMER_HOUR = 2;
24 const int OLD_STOP_SUMMER_HOUR = 3;
25 const int NEW_SUMMER_HOUR = 1;
26
27 if(dt.year < 2002) {
28 if(dt.mon > MAR && dt.mon < OCT)
29 return cet - SEC_PER_HOUR * 2;
30 else if(dt.mon == MAR) {
31 for(int d = max_days; d >= dt.day; --d) {
32 if(day_of_week_date(dt.year, MAR, d) == SUN) {
33 if(d == dt.day) {
34 if(dt.hour >= OLD_START_SUMMER_HOUR)
35 return cet - SEC_PER_HOUR * 2;
36 return cet - SEC_PER_HOUR;
37 }
38 return cet - SEC_PER_HOUR;
39 }
40 }
41 return cet - SEC_PER_HOUR * 2;
42 } else if(dt.mon == OCT) {
43 for(int d = max_days; d >= dt.day; --d) {
44 if(day_of_week_date(dt.year, OCT, d) == SUN) {
45 if(d == dt.day) {
46 if(dt.hour >= OLD_STOP_SUMMER_HOUR)
47 return cet - SEC_PER_HOUR;
48 return cet - SEC_PER_HOUR;
49 }
50 return cet - SEC_PER_HOUR * 2;
51 }
52 }
53 return cet - SEC_PER_HOUR;
54 }
55 return cet - SEC_PER_HOUR;
56 } else {
57 if(dt.mon > MAR && dt.mon < OCT)
58 return cet - SEC_PER_HOUR * 2;
59 else if(dt.mon == MAR) {
60 for(int d = max_days; d >= dt.day; --d) {
61 if(day_of_week_date(dt.year, MAR, d) == SUN) {
62 if(d == dt.day) {
63 if(dt.hour >= (NEW_SUMMER_HOUR + 2))
64 return cet - SEC_PER_HOUR * 2;
65 return cet - SEC_PER_HOUR;
66 }
67 return cet - SEC_PER_HOUR;
68 }
69 }
70 return cet - SEC_PER_HOUR * 2;
71 } else if(dt.mon == OCT) {
72 for(int d = max_days; d >= dt.day; --d) {
73 if(day_of_week_date(dt.year, OCT, d) == SUN) {
74 if(d == dt.day) {
75 if(dt.hour >= (NEW_SUMMER_HOUR + 1))
76 return cet - SEC_PER_HOUR;
77 return cet - SEC_PER_HOUR * 2;
78 }
79 return cet - SEC_PER_HOUR * 2;
80 }
81 }
82 return cet - SEC_PER_HOUR;
83 }
84 return cet - SEC_PER_HOUR;
85 }
86 return cet - SEC_PER_HOUR;
87 }
88
92 inline const ts_t eet_to_gmt(ts_t eet) {
93 return cet_to_gmt(eet - SEC_PER_HOUR);
94 }
95
97
98} // namespace time_shield
99
100#endif // _TIME_SHIELD_TIME_ZONE_CONVERSIONS_HPP_INCLUDED
Header for date and time structure and related functions.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
Definition constants.hpp:69
const ts_t eet_to_gmt(ts_t eet)
Convert Eastern European Time to Greenwich Mean Time.
const ts_t cet_to_gmt(ts_t cet)
Convert Central European Time to Greenwich Mean Time.
constexpr const T1 num_days_in_month(ts_t ts=time_shield::ts()) noexcept
Alias for num_days_in_month_ts function.
constexpr const T1 day_of_week_date(T2 year, T3 month, T4 day)
Get the day of the week.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
@ OCT
October.
Definition enums.hpp:102
@ MAR
March.
Definition enums.hpp:95
@ SUN
Sunday.
Definition enums.hpp:27
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition types.hpp:45
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).
Header file for time conversion functions.