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 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
31 if(dt.mon == MAR) {
32 for(int d = max_days; d >= dt.day; --d) {
33 if(day_of_week_date(dt.year, MAR, d) == SUN) {
34 if(d == dt.day) {
35 if(dt.hour >= OLD_START_SUMMER_HOUR)
36 return cet - SEC_PER_HOUR * 2;
37 return cet - SEC_PER_HOUR;
38 }
39 return cet - SEC_PER_HOUR;
40 }
41 }
42 return cet - SEC_PER_HOUR * 2;
43 } else if(dt.mon == OCT) {
44 for(int d = max_days; d >= dt.day; --d) {
45 if(day_of_week_date(dt.year, OCT, d) == SUN) {
46 if(d == dt.day) {
47 if(dt.hour >= OLD_STOP_SUMMER_HOUR)
48 return cet - SEC_PER_HOUR;
49 return cet - SEC_PER_HOUR;
50 }
51 return cet - SEC_PER_HOUR * 2;
52 }
53 }
54 return cet - SEC_PER_HOUR;
55 }
56 return cet - SEC_PER_HOUR;
57 } else {
58 if(dt.mon > MAR && dt.mon < OCT) {
59 return cet - SEC_PER_HOUR * 2;
60 } else
61 if(dt.mon == MAR) {
62 for(int d = max_days; d >= dt.day; --d) {
63 if(day_of_week_date(dt.year, MAR, d) == SUN) {
64 if(d == dt.day) {
65 if(dt.hour >= (NEW_SUMMER_HOUR + 2))
66 return cet - SEC_PER_HOUR * 2;
67 return cet - SEC_PER_HOUR;
68 }
69 return cet - SEC_PER_HOUR;
70 }
71 }
72 return cet - SEC_PER_HOUR * 2;
73 } else
74 if(dt.mon == OCT) {
75 for(int d = max_days; d >= dt.day; --d) {
76 if(day_of_week_date(dt.year, OCT, d) == SUN) {
77 if(d == dt.day) {
78 if(dt.hour >= (NEW_SUMMER_HOUR + 1))
79 return cet - SEC_PER_HOUR;
80 return cet - SEC_PER_HOUR * 2;
81 }
82 return cet - SEC_PER_HOUR * 2;
83 }
84 }
85 }
86 }
87 return cet - SEC_PER_HOUR;
88 }
89
93 inline ts_t eet_to_gmt(ts_t eet) {
94 return cet_to_gmt(eet - SEC_PER_HOUR);
95 }
96
98
99} // namespace time_shield
100
101#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.
ts_t eet_to_gmt(ts_t eet)
Convert Eastern European Time to Greenwich Mean Time.
ts_t cet_to_gmt(ts_t cet)
Convert Central European Time to Greenwich Mean Time.
constexpr T1 num_days_in_month(ts_t ts=time_shield::ts()) noexcept
Alias for num_days_in_month_ts function.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
constexpr T1 day_of_week_date(T2 year, T3 month, T4 day)
Get the day of the week.
@ 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.