|
1
|
#include <stdint.h>
|
|
2
|
|
|
3
|
static int last_sunday(int year, int month)
|
|
4
|
{
|
|
5
|
// Zeller’s congruence (modifiziert)
|
|
6
|
int m = month;
|
|
7
|
int y = year;
|
|
8
|
|
|
9
|
if (m == 1) { m = 13; y--; }
|
|
10
|
if (m == 2) { m = 14; y--; }
|
|
11
|
|
|
12
|
int K = y % 100;
|
|
13
|
int J = y / 100;
|
|
14
|
|
|
15
|
int h = (1 + (13 * (m + 1)) / 5 + K + K/4 + J/4 + 5*J) % 7;
|
|
16
|
|
|
17
|
// h = Wochentag des 1. des Monats (0=Samstag, 1=Sonntag, ...)
|
|
18
|
int weekday_first = ((h + 6) % 7); // 0=Sonntag, 1=Montag, ...
|
|
19
|
|
|
20
|
// Letzter Tag des Monats
|
|
21
|
static const int mdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
|
22
|
int days = mdays[month-1];
|
|
23
|
|
|
24
|
// Schaltjahr?
|
|
25
|
if (month == 2 && ((year%4==0 && year%100!=0) || (year%400==0)))
|
|
26
|
days = 29;
|
|
27
|
|
|
28
|
// Wochentag des letzten Tages
|
|
29
|
int weekday_last = (weekday_first + (days - 1)) % 7;
|
|
30
|
|
|
31
|
// Letzter Sonntag
|
|
32
|
return days - weekday_last;
|
|
33
|
}
|
|
34
|
|
|
35
|
int is_dst_europe(int year, int month, int day, int hour)
|
|
36
|
{
|
|
37
|
int start = last_sunday(year, 3); // letzter Sonntag im März
|
|
38
|
int end = last_sunday(year, 10); // letzter Sonntag im Oktober
|
|
39
|
|
|
40
|
// Vor Beginn der Sommerzeit
|
|
41
|
if (month < 3) return 0;
|
|
42
|
if (month > 10) return 0;
|
|
43
|
|
|
44
|
// Zwischen April und September immer Sommerzeit
|
|
45
|
if (month > 3 && month < 10) return 1;
|
|
46
|
|
|
47
|
// März: Wechsel um 02:00
|
|
48
|
if (month == 3) {
|
|
49
|
if (day < start) return 0;
|
|
50
|
if (day > start) return 1;
|
|
51
|
return (hour >= 2); // am Wechseltag ab 02:00 Sommerzeit
|
|
52
|
}
|
|
53
|
|
|
54
|
// Oktober: Wechsel um 03:00
|
|
55
|
if (month == 10) {
|
|
56
|
if (day < end) return 1;
|
|
57
|
if (day > end) return 0;
|
|
58
|
return (hour < 3); // am Wechseltag bis 03:00 Sommerzeit
|
|
59
|
}
|
|
60
|
|
|
61
|
return 0; // sollte nie erreicht werden
|
|
62
|
}
|