File | /wise/base/static/lib/perl5/site_perl/5.10.0/Time/Timezone.pm | Statements Executed | 29 | Total Time | 0.001387 seconds |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine | |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | Time::Timezone:: | BEGIN |
0 | 0 | 0 | 0 | 0 | Time::Timezone:: | calc_off |
0 | 0 | 0 | 0 | 0 | Time::Timezone:: | tz2zone |
0 | 0 | 0 | 0 | 0 | Time::Timezone:: | tz_local_offset |
0 | 0 | 0 | 0 | 0 | Time::Timezone:: | tz_name |
0 | 0 | 0 | 0 | 0 | Time::Timezone:: | tz_offset |
Line | Stmts. | Exclusive Time | Avg. | Code |
---|---|---|---|---|
1 | ||||
2 | package Time::Timezone; | |||
3 | ||||
4 | 1 | 1.7e-5 | 1.7e-5 | require 5.002; |
5 | ||||
6 | 1 | 1.0e-6 | 1.0e-6 | require Exporter; |
7 | 1 | 6.0e-6 | 6.0e-6 | @ISA = qw(Exporter); |
8 | 1 | 2.0e-6 | 2.0e-6 | @EXPORT = qw(tz2zone tz_local_offset tz_offset tz_name); |
9 | 1 | 0 | 0 | @EXPORT_OK = qw(); |
10 | ||||
11 | 3 | 3.0e-5 | 1.0e-5 | use Carp; # spent 59µs making 1 call to Exporter::import |
12 | 3 | 2.9e-5 | 9.7e-6 | use strict; # spent 9µs making 1 call to strict::import |
13 | ||||
14 | # Parts stolen from code by Paul Foley <paul@ascent.com> | |||
15 | ||||
16 | 3 | 4.8e-5 | 1.6e-5 | use vars qw($VERSION); # spent 25µs making 1 call to vars::import |
17 | ||||
18 | 1 | 1.0e-6 | 1.0e-6 | $VERSION = 2006.0814; |
19 | ||||
20 | sub tz2zone | |||
21 | { | |||
22 | my($TZ, $time, $isdst) = @_; | |||
23 | ||||
24 | 3 | 0.00043 | 0.00014 | use vars qw(%tzn_cache); # spent 23µs making 1 call to vars::import |
25 | ||||
26 | $TZ = defined($ENV{'TZ'}) ? ( $ENV{'TZ'} ? $ENV{'TZ'} : 'GMT' ) : '' | |||
27 | unless $TZ; | |||
28 | ||||
29 | # Hack to deal with 'PST8PDT' format of TZ | |||
30 | # Note that this can't deal with all the esoteric forms, but it | |||
31 | # does recognize the most common: [:]STDoff[DST[off][,rule]] | |||
32 | ||||
33 | if (! defined $isdst) { | |||
34 | my $j; | |||
35 | $time = time() unless $time; | |||
36 | ($j, $j, $j, $j, $j, $j, $j, $j, $isdst) = localtime($time); | |||
37 | } | |||
38 | ||||
39 | if (defined $tzn_cache{$TZ}->[$isdst]) { | |||
40 | return $tzn_cache{$TZ}->[$isdst]; | |||
41 | } | |||
42 | ||||
43 | if ($TZ =~ /^ | |||
44 | ( [^:\d+\-,] {3,} ) | |||
45 | ( [+-] ? | |||
46 | \d {1,2} | |||
47 | ( : \d {1,2} ) {0,2} | |||
48 | ) | |||
49 | ( [^\d+\-,] {3,} )? | |||
50 | /x | |||
51 | ) { | |||
52 | $TZ = $isdst ? $4 : $1; | |||
53 | $tzn_cache{$TZ} = [ $1, $4 ]; | |||
54 | } else { | |||
55 | $tzn_cache{$TZ} = [ $TZ, $TZ ]; | |||
56 | } | |||
57 | return $TZ; | |||
58 | } | |||
59 | ||||
60 | sub tz_local_offset | |||
61 | { | |||
62 | my ($time) = @_; | |||
63 | ||||
64 | $time = time() unless $time; | |||
65 | my (@l) = localtime($time); | |||
66 | my $isdst = $l[8] || 0; | |||
67 | my $tzenv = defined($ENV{TZ}) ? $ENV{TZ} : "__notz"; | |||
68 | ||||
69 | if ($Timezone::tz_local{$tzenv} && | |||
70 | defined($Timezone::tz_local{$tzenv}[$isdst])) { | |||
71 | return $Timezone::tz_local{$tzenv}[$isdst]; | |||
72 | } | |||
73 | ||||
74 | $Timezone::tz_local{$tzenv}[$isdst] = &calc_off($time); | |||
75 | ||||
76 | return $Timezone::tz_local{$tzenv}[$isdst]; | |||
77 | } | |||
78 | ||||
79 | sub calc_off | |||
80 | { | |||
81 | my ($time) = @_; | |||
82 | ||||
83 | my (@l) = localtime($time); | |||
84 | my (@g) = gmtime($time); | |||
85 | ||||
86 | my $off; | |||
87 | ||||
88 | $off = $l[0] - $g[0] | |||
89 | + ($l[1] - $g[1]) * 60 | |||
90 | + ($l[2] - $g[2]) * 3600; | |||
91 | ||||
92 | # subscript 7 is yday. | |||
93 | ||||
94 | if ($l[7] == $g[7]) { | |||
95 | # done | |||
96 | } elsif ($l[7] == $g[7] + 1) { | |||
97 | $off += 86400; | |||
98 | } elsif ($l[7] == $g[7] - 1) { | |||
99 | $off -= 86400; | |||
100 | } elsif ($l[7] < $g[7]) { | |||
101 | # crossed over a year boundry! | |||
102 | # localtime is beginning of year, gmt is end | |||
103 | # therefore local is ahead | |||
104 | $off += 86400; | |||
105 | } else { | |||
106 | $off -= 86400; | |||
107 | } | |||
108 | ||||
109 | return $off; | |||
110 | } | |||
111 | ||||
112 | # constants | |||
113 | # The rest of the file originally comes from Graham Barr <bodg@tiuk.ti.com> | |||
114 | # | |||
115 | # Some references: | |||
116 | # http://www.weltzeituhr.com/laender/zeitzonen_e.shtml | |||
117 | # http://www.worldtimezone.com/wtz-names/timezonenames.html | |||
118 | # http://www.timegenie.com/timezones.php | |||
119 | ||||
120 | 1 | 9.0e-6 | 9.0e-6 | CONFIG: { # spent 65µs making 1 call to vars::import |
121 | 3 | 0.00063 | 0.00021 | use vars qw(%dstZone %zoneOff %dstZoneOff %Zone); |
122 | ||||
123 | 1 | 3.4e-5 | 3.4e-5 | %dstZone = ( |
124 | "brst" => -2*3600, # Brazil Summer Time (East Daylight) | |||
125 | "adt" => -3*3600, # Atlantic Daylight | |||
126 | "edt" => -4*3600, # Eastern Daylight | |||
127 | "cdt" => -5*3600, # Central Daylight | |||
128 | "mdt" => -6*3600, # Mountain Daylight | |||
129 | "pdt" => -7*3600, # Pacific Daylight | |||
130 | "ydt" => -8*3600, # Yukon Daylight | |||
131 | "hdt" => -9*3600, # Hawaii Daylight | |||
132 | "bst" => +1*3600, # British Summer | |||
133 | "mest" => +2*3600, # Middle European Summer | |||
134 | "met dst" => +2*3600, # Middle European Summer | |||
135 | "sst" => +2*3600, # Swedish Summer | |||
136 | "fst" => +2*3600, # French Summer | |||
137 | "eest" => +3*3600, # Eastern European Summer | |||
138 | "cest" => +2*3600, # Central European Daylight | |||
139 | "wadt" => +8*3600, # West Australian Daylight | |||
140 | "kdt" => +10*3600, # Korean Daylight | |||
141 | # "cadt" => +10*3600+1800, # Central Australian Daylight | |||
142 | "eadt" => +11*3600, # Eastern Australian Daylight | |||
143 | "nzdt" => +13*3600, # New Zealand Daylight | |||
144 | ); | |||
145 | ||||
146 | # not included due to ambiguity: | |||
147 | # IST Indian Standard Time +5.5 | |||
148 | # Ireland Standard Time 0 | |||
149 | # Israel Standard Time +2 | |||
150 | # IDT Ireland Daylight Time +1 | |||
151 | # Israel Daylight Time +3 | |||
152 | # AMST Amazon Standard Time / -3 | |||
153 | # Armenia Standard Time +8 | |||
154 | # BST Brazil Standard -3 | |||
155 | ||||
156 | 1 | 3.5e-5 | 3.5e-5 | %Zone = ( |
157 | "gmt" => 0, # Greenwich Mean | |||
158 | "ut" => 0, # Universal (Coordinated) | |||
159 | "utc" => 0, | |||
160 | "wet" => 0, # Western European | |||
161 | "wat" => -1*3600, # West Africa | |||
162 | "azost" => -1*3600, # Azores Standard Time | |||
163 | "cvt" => -1*3600, # Cape Verde Time | |||
164 | "at" => -2*3600, # Azores | |||
165 | "fnt" => -2*3600, # Brazil Time (Extreme East - Fernando Noronha) | |||
166 | "ndt" => -2*3600-1800,# Newfoundland Daylight | |||
167 | "art" => -3*3600, # Argentina Time | |||
168 | # For completeness. BST is also British Summer, and GST is also Guam Standard. | |||
169 | # "gst" => -3*3600, # Greenland Standard | |||
170 | "nft" => -3*3600-1800,# Newfoundland | |||
171 | # "nst" => -3*3600-1800,# Newfoundland Standard | |||
172 | "mnt" => -4*3600, # Brazil Time (West Standard - Manaus) | |||
173 | "ewt" => -4*3600, # U.S. Eastern War Time | |||
174 | "ast" => -4*3600, # Atlantic Standard | |||
175 | "bot" => -4*3600, # Bolivia Time | |||
176 | "vet" => -4*3600, # Venezuela Time | |||
177 | "est" => -5*3600, # Eastern Standard | |||
178 | "cot" => -5*3600, # Colombia Time | |||
179 | "act" => -5*3600, # Brazil Time (Extreme West - Acre) | |||
180 | "pet" => -5*3600, # Peru Time | |||
181 | "cst" => -6*3600, # Central Standard | |||
182 | "cest" => +2*3600, # Central European Summer | |||
183 | "mst" => -7*3600, # Mountain Standard | |||
184 | "pst" => -8*3600, # Pacific Standard | |||
185 | "yst" => -9*3600, # Yukon Standard | |||
186 | "hst" => -10*3600, # Hawaii Standard | |||
187 | "cat" => -10*3600, # Central Alaska | |||
188 | "ahst" => -10*3600, # Alaska-Hawaii Standard | |||
189 | "taht" => -10*3600, # Tahiti Time | |||
190 | "nt" => -11*3600, # Nome | |||
191 | "idlw" => -12*3600, # International Date Line West | |||
192 | "cet" => +1*3600, # Central European | |||
193 | "mez" => +1*3600, # Central European (German) | |||
194 | "met" => +1*3600, # Middle European | |||
195 | "mewt" => +1*3600, # Middle European Winter | |||
196 | "swt" => +1*3600, # Swedish Winter | |||
197 | "set" => +1*3600, # Seychelles | |||
198 | "fwt" => +1*3600, # French Winter | |||
199 | "west" => +1*3600, # Western Europe Summer Time | |||
200 | "eet" => +2*3600, # Eastern Europe, USSR Zone 1 | |||
201 | "ukr" => +2*3600, # Ukraine | |||
202 | "sast" => +2*3600, # South Africa Standard Time | |||
203 | "bt" => +3*3600, # Baghdad, USSR Zone 2 | |||
204 | "eat" => +3*3600, # East Africa Time | |||
205 | # "it" => +3*3600+1800,# Iran | |||
206 | "irst" => +3*3600+1800,# Iran Standard Time | |||
207 | "zp4" => +4*3600, # USSR Zone 3 | |||
208 | "msd" => +4*3600, # Moscow Daylight Time | |||
209 | "sct" => +4*3600, # Seychelles Time | |||
210 | "zp5" => +5*3600, # USSR Zone 4 | |||
211 | "azst" => +5*3600, # Azerbaijan Summer Time | |||
212 | "mvt" => +5*3600, # Maldives Time | |||
213 | "uzt" => +5*3600, # Uzbekistan Time | |||
214 | "ist" => +5*3600+1800,# Indian Standard | |||
215 | "zp6" => +6*3600, # USSR Zone 5 | |||
216 | "lkt" => +6*3600, # Sri Lanka Time | |||
217 | "pkst" => +6*3600, # Pakistan Summer Time | |||
218 | "yekst" => +6*3600, # Yekaterinburg Summer Time | |||
219 | # For completeness. NST is also Newfoundland Stanard, and SST is also Swedish Summer. | |||
220 | # "nst" => +6*3600+1800,# North Sumatra | |||
221 | # "sst" => +7*3600, # South Sumatra, USSR Zone 6 | |||
222 | "wast" => +7*3600, # West Australian Standard | |||
223 | "ict" => +7*3600, # Indochina Time | |||
224 | "wit" => +7*3600, # Western Indonesia Time | |||
225 | # "jt" => +7*3600+1800,# Java (3pm in Cronusland!) | |||
226 | "cct" => +8*3600, # China Coast, USSR Zone 7 | |||
227 | "wst" => +8*3600, # West Australian Standard | |||
228 | "hkt" => +8*3600, # Hong Kong | |||
229 | "bnt" => +8*3600, # Brunei Darussalam Time | |||
230 | "cit" => +8*3600, # Central Indonesia Time | |||
231 | "myt" => +8*3600, # Malaysia Time | |||
232 | "pht" => +8*3600, # Philippines Time | |||
233 | "sgt" => +8*3600, # Singapore Time | |||
234 | "jst" => +9*3600, # Japan Standard, USSR Zone 8 | |||
235 | "kst" => +9*3600, # Korean Standard | |||
236 | # "cast" => +9*3600+1800,# Central Australian Standard | |||
237 | "east" => +10*3600, # Eastern Australian Standard | |||
238 | "gst" => +10*3600, # Guam Standard, USSR Zone 9 | |||
239 | "nct" => +11*3600, # New Caledonia Time | |||
240 | "nzt" => +12*3600, # New Zealand | |||
241 | "nzst" => +12*3600, # New Zealand Standard | |||
242 | "fjt" => +12*3600, # Fiji Time | |||
243 | "idle" => +12*3600, # International Date Line East | |||
244 | ); | |||
245 | ||||
246 | 1 | 6.4e-5 | 6.4e-5 | %zoneOff = reverse(%Zone); |
247 | 1 | 1.9e-5 | 1.9e-5 | %dstZoneOff = reverse(%dstZone); |
248 | ||||
249 | # Preferences | |||
250 | ||||
251 | 1 | 1.0e-6 | 1.0e-6 | $zoneOff{0} = 'gmt'; |
252 | 1 | 1.0e-6 | 1.0e-6 | $dstZoneOff{3600} = 'bst'; |
253 | ||||
254 | } | |||
255 | ||||
256 | sub tz_offset | |||
257 | { | |||
258 | my ($zone, $time) = @_; | |||
259 | ||||
260 | return &tz_local_offset() unless($zone); | |||
261 | ||||
262 | $time = time() unless $time; | |||
263 | my(@l) = localtime($time); | |||
264 | my $dst = $l[8]; | |||
265 | ||||
266 | $zone = lc $zone; | |||
267 | ||||
268 | if ($zone =~ /^([\-\+]\d{3,4})$/) { | |||
269 | my $sign = $1 < 0 ? -1 : 1 ; | |||
270 | my $v = abs(0 + $1); | |||
271 | return $sign * 60 * (int($v / 100) * 60 + ($v % 100)); | |||
272 | } elsif (exists $dstZone{$zone} && ($dst || !exists $Zone{$zone})) { | |||
273 | return $dstZone{$zone}; | |||
274 | } elsif(exists $Zone{$zone}) { | |||
275 | return $Zone{$zone}; | |||
276 | } | |||
277 | undef; | |||
278 | } | |||
279 | ||||
280 | sub tz_name | |||
281 | { | |||
282 | my ($off, $time) = @_; | |||
283 | ||||
284 | $time = time() unless $time; | |||
285 | my(@l) = localtime($time); | |||
286 | my $dst = $l[8]; | |||
287 | ||||
288 | if (exists $dstZoneOff{$off} && ($dst || !exists $zoneOff{$off})) { | |||
289 | return $dstZoneOff{$off}; | |||
290 | } elsif (exists $zoneOff{$off}) { | |||
291 | return $zoneOff{$off}; | |||
292 | } | |||
293 | sprintf("%+05d", int($off / 60) * 100 + $off % 60); | |||
294 | } | |||
295 | ||||
296 | 1 | 3.1e-5 | 3.1e-5 | 1; |
297 | ||||
298 | __END__ | |||
299 | ||||
300 | =head1 NAME | |||
301 | ||||
302 | Time::Timezone -- miscellaneous timezone manipulations routines | |||
303 | ||||
304 | =head1 SYNOPSIS | |||
305 | ||||
306 | use Time::Timezone; | |||
307 | print tz2zone(); | |||
308 | print tz2zone($ENV{'TZ'}); | |||
309 | print tz2zone($ENV{'TZ'}, time()); | |||
310 | print tz2zone($ENV{'TZ'}, undef, $isdst); | |||
311 | $offset = tz_local_offset(); | |||
312 | $offset = tz_offset($TZ); | |||
313 | ||||
314 | =head1 DESCRIPTION | |||
315 | ||||
316 | This is a collection of miscellaneous timezone manipulation routines. | |||
317 | ||||
318 | C<tz2zone()> parses the TZ environment variable and returns a timezone | |||
319 | string suitable for inclusion in L<date>-like output. It opionally takes | |||
320 | a timezone string, a time, and a is-dst flag. | |||
321 | ||||
322 | C<tz_local_offset()> determins the offset from GMT time in seconds. It | |||
323 | only does the calculation once. | |||
324 | ||||
325 | C<tz_offset()> determines the offset from GMT in seconds of a specified | |||
326 | timezone. | |||
327 | ||||
328 | C<tz_name()> determines the name of the timezone based on its offset | |||
329 | ||||
330 | =head1 AUTHORS | |||
331 | ||||
332 | Graham Barr <bodg@tiuk.ti.com> | |||
333 | David Muir Sharnoff <muir@idiom.com> | |||
334 | Paul Foley <paul@ascent.com> | |||
335 | ||||
336 | =head1 LICENSE | |||
337 | ||||
338 | David Muir Sharnoff disclaims any copyright and puts his contribution | |||
339 | to this module in the public domain. | |||
340 |