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

patrick-canterino.de