]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Time/German.pm
added system independent German time support
[selfforum.git] / selfforum-cgi / shared / Time / German.pm
1 package Time::German;
2
3 ################################################################################
4 # #
5 # File: shared/Time/German.pm #
6 # #
7 # Authors: Andre Malo <nd@o3media.de>, 2001-06-10 #
8 # #
9 # Description: determine time offset German Time <=> GMT (seconds) #
10 # #
11 ################################################################################
12
13 use strict;
14
15 ################################################################################
16 #
17 # Export
18 #
19 use base 'Exporter';
20 @Time::German::EXPORT = qw(germantime);
21
22 ################################################################################
23 #
24 # german summertime 1980-1995 (ydays)
25 #
26 my %summertime = (
27 80 => [96, 271],
28 81 => [87, 269],
29 82 => [86, 268],
30 83 => [85, 267],
31 84 => [84, 273],
32 85 => [89, 271],
33 86 => [88, 270],
34 87 => [87, 269],
35 88 => [86, 268],
36 89 => [84, 266],
37 90 => [83, 272],
38 91 => [89, 271],
39 92 => [88, 270],
40 93 => [86, 268],
41 94 => [85, 267],
42 95 => [84, 266]
43 );
44
45 ### germantime () ##############################################################
46 #
47 # like 'localtime', but system independent
48 #
49 # Params: $time - time since epoch (GMT)
50 #
51 # Return: same as localtime, but german time ;-)
52 #
53 sub germantime (;$) {
54 my $time = shift;
55 $time = time unless defined $time;
56
57 my ($hour,$mday,$mon,$year,$wday,$yday) = (gmtime($time))[qw(2 3 4 5 6 7)];
58 my $offset = 1;
59
60 # 1980 - 1995
61 #
62 if ($summertime{$year}) {
63 $offset++ if (
64 (
65 $yday > $summertime{$year} -> [0] and
66 $yday < $summertime{$year} -> [1]
67 ) or
68 (
69 $yday == $summertime{$year} -> [0] and
70 $hour >= 1
71 ) or
72 (
73 $yday == $summertime{$year} -> [1] and
74 $hour <= 1
75 )
76 );
77 }
78
79 # > 1995
80 #
81 elsif ($year > 95) {
82 # determine last Sunday in March or October
83 #
84 my $limit = $mday + int((31-$mday)/7) * 7 - $wday if ($mon == 2 or $mon == 9);
85
86 $offset++ if (
87 (
88 $mon > 2 and
89 $mon < 9
90 ) or
91 (
92 $mon == 2 and
93 (
94 $mday > $limit or
95 $mday == $limit and
96 $hour >= 1
97 )
98 ) or
99 (
100 $mon == 9 and
101 (
102 $mday < $limit or
103 $mday == $limit and
104 $hour <= 1
105 )
106 )
107 );
108 }
109
110 return gmtime($time + $offset * 3600);
111 }
112
113 # keep 'require' happy
114 1;
115
116 #
117 #
118 ### end of Time::German ########################################################

patrick-canterino.de