-
Notifications
You must be signed in to change notification settings - Fork 2
/
timezone.h
39 lines (31 loc) · 918 Bytes
/
timezone.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef TIMEZONE_H
#define TIMEZONE_H
const int UTCDifference = 1;
RtcDateTime ApplyTimezone(RtcDateTime utc)
{
// normal timezone difference from UTC
utc += UTCDifference * 3600;
// Daylight Saving Time
// determine last Sunday in March of current year
RtcDateTime start(utc.Year(), 3, 25, 2, 0, 0);
while (start.DayOfWeek() != 0) {
start += 86400;
}
// determine last Sunday in October of current year
RtcDateTime end(utc.Year(), 10, 25, 3, 0, 0);
while (end.DayOfWeek() != 0) {
end += 86400;
}
if (utc.Month() >= start.Month() && utc.Month() <= end.Month()) {
if (utc.Month() == start.Month() && utc.Day() >= start.Day()
&& utc.Hour() >= start.Hour()
|| utc.Month() == end.Month() && utc.Day() <= end.Day()
&& utc.Hour() <= end.Hour()) {
utc += 3600;
} else if (utc.Month() > start.Month() && utc.Month() < end.Month()) {
utc += 3600;
}
}
return utc;
}
#endif