]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Time/German.pm
German.pm: added version check, turned 'germantime' to 'localtime'. Time::German...
[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 use vars qw(
15 @EXPORT
16 $VERSION
17 );
18
19 ################################################################################
20 #
21 # Version check
22 #
23 $VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
24
25 ################################################################################
26 #
27 # Export
28 #
29 use base 'Exporter';
30 @EXPORT = qw(localtime);
31
32 ################################################################################
33 #
34 # german summertime 1980-1995 (ydays)
35 #
36 my %summertime = (
37 80 => [96, 271],
38 81 => [87, 269],
39 82 => [86, 268],
40 83 => [85, 267],
41 84 => [84, 273],
42 85 => [89, 271],
43 86 => [88, 270],
44 87 => [87, 269],
45 88 => [86, 268],
46 89 => [84, 266],
47 90 => [83, 272],
48 91 => [89, 271],
49 92 => [88, 270],
50 93 => [86, 268],
51 94 => [85, 267],
52 95 => [84, 266]
53 );
54
55 ### localtime () ###############################################################
56 #
57 # like 'localtime', but system independent
58 #
59 # Params: $time - time since epoch (GMT)
60 #
61 # Return: same as localtime, but german time ;-)
62 #
63 sub localtime (;$) {
64 my $time = shift;
65 $time = time unless defined $time;
66
67 my ($hour,$mday,$mon,$year,$wday,$yday) = (gmtime($time))[qw(2 3 4 5 6 7)];
68 my $offset = 1;
69
70 # 1980 - 1995
71 #
72 if ($summertime{$year}) {
73 $offset++ if (
74 (
75 $yday > $summertime{$year} -> [0] and
76 $yday < $summertime{$year} -> [1]
77 ) or
78 (
79 $yday == $summertime{$year} -> [0] and
80 $hour >= 1
81 ) or
82 (
83 $yday == $summertime{$year} -> [1] and
84 $hour <= 1
85 )
86 );
87 }
88
89 # > 1995
90 #
91 elsif ($year > 95) {
92 # determine last Sunday in March or October
93 #
94 my $limit = $mday + int((31-$mday)/7) * 7 - $wday if ($mon == 2 or $mon == 9);
95
96 $offset++ if (
97 (
98 $mon > 2 and
99 $mon < 9
100 ) or
101 (
102 $mon == 2 and
103 (
104 $mday > $limit or
105 $mday == $limit and
106 $hour >= 1
107 )
108 ) or
109 (
110 $mon == 9 and
111 (
112 $mday < $limit or
113 $mday == $limit and
114 $hour <= 1
115 )
116 )
117 );
118 }
119
120 return gmtime($time + $offset * 3600);
121 }
122
123 # keep 'require' happy
124 1;
125
126 #
127 #
128 ### end of Time::German ########################################################

patrick-canterino.de