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

patrick-canterino.de