Filename | /usr/share/perl5/Date/Manip/TZ.pm |
Statements | Executed 394 statements in 10.2ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 2 | 1 | 513µs | 762µs | _module | Date::Manip::TZ::
2 | 1 | 1 | 392µs | 777µs | _get_curr_zone | Date::Manip::TZ::
1 | 1 | 1 | 115µs | 962µs | zone | Date::Manip::TZ::
2 | 1 | 1 | 103µs | 157µs | _init | Date::Manip::TZ::
3 | 2 | 1 | 97µs | 117µs | _all_periods | Date::Manip::TZ::
2 | 2 | 2 | 88µs | 174µs | date_period | Date::Manip::TZ::
10 | 7 | 2 | 63µs | 63µs | _zone | Date::Manip::TZ::
1 | 1 | 1 | 40µs | 78µs | BEGIN@586 | Date::Manip::TZ::
1 | 1 | 1 | 35µs | 103µs | _convert | Date::Manip::TZ::
2 | 1 | 1 | 26µs | 810µs | _set_curr_zone | Date::Manip::TZ::
4 | 1 | 1 | 26µs | 26µs | CORE:ftfile (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 25µs | 39µs | BEGIN@18 | Date::Manip::TZ::
1 | 1 | 1 | 23µs | 137µs | convert_to_gmt | Date::Manip::TZ::
1 | 1 | 1 | 22µs | 24µs | BEGIN@14 | Date::Manip::TZ::
8 | 3 | 1 | 22µs | 22µs | CORE:match (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 20µs | 23µs | BEGIN@24 | Date::Manip::TZ::
1 | 1 | 1 | 18µs | 41µs | BEGIN@1446 | Date::Manip::TZ::
1 | 1 | 1 | 18µs | 18µs | _periods | Date::Manip::TZ::
1 | 1 | 1 | 17µs | 35µs | BEGIN@1450 | Date::Manip::TZ::
1 | 1 | 1 | 16µs | 82µs | BEGIN@17 | Date::Manip::TZ::
1 | 1 | 1 | 15µs | 245µs | BEGIN@22 | Date::Manip::TZ::
2 | 1 | 1 | 14µs | 824µs | _init_final | Date::Manip::TZ::
1 | 1 | 1 | 14µs | 53µs | BEGIN@26 | Date::Manip::TZ::
1 | 1 | 1 | 14µs | 31µs | BEGIN@596 | Date::Manip::TZ::
1 | 1 | 1 | 12µs | 29µs | BEGIN@137 | Date::Manip::TZ::
1 | 1 | 1 | 11µs | 23µs | BEGIN@20 | Date::Manip::TZ::
1 | 1 | 1 | 11µs | 11µs | _convert_args | Date::Manip::TZ::
1 | 1 | 1 | 11µs | 14µs | BEGIN@19 | Date::Manip::TZ::
1 | 1 | 1 | 11µs | 25µs | BEGIN@168 | Date::Manip::TZ::
6 | 3 | 1 | 9µs | 9µs | CORE:subst (opcode) | Date::Manip::TZ::
2 | 1 | 1 | 5µs | 5µs | CORE:readline (opcode) | Date::Manip::TZ::
2 | 1 | 1 | 5µs | 5µs | CORE:close (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 3µs | 3µs | CORE:sort (opcode) | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _abbrx | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _check_abbrev_isdst | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _check_offset_abbrev_isdst | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _cmd | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _lastrule | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _list_add | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _list_union | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _offmod | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _offrx | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _sortByLength | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _windows_registry_val | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _zonerx | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _zrx | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | all_periods | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | convert | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | convert_from_gmt | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | convert_from_local | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | convert_to_local | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | curr_zone | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | curr_zone_methods | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | define_abbrev | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | define_alias | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | define_offset | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | periods | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | tzcode | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | tzdata | Date::Manip::TZ::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
0 | 1 | 82µs | Profile data that couldn't be associated with a specific line: # spent 82µs making 1 call to Date::Manip::TZ::BEGIN@17 | ||
1 | 1 | 7µs | package Date::Manip::TZ; | ||
2 | # Copyright (c) 2008-2010 Sullivan Beck. All rights reserved. | ||||
3 | # This program is free software; you can redistribute it and/or modify it | ||||
4 | # under the same terms as Perl itself. | ||||
5 | |||||
6 | ######################################################################## | ||||
7 | # Any routine that starts with an underscore (_) is NOT intended for | ||||
8 | # public use. They are for internal use in the the Date::Manip | ||||
9 | # modules and are subject to change without warning or notice. | ||||
10 | # | ||||
11 | # ABSOLUTELY NO USER SUPPORT IS OFFERED FOR THESE ROUTINES! | ||||
12 | ######################################################################## | ||||
13 | |||||
14 | 3 | 45µs | 2 | 27µs | # spent 24µs (22+2) within Date::Manip::TZ::BEGIN@14 which was called:
# once (22µs+2µs) by Date::Manip::Obj::BEGIN@16 at line 14 # spent 24µs making 1 call to Date::Manip::TZ::BEGIN@14
# spent 2µs making 1 call to UNIVERSAL::import |
15 | 1 | 14µs | @ISA = ('Date::Manip::Obj'); | ||
16 | |||||
17 | 4 | 78µs | 1 | 66µs | # spent 82µs (16+66) within Date::Manip::TZ::BEGIN@17 which was called:
# once (16µs+66µs) by Date::Manip::Obj::BEGIN@16 at line 0 # spent 66µs making 1 call to feature::import |
18 | 3 | 30µs | 2 | 54µs | # spent 39µs (25+14) within Date::Manip::TZ::BEGIN@18 which was called:
# once (25µs+14µs) by Date::Manip::Obj::BEGIN@16 at line 18 # spent 39µs making 1 call to Date::Manip::TZ::BEGIN@18
# spent 14µs making 1 call to warnings::import |
19 | 3 | 28µs | 2 | 17µs | # spent 14µs (11+3) within Date::Manip::TZ::BEGIN@19 which was called:
# once (11µs+3µs) by Date::Manip::Obj::BEGIN@16 at line 19 # spent 14µs making 1 call to Date::Manip::TZ::BEGIN@19
# spent 3µs making 1 call to strict::import |
20 | 3 | 28µs | 2 | 35µs | # spent 23µs (11+12) within Date::Manip::TZ::BEGIN@20 which was called:
# once (11µs+12µs) by Date::Manip::Obj::BEGIN@16 at line 20 # spent 23µs making 1 call to Date::Manip::TZ::BEGIN@20
# spent 12µs making 1 call to feature::import |
21 | |||||
22 | 3 | 43µs | 2 | 476µs | # spent 245µs (15+231) within Date::Manip::TZ::BEGIN@22 which was called:
# once (15µs+231µs) by Date::Manip::Obj::BEGIN@16 at line 22 # spent 245µs making 1 call to Date::Manip::TZ::BEGIN@22
# spent 231µs making 1 call to Exporter::import |
23 | 1 | 340µs | require Date::Manip::Zones; | ||
24 | 3 | 38µs | 2 | 25µs | # spent 23µs (20+2) within Date::Manip::TZ::BEGIN@24 which was called:
# once (20µs+2µs) by Date::Manip::Obj::BEGIN@16 at line 24 # spent 23µs making 1 call to Date::Manip::TZ::BEGIN@24
# spent 2µs making 1 call to UNIVERSAL::import |
25 | |||||
26 | 3 | 400µs | 2 | 92µs | # spent 53µs (14+39) within Date::Manip::TZ::BEGIN@26 which was called:
# once (14µs+39µs) by Date::Manip::Obj::BEGIN@16 at line 26 # spent 53µs making 1 call to Date::Manip::TZ::BEGIN@26
# spent 39µs making 1 call to vars::import |
27 | 1 | 3µs | $VERSION='6.11'; | ||
28 | |||||
29 | ######################################################################## | ||||
30 | # BASE METHODS | ||||
31 | ######################################################################## | ||||
32 | |||||
33 | # spent 157µs (103+54) within Date::Manip::TZ::_init which was called 2 times, avg 78µs/call:
# 2 times (103µs+54µs) by Date::Manip::Obj::new at line 152 of Date/Manip/Obj.pm, avg 78µs/call | ||||
34 | 2 | 3µs | my($self) = @_; | ||
35 | |||||
36 | 2 | 56µs | $$self{'data'} = | ||
37 | { | ||||
38 | # These are the variables defined in Date::Manip::Zones | ||||
39 | 'Module' => \%Date::Manip::Zones::Module, | ||||
40 | 'ZoneNames' => \%Date::Manip::Zones::ZoneNames, | ||||
41 | 'Alias' => \%Date::Manip::Zones::Alias, | ||||
42 | 'Abbrev' => \%Date::Manip::Zones::Abbrev, | ||||
43 | 'Offmod' => \%Date::Manip::Zones::Offmod, | ||||
44 | 'FirstDate' => $Date::Manip::Zones::FirstDate, | ||||
45 | 'LastDate' => $Date::Manip::Zones::LastDate, | ||||
46 | 'LastYear' => $Date::Manip::Zones::LastYear, | ||||
47 | |||||
48 | # These override values from Date::Manip::Zones | ||||
49 | 'MyAlias' => {}, | ||||
50 | 'MyAbbrev' => {}, | ||||
51 | 'MyOffsets' => {}, | ||||
52 | |||||
53 | # Each timezone/offset module that is loaded goes here | ||||
54 | 'Zones' => {}, | ||||
55 | 'Offsets' => {}, | ||||
56 | |||||
57 | # methods a list of methods used for determining the | ||||
58 | # current zone | ||||
59 | # dates critical dates on a per/year (UT) basis | ||||
60 | # zonerx the regular expression for matching timezone | ||||
61 | # names/aliases | ||||
62 | # abbrx the regular expression for matching timezone | ||||
63 | # abbreviations | ||||
64 | # offrx the regular expression for matching a valid | ||||
65 | # timezone offset | ||||
66 | # zrx the regular expression to match all timezone | ||||
67 | # information | ||||
68 | 'methods' => [], | ||||
69 | 'zonerx' => undef, | ||||
70 | 'abbrx' => undef, | ||||
71 | 'offrx' => undef, | ||||
72 | 'zrx' => undef, | ||||
73 | }; | ||||
74 | |||||
75 | # OS specific stuff | ||||
76 | |||||
77 | 2 | 3µs | my $dmb = $$self{'objs'}{'base'}; | ||
78 | 2 | 6µs | 2 | 54µs | my $os = $dmb->_os(); # spent 54µs making 2 calls to Date::Manip::Base::_os, avg 27µs/call |
79 | |||||
80 | 2 | 32µs | if ($os eq 'Unix') { | ||
81 | $$self{'data'}{'methods'} = [ | ||||
82 | qw(main TZ | ||||
83 | env TZ | ||||
84 | file /etc/TIMEZONE | ||||
85 | file /etc/timezone | ||||
86 | file /etc/sysconfig/clock | ||||
87 | file /etc/default/init | ||||
88 | ), | ||||
89 | 'command', '/bin/date +%Z', | ||||
90 | 'command', '/usr/bin/date +%Z', | ||||
91 | 'command', '/usr/local/bin/date +%Z', | ||||
92 | qw(cmdfield /bin/date -2 | ||||
93 | cmdfield /usr/bin/date -2 | ||||
94 | cmdfield /usr/local/bin/date -2 | ||||
95 | gmtoff | ||||
96 | ), | ||||
97 | ]; | ||||
98 | |||||
99 | } elsif ($os eq 'Windows') { | ||||
100 | $$self{'data'}{'methods'} = [ | ||||
101 | qw(main TZ | ||||
102 | env TZ | ||||
103 | registry | ||||
104 | gmtoff), | ||||
105 | ]; | ||||
106 | |||||
107 | } elsif ($os eq 'VMS') { | ||||
108 | $$self{'data'}{'methods'} = [ | ||||
109 | qw(main TZ | ||||
110 | env TZ | ||||
111 | env SYS$TIMEZONE_RULE | ||||
112 | env SYS$TIMEZONE_NAME | ||||
113 | env UCX$TZ | ||||
114 | env TCPIP$TZ | ||||
115 | env MULTINET_TIMEZONE | ||||
116 | env SYS$TIMEZONE_DIFFERENTIAL | ||||
117 | gmtoff | ||||
118 | ), | ||||
119 | ]; | ||||
120 | |||||
121 | } else { | ||||
122 | $$self{'data'}{'methods'} = [ | ||||
123 | qw(main TZ | ||||
124 | env TZ | ||||
125 | gmtoff | ||||
126 | ), | ||||
127 | ]; | ||||
128 | } | ||||
129 | } | ||||
130 | |||||
131 | # spent 824µs (14+810) within Date::Manip::TZ::_init_final which was called 2 times, avg 412µs/call:
# 2 times (14µs+810µs) by Date::Manip::Obj::new at line 161 of Date/Manip/Obj.pm, avg 412µs/call | ||||
132 | 2 | 2µs | my($self) = @_; | ||
133 | |||||
134 | 2 | 12µs | 2 | 810µs | $self->_set_curr_zone(); # spent 810µs making 2 calls to Date::Manip::TZ::_set_curr_zone, avg 405µs/call |
135 | } | ||||
136 | |||||
137 | 3 | 268µs | 2 | 46µs | # spent 29µs (12+17) within Date::Manip::TZ::BEGIN@137 which was called:
# once (12µs+17µs) by Date::Manip::Obj::BEGIN@16 at line 137 # spent 29µs making 1 call to Date::Manip::TZ::BEGIN@137
# spent 17µs making 1 call to strict::unimport |
138 | # This loads data from an offset module | ||||
139 | # | ||||
140 | sub _offmod { | ||||
141 | my($self,$offset) = @_; | ||||
142 | return if (exists $$self{'data'}{'Offsets'}{$offset}); | ||||
143 | |||||
144 | my $mod = $$self{'data'}{'Offmod'}{$offset}; | ||||
145 | eval "require Date::Manip::Offset::${mod}"; | ||||
146 | my %off = %{ "Date::Manip::Offset::${mod}::Offset" }; | ||||
147 | |||||
148 | $$self{'data'}{'Offsets'}{$offset} = { %off }; | ||||
149 | } | ||||
150 | |||||
151 | # This loads data from a zone module (takes a lowercase zone) | ||||
152 | # | ||||
153 | sub _module { | ||||
154 | 3 | 4µs | my($self,$zone) = @_; | ||
155 | 3 | 10µs | return if (exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||
156 | |||||
157 | 1 | 2µs | my $mod = $$self{'data'}{'Module'}{$zone}; | ||
158 | 1 | 53µs | eval "require Date::Manip::TZ::${mod}"; # spent 155µs executing statements in string eval | ||
159 | 1 | 9µs | my %dates = %{ "Date::Manip::TZ::${mod}::Dates" }; | ||
160 | 1 | 4µs | my %last = %{ "Date::Manip::TZ::${mod}::LastRule" }; | ||
161 | 1 | 18µs | $$self{'data'}{'Zones'}{$zone} = | ||
162 | { | ||||
163 | 'Dates' => { %dates }, | ||||
164 | 'LastRule' => { %last }, | ||||
165 | 'Loaded' => 1 | ||||
166 | }; | ||||
167 | } | ||||
168 | 3 | 2.59ms | 2 | 40µs | # spent 25µs (11+15) within Date::Manip::TZ::BEGIN@168 which was called:
# once (11µs+15µs) by Date::Manip::Obj::BEGIN@16 at line 168 # spent 25µs making 1 call to Date::Manip::TZ::BEGIN@168
# spent 15µs making 1 call to strict::import |
169 | |||||
170 | ######################################################################## | ||||
171 | # CHECKING/MODIFYING ZONEINFO DATA | ||||
172 | ######################################################################## | ||||
173 | |||||
174 | # spent 63µs within Date::Manip::TZ::_zone which was called 10 times, avg 6µs/call:
# 2 times (24µs+0s) by Date::Manip::TZ::_get_curr_zone at line 500, avg 12µs/call
# 2 times (7µs+0s) by Date::Manip::TZ::date_period at line 1050, avg 4µs/call
# 2 times (7µs+0s) by Date::Manip::TZ::_set_curr_zone at line 367, avg 3µs/call
# once (10µs+0s) by Date::Manip::Base::_config_var_setdate at line 1799 of Date/Manip/Base.pm
# once (7µs+0s) by Date::Manip::TZ::zone at line 638
# once (4µs+0s) by Date::Manip::TZ::_convert at line 1299
# once (3µs+0s) by Date::Manip::TZ::_convert at line 1293 | ||||
175 | 10 | 8µs | my($self,$zone) = @_; | ||
176 | 10 | 5µs | $zone = lc($zone); | ||
177 | |||||
178 | 10 | 72µs | if (exists $$self{'data'}{'MyAlias'}{$zone}) { | ||
179 | return $$self{'data'}{'MyAlias'}{$zone}; | ||||
180 | } elsif (exists $$self{'data'}{'Alias'}{$zone}) { | ||||
181 | return $$self{'data'}{'Alias'}{$zone}; | ||||
182 | } else { | ||||
183 | return ''; | ||||
184 | } | ||||
185 | } | ||||
186 | |||||
187 | sub tzdata { | ||||
188 | my($self) = @_; | ||||
189 | return $Date::Manip::Zones::TzdataVersion; | ||||
190 | } | ||||
191 | |||||
192 | sub tzcode { | ||||
193 | my($self) = @_; | ||||
194 | return $Date::Manip::Zones::TzcodeVersion; | ||||
195 | } | ||||
196 | |||||
197 | sub define_alias { | ||||
198 | my($self,$alias,$zone) = @_; | ||||
199 | $alias = lc($alias); | ||||
200 | |||||
201 | if ($alias eq 'reset') { | ||||
202 | $$self{'data'}{'MyAlias'} = {}; | ||||
203 | $$self{'data'}{'zonerx'} = undef; | ||||
204 | return 0; | ||||
205 | } | ||||
206 | if (lc($zone) eq 'reset') { | ||||
207 | delete $$self{'data'}{'MyAlias'}{$alias}; | ||||
208 | $$self{'data'}{'zonerx'} = undef; | ||||
209 | return 0; | ||||
210 | } | ||||
211 | |||||
212 | $zone = $self->_zone($zone); | ||||
213 | |||||
214 | return 1 if (! $zone); | ||||
215 | $$self{'data'}{'MyAlias'}{$alias} = $zone; | ||||
216 | $$self{'data'}{'zonerx'} = undef; | ||||
217 | return 0; | ||||
218 | } | ||||
219 | |||||
220 | sub define_abbrev { | ||||
221 | my($self,$abbrev,@zone) = @_; | ||||
222 | $abbrev = lc($abbrev); | ||||
223 | |||||
224 | if ($abbrev eq 'reset') { | ||||
225 | $$self{'data'}{'MyAbbrev'} = {}; | ||||
226 | $$self{'data'}{'abbrx'} = undef; | ||||
227 | return 0; | ||||
228 | } | ||||
229 | if ($#zone == 0 && lc($zone[0]) eq 'reset') { | ||||
230 | delete $$self{'data'}{'MyAbbrev'}{$abbrev}; | ||||
231 | $$self{'data'}{'abbrx'} = undef; | ||||
232 | return (0); | ||||
233 | } | ||||
234 | |||||
235 | if (! exists $$self{'data'}{'Abbrev'}{$abbrev}) { | ||||
236 | return (1); | ||||
237 | } | ||||
238 | |||||
239 | my (@z,%z); | ||||
240 | my %zone = map { $_,1 } @{ $$self{'data'}{'Abbrev'}{$abbrev} }; | ||||
241 | foreach my $z (@zone) { | ||||
242 | my $zone = $self->_zone($z); | ||||
243 | return (2,$z) if (! $zone); | ||||
244 | return (3,$z) if (! exists $zone{$zone}); | ||||
245 | next if (exists $z{$zone}); | ||||
246 | $z{$zone} = 1; | ||||
247 | push(@z,$zone); | ||||
248 | } | ||||
249 | |||||
250 | $$self{'data'}{'MyAbbrev'}{$abbrev} = [ @z ]; | ||||
251 | $$self{'data'}{'abbrx'} = undef; | ||||
252 | return (); | ||||
253 | } | ||||
254 | |||||
255 | sub define_offset { | ||||
256 | my($self,$offset,@args) = @_; | ||||
257 | my $dmb = $$self{'objs'}{'base'}; | ||||
258 | |||||
259 | if (lc($offset) eq 'reset') { | ||||
260 | $$self{'data'}{'MyOffsets'} = {}; | ||||
261 | return (0); | ||||
262 | } | ||||
263 | if ($#args == 0 && lc($args[0]) eq 'reset') { | ||||
264 | delete $$self{'data'}{'MyOffsets'}{$offset}; | ||||
265 | return (0); | ||||
266 | } | ||||
267 | |||||
268 | # Check that $offset is valid. If it is, load the | ||||
269 | # appropriate module. | ||||
270 | |||||
271 | if (ref($offset)) { | ||||
272 | $offset = $dmb->join('offset',$offset); | ||||
273 | } else { | ||||
274 | $offset = $dmb->_delta_convert('offset',$offset); | ||||
275 | } | ||||
276 | return (9) if (! $offset); | ||||
277 | return (1) if (! exists $$self{'data'}{'Offmod'}{$offset}); | ||||
278 | |||||
279 | $self->_offmod($offset); | ||||
280 | |||||
281 | # Find out whether we're handling STD, DST, or both. | ||||
282 | |||||
283 | my(@isdst) = (0,1); | ||||
284 | if ($args[0] =~ /^std|dst|stdonly|dstonly$/i) { | ||||
285 | my $tmp = lc(shift(@args)); | ||||
286 | if ($tmp eq 'stdonly') { | ||||
287 | @isdst = (0); | ||||
288 | } elsif ($tmp eq 'dstonly') { | ||||
289 | @isdst = (1); | ||||
290 | } | ||||
291 | } | ||||
292 | my @zone = @args; | ||||
293 | |||||
294 | if ($#isdst == 0 && | ||||
295 | ! exists($$self{'data'}{'Offsets'}{$offset}{$isdst[0]})) { | ||||
296 | return (2); | ||||
297 | } | ||||
298 | |||||
299 | # Check to see that each zone is valid, and contains this offset. | ||||
300 | |||||
301 | my %tmp; | ||||
302 | foreach my $isdst (0,1) { | ||||
303 | next if (! exists $$self{'data'}{'Offsets'}{$offset}{$isdst}); | ||||
304 | my @z = @{ $$self{'data'}{'Offsets'}{$offset}{$isdst} }; | ||||
305 | $tmp{$isdst} = { map { $_,1 } @z }; | ||||
306 | } | ||||
307 | |||||
308 | foreach my $z (@zone) { | ||||
309 | my $lcz = lc($z); | ||||
310 | if (! exists $$self{'data'}{'ZoneNames'}{$lcz}) { | ||||
311 | return (3,$z); | ||||
312 | } elsif (! exists $tmp{0}{$lcz} && | ||||
313 | ! exists $tmp{1}{$lcz}) { | ||||
314 | return (4,$z); | ||||
315 | } elsif ($#isdst == 0 && | ||||
316 | ! exists $tmp{$isdst[0]}{$lcz}) { | ||||
317 | return (5,$z); | ||||
318 | } | ||||
319 | $z = $lcz; | ||||
320 | } | ||||
321 | |||||
322 | # Set the zones accordingly. | ||||
323 | |||||
324 | foreach my $isdst (@isdst) { | ||||
325 | my @z; | ||||
326 | foreach my $z (@zone) { | ||||
327 | push(@z,$z) if (exists $tmp{$isdst}{$z}); | ||||
328 | } | ||||
329 | $$self{'data'}{'MyOffsets'}{$offset}{$isdst} = [ @z ]; | ||||
330 | } | ||||
331 | |||||
332 | return (0); | ||||
333 | } | ||||
334 | |||||
335 | ######################################################################## | ||||
336 | # SYSTEM ZONE | ||||
337 | ######################################################################## | ||||
338 | |||||
339 | sub curr_zone { | ||||
340 | my($self,$reset) = @_; | ||||
341 | my $dmb = $$self{'objs'}{'base'}; | ||||
342 | |||||
343 | if ($reset) { | ||||
344 | $self->_set_curr_zone(); | ||||
345 | } | ||||
346 | |||||
347 | my($ret) = $dmb->_now('systz',1); | ||||
348 | return $$self{'data'}{'ZoneNames'}{$ret} | ||||
349 | } | ||||
350 | |||||
351 | sub curr_zone_methods { | ||||
352 | my($self,@methods) = @_; | ||||
353 | |||||
354 | if (${^TAINT}) { | ||||
355 | warn "ERROR: [curr_zone_methods] not allowed when taint checking on\n"; | ||||
356 | return; | ||||
357 | } | ||||
358 | |||||
359 | $$self{'data'}{'methods'} = [ @methods ]; | ||||
360 | } | ||||
361 | |||||
362 | # spent 810µs (26+784) within Date::Manip::TZ::_set_curr_zone which was called 2 times, avg 405µs/call:
# 2 times (26µs+784µs) by Date::Manip::TZ::_init_final at line 134, avg 405µs/call | ||||
363 | 2 | 2µs | my($self) = @_; | ||
364 | 2 | 2µs | my $dmb = $$self{'objs'}{'base'}; | ||
365 | 2 | 6µs | 2 | 777µs | my $currzone = $self->_get_curr_zone(); # spent 777µs making 2 calls to Date::Manip::TZ::_get_curr_zone, avg 389µs/call |
366 | |||||
367 | 2 | 11µs | 2 | 7µs | $$dmb{'data'}{'now'}{'systz'} = $self->_zone($currzone); # spent 7µs making 2 calls to Date::Manip::TZ::_zone, avg 3µs/call |
368 | } | ||||
369 | |||||
370 | # This determines the system timezone using all of the methods | ||||
371 | # applicable to the operating system. The first match is used. | ||||
372 | # | ||||
373 | # spent 777µs (392+385) within Date::Manip::TZ::_get_curr_zone which was called 2 times, avg 389µs/call:
# 2 times (392µs+385µs) by Date::Manip::TZ::_set_curr_zone at line 365, avg 389µs/call | ||||
374 | 2 | 2µs | my($self) = @_; | ||
375 | 2 | 2µs | my $dmb = $$self{'objs'}{'base'}; | ||
376 | |||||
377 | 2 | 4µs | my $t = time; | ||
378 | 2 | 43µs | my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t); | ||
379 | 2 | 2µs | my $currzone = ''; | ||
380 | 2 | 2µs | my $dstflag = ($isdst ? 'dstonly' : 'stdonly'); | ||
381 | |||||
382 | 2 | 27µs | my (@methods) = @{ $$self{'data'}{'methods'} }; | ||
383 | 2 | 4µs | METHOD: while (@methods) { | ||
384 | 8 | 11µs | my $method = shift(@methods); | ||
385 | 8 | 6µs | my @zone = (); | ||
386 | |||||
387 | 8 | 8µs | given ($method) { | ||
388 | |||||
389 | 8 | 15µs | when ('main') { | ||
390 | 2 | 2µs | if (! @methods) { | ||
391 | warn "ERROR: [_set_curr_zone] main requires argument\n"; | ||||
392 | return; | ||||
393 | } | ||||
394 | 2 | 2µs | my $var = shift(@methods); | ||
395 | 2 | 4µs | push(@zone,$$::var) if (defined $$::var); | ||
396 | } | ||||
397 | |||||
398 | 6 | 5µs | when ('env') { | ||
399 | 2 | 3µs | if (! @methods) { | ||
400 | warn "ERROR: [_set_curr_zone] env requires argument\n"; | ||||
401 | return; | ||||
402 | } | ||||
403 | 2 | 3µs | my $var = shift(@methods); | ||
404 | 2 | 6µs | push(@zone,$ENV{$var}) if (exists $ENV{$var}); | ||
405 | } | ||||
406 | |||||
407 | 4 | 3µs | when ('file') { | ||
408 | 4 | 3µs | if (! @methods) { | ||
409 | warn "ERROR: [_set_curr_zone] file requires argument\n"; | ||||
410 | return; | ||||
411 | } | ||||
412 | 4 | 4µs | my $file = shift(@methods); | ||
413 | 4 | 59µs | 4 | 26µs | next if (! -f $file); # spent 26µs making 4 calls to Date::Manip::TZ::CORE:ftfile, avg 6µs/call |
414 | |||||
415 | 2 | 25µs | 2 | 132µs | my $in = new IO::File; # spent 132µs making 2 calls to IO::File::new, avg 66µs/call |
416 | 2 | 7µs | 2 | 102µs | $in->open($file) || next; # spent 102µs making 2 calls to IO::File::open, avg 51µs/call |
417 | 2 | 2µs | my $firstline = 1; | ||
418 | 2 | 18µs | 2 | 56µs | while (! $in->eof) { # spent 56µs making 2 calls to IO::Handle::eof, avg 28µs/call |
419 | 2 | 17µs | 2 | 5µs | my $line = <$in>; # spent 5µs making 2 calls to Date::Manip::TZ::CORE:readline, avg 3µs/call |
420 | 2 | 20µs | 4 | 10µs | next if ($line =~ /^\s*\043/ || # spent 10µs making 4 calls to Date::Manip::TZ::CORE:match, avg 2µs/call |
421 | $line =~ /^\s*$/); | ||||
422 | 2 | 8µs | 2 | 4µs | if ($line =~ /^\s*(?:TZ|TIMEZONE|ZONE)\s*=\s*(\S+)/i) { # spent 4µs making 2 calls to Date::Manip::TZ::CORE:match, avg 2µs/call |
423 | my $zone = $1; | ||||
424 | $zone =~ s/["']//g; # " | ||||
425 | push(@zone,$zone); | ||||
426 | last; | ||||
427 | } | ||||
428 | 2 | 7µs | 2 | 13µs | if ($firstline) { # spent 13µs making 2 calls to IO::Handle::eof, avg 7µs/call |
429 | 2 | 2µs | $firstline = 0; | ||
430 | 2 | 13µs | 2 | 6µs | $line =~ s/\s//g; # spent 6µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 3µs/call |
431 | 2 | 7µs | 2 | 2µs | $line =~ s/["']//g; # " # spent 2µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 1µs/call |
432 | 2 | 3µs | push(@zone,$line); | ||
433 | } | ||||
434 | } | ||||
435 | 2 | 47µs | 2 | 5µs | close(IN); # spent 5µs making 2 calls to Date::Manip::TZ::CORE:close, avg 2µs/call |
436 | } | ||||
437 | |||||
438 | when ('command') { | ||||
439 | if (! @methods) { | ||||
440 | warn "ERROR: [_set_curr_zone] command requires argument\n"; | ||||
441 | return; | ||||
442 | } | ||||
443 | my $command = shift(@methods); | ||||
444 | my ($out) = _cmd($command); | ||||
445 | push(@zone,$out) if ($out); | ||||
446 | } | ||||
447 | |||||
448 | when ('cmdfield') { | ||||
449 | if ($#methods < 1) { | ||||
450 | warn "ERROR: [_set_curr_zone] cmdfield requires 2 arguments\n"; | ||||
451 | return; | ||||
452 | } | ||||
453 | my $command = shift(@methods); | ||||
454 | my $n = shift(@methods); | ||||
455 | my ($out) = _cmd($command); | ||||
456 | if ($out) { | ||||
457 | $out =~ s/^\s*//; | ||||
458 | $out =~ s/\s*$//; | ||||
459 | my @out = split(/\s+/,$out); | ||||
460 | push(@zone,$out[$n]) if (defined $out[$n]); | ||||
461 | } | ||||
462 | } | ||||
463 | |||||
464 | when ('gmtoff') { | ||||
465 | my($secUT,$minUT,$hourUT,$mdayUT,$monUT,$yearUT,$wdayUT,$ydayUT, | ||||
466 | $isdstUT) = gmtime($t); | ||||
467 | if ($mdayUT>($mday+1)) { | ||||
468 | # UT = 28-31 LT = 1 | ||||
469 | $mdayUT=0; | ||||
470 | } elsif ($mdayUT<($mday-1)) { | ||||
471 | # UT = 1 LT = 28-31 | ||||
472 | $mday=0; | ||||
473 | } | ||||
474 | $sec = (($mday*24 + $hour)*60 + $min)*60 + $sec; | ||||
475 | $secUT = (($mdayUT*24 + $hourUT)*60 + $minUT)*60 + $secUT; | ||||
476 | my $off = $sec-$secUT; | ||||
477 | |||||
478 | $off = $dmb->_delta_convert('time',"0:0:$off"); | ||||
479 | $off = $dmb->_delta_convert('offset',$off); | ||||
480 | push(@zone,$off); | ||||
481 | } | ||||
482 | |||||
483 | when ('registry') { | ||||
484 | my $z = $self->_windows_registry_val(); | ||||
485 | push(@zone,$z) if ($z); | ||||
486 | } | ||||
487 | |||||
488 | default { | ||||
489 | warn "ERROR: [_set_curr_zone] invalid method: $method\n"; | ||||
490 | return; | ||||
491 | } | ||||
492 | } | ||||
493 | |||||
494 | 6 | 15µs | foreach my $zone (@zone) { | ||
495 | 2 | 3µs | $zone = lc($zone); | ||
496 | # OpenUNIX puts a colon at the start | ||||
497 | 2 | 8µs | 2 | 2µs | $zone =~ s/^://; # spent 2µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 850ns/call |
498 | |||||
499 | # If we got a zone name/alias | ||||
500 | 2 | 13µs | 2 | 24µs | $currzone = $self->_zone($zone); # spent 24µs making 2 calls to Date::Manip::TZ::_zone, avg 12µs/call |
501 | 2 | 4µs | last METHOD if ($currzone); | ||
502 | |||||
503 | # If we got an abbreviation (EST) | ||||
504 | if (exists $$self{'data'}{'Abbrev'}{$zone}) { | ||||
505 | $currzone = $$self{'data'}{'Abbrev'}{$zone}[0]; | ||||
506 | last METHOD; | ||||
507 | } | ||||
508 | |||||
509 | # If we got an offset | ||||
510 | |||||
511 | $currzone = $self->zone($zone,$dstflag); | ||||
512 | last METHOD if ($currzone); | ||||
513 | } | ||||
514 | } | ||||
515 | |||||
516 | 2 | 1µs | if (! $currzone) { | ||
517 | warn "ERROR: Date::Manip unable to determine Time Zone.\n"; | ||||
518 | die; | ||||
519 | } | ||||
520 | |||||
521 | 2 | 9µs | return $currzone; | ||
522 | } | ||||
523 | |||||
524 | # This comes from the DateTime-TimeZone module | ||||
525 | # | ||||
526 | sub _windows_registry_val { | ||||
527 | my($self) = @_; | ||||
528 | |||||
529 | require Win32::TieRegistry; | ||||
530 | |||||
531 | my $lmachine = new Win32::TieRegistry 'LMachine', | ||||
532 | { Access => Win32::TieRegistry::KEY_READ(), | ||||
533 | Delimiter => '/' } | ||||
534 | or return ''; | ||||
535 | |||||
536 | my $tzinfo = $lmachine->Open('SYSTEM/CurrentControlSet/Control/TimeZoneInformation/'); | ||||
537 | |||||
538 | # | ||||
539 | # Windows Vista, Windows 2008 Server | ||||
540 | # | ||||
541 | |||||
542 | my $tzkn = $tzinfo->GetValue('TimeZoneKeyName'); | ||||
543 | if (defined($tzkn) && $tzkn) { | ||||
544 | # For some reason, Vista is tacking on a bunch of stuff at the | ||||
545 | # end of the timezone, starting with a chr(0). Strip it off. | ||||
546 | |||||
547 | my $c = chr(0); | ||||
548 | my $i = index($tzkn,$c); | ||||
549 | if ($i != -1) { | ||||
550 | $tzkn = substr($tzkn,0,$i); | ||||
551 | } | ||||
552 | my $z = $self->_zone($tzkn); | ||||
553 | return $z if ($z); | ||||
554 | } | ||||
555 | |||||
556 | # | ||||
557 | # Windows NT, Windows 2000, Windows XP, Windows 2003 Server | ||||
558 | # | ||||
559 | |||||
560 | my $stdnam = $tzinfo->GetValue('StandardName'); | ||||
561 | my $z = $self->_zone($stdnam); | ||||
562 | return $z if ($z); | ||||
563 | |||||
564 | # | ||||
565 | # For non-English versions, we have to determine which timezone it | ||||
566 | # actually is. | ||||
567 | # | ||||
568 | |||||
569 | my $atz = $lmachine->Open('SOFTWARE/Microsoft/Windows NT/CurrentVersion/Time Zones/'); | ||||
570 | if (! defined($atz) || ! $atz) { | ||||
571 | $atz = $lmachine->Open('SOFTWARE/Microsoft/Windows/CurrentVersion/Time Zones/'); | ||||
572 | } | ||||
573 | |||||
574 | return "" if (! defined($atz) || ! $atz); | ||||
575 | |||||
576 | foreach my $z ($atz->SubKeyNames()) { | ||||
577 | my $tmp = $atz->Open("$z/"); | ||||
578 | my $znam = $tmp->GetValue('Std'); | ||||
579 | return $z if ($znam eq $stdnam); | ||||
580 | } | ||||
581 | } | ||||
582 | |||||
583 | # We will be testing commands that don't exist on all architectures, | ||||
584 | # so disable warnings. | ||||
585 | # | ||||
586 | 3 | 217µs | 2 | 115µs | # spent 78µs (40+37) within Date::Manip::TZ::BEGIN@586 which was called:
# once (40µs+37µs) by Date::Manip::Obj::BEGIN@16 at line 586 # spent 78µs making 1 call to Date::Manip::TZ::BEGIN@586
# spent 37µs making 1 call to warnings::unimport |
587 | sub _cmd { | ||||
588 | my($cmd) = @_; | ||||
589 | local(*IN); | ||||
590 | open(IN,"$cmd |") || return (); | ||||
591 | my @out = <IN>; | ||||
592 | close(IN); | ||||
593 | chomp(@out); | ||||
594 | return @out; | ||||
595 | } | ||||
596 | 3 | 4.79ms | 2 | 49µs | # spent 31µs (14+17) within Date::Manip::TZ::BEGIN@596 which was called:
# once (14µs+17µs) by Date::Manip::Obj::BEGIN@16 at line 596 # spent 31µs making 1 call to Date::Manip::TZ::BEGIN@596
# spent 17µs making 1 call to warnings::import |
597 | |||||
598 | ######################################################################## | ||||
599 | # DETERMINING A TIMEZONE | ||||
600 | ######################################################################## | ||||
601 | |||||
602 | # spent 962µs (115+847) within Date::Manip::TZ::zone which was called:
# once (115µs+847µs) by Date::Manip::Base::_config_var_setdate at line 1739 of Date/Manip/Base.pm | ||||
603 | 1 | 2µs | my($self,@args) = @_; | ||
604 | 1 | 2µs | my $dmb = $$self{'objs'}{'base'}; | ||
605 | 1 | 600ns | if (! @args) { | ||
606 | my($tz) = $dmb->_now('tz',1); | ||||
607 | return $$self{'data'}{'ZoneNames'}{$tz} | ||||
608 | } | ||||
609 | |||||
610 | # Parse the arguments | ||||
611 | |||||
612 | 1 | 2µs | my($zone,$abbrev,$offset,$dstflag) = ('','','',''); | ||
613 | 1 | 1µs | my(@abbrev,$date,$tmp); | ||
614 | 1 | 2µs | foreach my $arg (@args) { | ||
615 | |||||
616 | 3 | 7µs | if (ref($arg) eq 'ARRAY') { | ||
617 | 1 | 2µs | if ($#$arg == 5) { | ||
618 | # [Y,M,D,H,Mn,S] | ||||
619 | 1 | 400ns | return undef if ($date); | ||
620 | 1 | 500ns | $date = $arg; | ||
621 | |||||
622 | } elsif ($#$arg == 2) { | ||||
623 | # [H,Mn,S] | ||||
624 | return undef if ($offset); | ||||
625 | $offset = $dmb->join('offset',$arg); | ||||
626 | return undef if (! $offset); | ||||
627 | |||||
628 | } else { | ||||
629 | return undef; | ||||
630 | } | ||||
631 | |||||
632 | } elsif (ref($arg)) { | ||||
633 | return undef; | ||||
634 | |||||
635 | } else { | ||||
636 | 2 | 2µs | $arg = lc($arg); | ||
637 | |||||
638 | 2 | 23µs | 3 | 15µs | if ($arg =~ /^(std|dst|stdonly|dstonly)$/) { # spent 8µs making 2 calls to Date::Manip::TZ::CORE:match, avg 4µs/call
# spent 7µs making 1 call to Date::Manip::TZ::_zone |
639 | 1 | 700ns | return undef if ($dstflag); | ||
640 | 1 | 1µs | $dstflag = $arg; | ||
641 | |||||
642 | } elsif ($tmp = $self->_zone($arg)) { | ||||
643 | 1 | 600ns | return undef if ($zone); | ||
644 | 1 | 800ns | $zone = $tmp; | ||
645 | |||||
646 | } elsif (exists $$self{'data'}{'MyAbbrev'}{$arg}) { | ||||
647 | return undef if (@abbrev); | ||||
648 | $abbrev = $arg; | ||||
649 | @abbrev = @{ $$self{'data'}{'MyAbbrev'}{$arg} }; | ||||
650 | } elsif (exists $$self{'data'}{'Abbrev'}{$arg}) { | ||||
651 | return undef if (@abbrev); | ||||
652 | $abbrev = $arg; | ||||
653 | @abbrev = @{ $$self{'data'}{'Abbrev'}{$arg} }; | ||||
654 | |||||
655 | } elsif ($tmp = $dmb->split('offset',$arg)) { | ||||
656 | return undef if ($offset); | ||||
657 | $offset = $dmb->_delta_convert('offset',$arg); | ||||
658 | |||||
659 | } elsif ($tmp = $dmb->split('date',$arg)) { | ||||
660 | return undef if ($date); | ||||
661 | $date = $tmp; | ||||
662 | |||||
663 | } else { | ||||
664 | return undef; | ||||
665 | } | ||||
666 | } | ||||
667 | } | ||||
668 | |||||
669 | # | ||||
670 | # Determine the zones that match all data. | ||||
671 | # | ||||
672 | |||||
673 | 1 | 900ns | my @zone; | ||
674 | |||||
675 | 1 | 800ns | while (1) { | ||
676 | |||||
677 | # No information | ||||
678 | |||||
679 | 1 | 800ns | if (! $zone && | ||
680 | ! $abbrev && | ||||
681 | ! $offset) { | ||||
682 | my($z) = $dmb->_now('tz',1); | ||||
683 | @zone = (lc($z)); | ||||
684 | } | ||||
685 | |||||
686 | # $dstflag | ||||
687 | # | ||||
688 | # $dstflag is "dst' if | ||||
689 | # zone is passed in as an offset | ||||
690 | # date is passed in | ||||
691 | |||||
692 | 1 | 500ns | $dstflag = "dst" if ($offset && $date && ! $dstflag); | ||
693 | |||||
694 | 1 | 600ns | my(@isdst); | ||
695 | 1 | 2µs | if ($dstflag eq 'stdonly') { | ||
696 | @isdst = (0); | ||||
697 | } elsif ($dstflag eq 'dstonly') { | ||||
698 | @isdst = (1); | ||||
699 | } elsif ($dstflag eq 'dst') { | ||||
700 | @isdst = (1,0); | ||||
701 | } else { | ||||
702 | 1 | 2µs | @isdst = (0,1); | ||
703 | } | ||||
704 | |||||
705 | # $zone | ||||
706 | |||||
707 | 1 | 2µs | if ($zone) { | ||
708 | @zone = ($zone); | ||||
709 | } | ||||
710 | |||||
711 | # $abbrev | ||||
712 | |||||
713 | 1 | 700ns | if ($abbrev) { | ||
714 | my @z; | ||||
715 | foreach my $isdst (@isdst) { | ||||
716 | my @tmp = $self->_check_abbrev_isdst($abbrev,$isdst,@abbrev); | ||||
717 | if (@tmp) { | ||||
718 | if (@z) { | ||||
719 | @z = _list_add(\@z,\@tmp); | ||||
720 | } else { | ||||
721 | @z = @tmp; | ||||
722 | } | ||||
723 | } | ||||
724 | } | ||||
725 | |||||
726 | if (@zone) { | ||||
727 | @zone = _list_union(\@z,\@zone); | ||||
728 | } else { | ||||
729 | @zone = @z; | ||||
730 | } | ||||
731 | last if (! @zone); | ||||
732 | } | ||||
733 | |||||
734 | # $offset | ||||
735 | |||||
736 | 1 | 500ns | if ($offset) { | ||
737 | return undef if (! exists $$self{'data'}{'Offmod'}{$offset}); | ||||
738 | $self->_offmod($offset); | ||||
739 | |||||
740 | my @z; | ||||
741 | foreach my $isdst (@isdst) { | ||||
742 | my @tmp; | ||||
743 | if (exists $$self{'data'}{'MyOffsets'}{$offset}{$isdst}) { | ||||
744 | @tmp = @{ $$self{'data'}{'MyOffsets'}{$offset}{$isdst} }; | ||||
745 | } elsif (exists $$self{'data'}{'Offsets'}{$offset}{$isdst}) { | ||||
746 | @tmp = @{ $$self{'data'}{'Offsets'}{$offset}{$isdst} }; | ||||
747 | } | ||||
748 | @tmp = $self->_check_offset_abbrev_isdst($offset,$abbrev,$isdst,@tmp) | ||||
749 | if ($abbrev); | ||||
750 | if (@tmp) { | ||||
751 | if (@z) { | ||||
752 | @z = _list_add(\@z,\@tmp); | ||||
753 | } else { | ||||
754 | @z = @tmp; | ||||
755 | } | ||||
756 | } | ||||
757 | } | ||||
758 | |||||
759 | if (@zone) { | ||||
760 | @zone = _list_union(\@zone,\@z); | ||||
761 | } else { | ||||
762 | @zone = @z; | ||||
763 | } | ||||
764 | last if (! @zone); | ||||
765 | } | ||||
766 | |||||
767 | # $date | ||||
768 | |||||
769 | 1 | 1µs | if ($date) { | ||
770 | # Get all periods for the year. | ||||
771 | # | ||||
772 | # Test all periods to make sure that $date is between the | ||||
773 | # wallclock times AND matches other criteria. All periods | ||||
774 | # must be tested since the same wallclock time can be in | ||||
775 | # multiple periods. | ||||
776 | |||||
777 | 1 | 600ns | my @tmp; | ||
778 | 1 | 6µs | my $isdst = ''; | ||
779 | 1 | 800ns | $isdst = 0 if ($dstflag eq 'stdonly'); | ||
780 | 1 | 600ns | $isdst = 1 if ($dstflag eq 'dstonly'); | ||
781 | 1 | 2µs | ZONE: foreach my $z (@zone) { | ||
782 | 1 | 4µs | 1 | 755µs | $self->_module($z); # spent 755µs making 1 call to Date::Manip::TZ::_module |
783 | 1 | 1µs | my $y = $$date[0]; | ||
784 | 1 | 6µs | 1 | 70µs | my @periods = $self->_all_periods($z,$y); # spent 70µs making 1 call to Date::Manip::TZ::_all_periods |
785 | |||||
786 | 1 | 1µs | foreach my $period (@periods) { | ||
787 | 1 | 2µs | my($begUT,$begLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||
788 | 1 | 8µs | 2 | 7µs | next if ($dmb->cmp($date,$begLT) == -1 || # spent 7µs making 2 calls to Date::Manip::Base::cmp, avg 3µs/call |
789 | $dmb->cmp($date,$endLT) == 1 || | ||||
790 | ($offset ne '' && $offset ne $off) || | ||||
791 | ($isdst ne '' && $isdst ne $dst) || | ||||
792 | ($abbrev ne '' && lc($abbrev) ne lc($abb)) | ||||
793 | ); | ||||
794 | 1 | 800ns | push(@tmp,$z); | ||
795 | 1 | 2µs | next ZONE; | ||
796 | } | ||||
797 | } | ||||
798 | 1 | 1µs | @zone = @tmp; | ||
799 | 1 | 700ns | last if (! @zone); | ||
800 | } | ||||
801 | |||||
802 | 1 | 600ns | last; | ||
803 | } | ||||
804 | |||||
805 | # Return the value/list | ||||
806 | |||||
807 | 1 | 600ns | if (wantarray) { | ||
808 | my @ret; | ||||
809 | foreach my $z (@zone) { | ||||
810 | push(@ret,$$self{'data'}{'ZoneNames'}{$z}); | ||||
811 | } | ||||
812 | return @ret; | ||||
813 | } | ||||
814 | |||||
815 | 1 | 500ns | return '' if (! @zone); | ||
816 | 1 | 7µs | return $$self{'data'}{'ZoneNames'}{$zone[0]} | ||
817 | } | ||||
818 | |||||
819 | # This returns a list of all timezones which have the correct | ||||
820 | # abbrev/isdst combination. | ||||
821 | # | ||||
822 | sub _check_abbrev_isdst { | ||||
823 | my($self,$abbrev,$isdst,@zones) = @_; | ||||
824 | |||||
825 | my @ret; | ||||
826 | ZONE: foreach my $zone (@zones) { | ||||
827 | $self->_module($zone); | ||||
828 | |||||
829 | foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
830 | my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} }; | ||||
831 | foreach my $period (@periods) { | ||||
832 | my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||||
833 | next if (lc($abbrev) ne lc($abb) || | ||||
834 | $isdst != $dst); | ||||
835 | push(@ret,$zone); | ||||
836 | next ZONE; | ||||
837 | } | ||||
838 | } | ||||
839 | } | ||||
840 | |||||
841 | return @ret; | ||||
842 | } | ||||
843 | |||||
844 | # This returns a list of all timezones which have the correct | ||||
845 | # abbrev/isdst combination. | ||||
846 | # | ||||
847 | sub _check_offset_abbrev_isdst { | ||||
848 | my($self,$offset,$abbrev,$isdst,@zones) = @_; | ||||
849 | |||||
850 | my @ret; | ||||
851 | ZONE: foreach my $zone (@zones) { | ||||
852 | $self->_module($zone); | ||||
853 | |||||
854 | foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
855 | my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} }; | ||||
856 | foreach my $period (@periods) { | ||||
857 | my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||||
858 | next if (lc($abbrev) ne lc($abb) || | ||||
859 | $offset ne $off || | ||||
860 | $isdst != $dst); | ||||
861 | push(@ret,$zone); | ||||
862 | next ZONE; | ||||
863 | } | ||||
864 | } | ||||
865 | } | ||||
866 | |||||
867 | return @ret; | ||||
868 | } | ||||
869 | |||||
870 | # This finds the elements common to two lists, and preserves the order | ||||
871 | # from the first list. | ||||
872 | # | ||||
873 | sub _list_union { | ||||
874 | my($list1,$list2) = @_; | ||||
875 | my(%list2) = map { $_,1 } @$list2; | ||||
876 | my(@ret); | ||||
877 | foreach my $ele (@$list1) { | ||||
878 | push(@ret,$ele) if (exists $list2{$ele}); | ||||
879 | } | ||||
880 | return @ret; | ||||
881 | } | ||||
882 | |||||
883 | # This adds elements from the second list to the first list, provided | ||||
884 | # they are not already there. | ||||
885 | # | ||||
886 | sub _list_add { | ||||
887 | my($list1,$list2) = @_; | ||||
888 | my(%list1) = map { $_,1 } @$list1; | ||||
889 | my(@ret) = @$list1; | ||||
890 | foreach my $ele (@$list2) { | ||||
891 | next if (exists $list1{$ele}); | ||||
892 | push(@ret,$ele); | ||||
893 | $list1{$ele} = 1; | ||||
894 | } | ||||
895 | return @ret; | ||||
896 | } | ||||
897 | |||||
898 | ######################################################################## | ||||
899 | # PERIODS METHODS | ||||
900 | ######################################################################## | ||||
901 | |||||
902 | sub all_periods { | ||||
903 | my($self,$zone,$year) = @_; | ||||
904 | |||||
905 | my $z = $self->_zone($zone); | ||||
906 | if (! $z) { | ||||
907 | warn "ERROR: [periods] Invalid zone: $zone\n"; | ||||
908 | return; | ||||
909 | } | ||||
910 | $zone = $z; | ||||
911 | $self->_module($zone); | ||||
912 | |||||
913 | return $self->_all_periods($zone,$year); | ||||
914 | } | ||||
915 | |||||
916 | sub _all_periods { | ||||
917 | 3 | 3µs | my($self,$zone,$year) = @_; | ||
918 | 3 | 5µs | $year += 0; | ||
919 | |||||
920 | 3 | 14µs | if (! exists $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year}) { | ||
921 | |||||
922 | # | ||||
923 | # $ym1 is the year prior to $year which contains a rule (which will | ||||
924 | # end in $year or later). $y is $year IF the zone contains rules | ||||
925 | # for this year. | ||||
926 | # | ||||
927 | |||||
928 | 1 | 800ns | my($ym1,$ym0); | ||
929 | 1 | 3µs | if ($year > $$self{'data'}{'LastYear'} && | ||
930 | exists $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}) { | ||||
931 | $ym1 = $year-1; | ||||
932 | $ym0 = $year; | ||||
933 | |||||
934 | } else { | ||||
935 | 1 | 13µs | 1 | 3µs | foreach my $y (sort { $a <=> $b } # spent 3µs making 1 call to Date::Manip::TZ::CORE:sort |
936 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
937 | 1 | 700ns | if ($y < $year) { | ||
938 | 1 | 600ns | $ym1 = $y; | ||
939 | 1 | 500ns | next; | ||
940 | } | ||||
941 | $ym0 = $year if ($year == $y); | ||||
942 | last; | ||||
943 | } | ||||
944 | } | ||||
945 | 1 | 600ns | $ym1 = 0 if (! $ym1); | ||
946 | |||||
947 | # | ||||
948 | # Get the periods from the prior year. The last one is used (any others | ||||
949 | # are discarded). | ||||
950 | # | ||||
951 | |||||
952 | 1 | 500ns | my(@periods); | ||
953 | |||||
954 | # $ym1 will be 0 in 0001 | ||||
955 | 1 | 1µs | if ($ym1) { | ||
956 | 1 | 5µs | 1 | 18µs | my @tmp = $self->_periods($zone,$ym1); # spent 18µs making 1 call to Date::Manip::TZ::_periods |
957 | 1 | 2µs | push(@periods,pop(@tmp)) if (@tmp); | ||
958 | } | ||||
959 | |||||
960 | # | ||||
961 | # Add on any periods from the current year. | ||||
962 | # | ||||
963 | |||||
964 | 1 | 800ns | if ($ym0) { | ||
965 | push(@periods,$self->_periods($zone,$year)); | ||||
966 | } | ||||
967 | |||||
968 | 1 | 2µs | $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} = [ @periods ]; | ||
969 | } | ||||
970 | |||||
971 | # A faster 'dclone' so we don't return the actual data | ||||
972 | 3 | 2µs | my @ret; | ||
973 | 3 | 8µs | foreach my $ele (@{ $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} }) { | ||
974 | push(@ret, | ||||
975 | [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4],$$ele[5], | ||||
976 | 3 | 27µs | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
977 | } | ||||
978 | 3 | 20µs | return @ret; | ||
979 | } | ||||
980 | |||||
981 | sub periods { | ||||
982 | my($self,$zone,$year,$year1) = @_; | ||||
983 | |||||
984 | my $z = $self->_zone($zone); | ||||
985 | if (! $z) { | ||||
986 | warn "ERROR: [periods] Invalid zone: $zone\n"; | ||||
987 | return; | ||||
988 | } | ||||
989 | $zone = $z; | ||||
990 | $self->_module($zone); | ||||
991 | |||||
992 | if (! defined($year1)) { | ||||
993 | return $self->_periods($zone,$year); | ||||
994 | } | ||||
995 | |||||
996 | $year = 1 if (! defined($year)); | ||||
997 | |||||
998 | my @ret; | ||||
999 | my $lastyear = $$self{'data'}{'LastYear'}; | ||||
1000 | |||||
1001 | if ($year <= $lastyear) { | ||||
1002 | foreach my $y (sort { $a <=> $b } | ||||
1003 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
1004 | last if ($y > $year1 || $y > $lastyear); | ||||
1005 | next if ($y < $year); | ||||
1006 | push(@ret,$self->_periods($zone,$y)); | ||||
1007 | } | ||||
1008 | } | ||||
1009 | |||||
1010 | if ($year1 > $lastyear) { | ||||
1011 | $year = $lastyear + 1 if ($year <= $lastyear); | ||||
1012 | foreach my $y ($year..$year1) { | ||||
1013 | push(@ret,$self->_periods($zone,$y)); | ||||
1014 | } | ||||
1015 | } | ||||
1016 | |||||
1017 | return @ret; | ||||
1018 | } | ||||
1019 | |||||
1020 | # spent 18µs within Date::Manip::TZ::_periods which was called:
# once (18µs+0s) by Date::Manip::TZ::_all_periods at line 956 | ||||
1021 | 1 | 2µs | my($self,$zone,$year) = @_; | ||
1022 | 1 | 800ns | $year += 0; | ||
1023 | |||||
1024 | 1 | 2µs | if (! exists $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year}) { | ||
1025 | |||||
1026 | my @periods = (); | ||||
1027 | if ($year > $$self{'data'}{'LastYear'}) { | ||||
1028 | # Calculate periods using the LastRule method | ||||
1029 | @periods = $self->_lastrule($zone,$year); | ||||
1030 | } | ||||
1031 | |||||
1032 | $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} = [ @periods ]; | ||||
1033 | } | ||||
1034 | |||||
1035 | # A faster 'dclone' so we don't return the actual data | ||||
1036 | 1 | 400ns | my @ret; | ||
1037 | 1 | 3µs | foreach my $ele (@{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} }) { | ||
1038 | push(@ret, | ||||
1039 | [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4],$$ele[5], | ||||
1040 | 1 | 7µs | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
1041 | } | ||||
1042 | 1 | 5µs | return @ret; | ||
1043 | } | ||||
1044 | |||||
1045 | # spent 174µs (88+85) within Date::Manip::TZ::date_period which was called 2 times, avg 87µs/call:
# once (60µs+53µs) by Date::Manip::Base::_config_var_setdate at line 1771 of Date/Manip/Base.pm
# once (29µs+32µs) by Date::Manip::TZ::_convert at line 1307 | ||||
1046 | 2 | 2µs | my($self,$date,$zone,$wallclock,$isdst) = @_; | ||
1047 | 2 | 800ns | $wallclock = 0 if (! $wallclock); | ||
1048 | 2 | 1µs | $isdst = 0 if (! $isdst); | ||
1049 | |||||
1050 | 2 | 4µs | 2 | 7µs | my $z = $self->_zone($zone); # spent 7µs making 2 calls to Date::Manip::TZ::_zone, avg 4µs/call |
1051 | 2 | 700ns | if (! $z) { | ||
1052 | warn "ERROR: [date_period] Invalid zone: $zone\n"; | ||||
1053 | return; | ||||
1054 | } | ||||
1055 | 2 | 600ns | $zone = $z; | ||
1056 | 2 | 4µs | 2 | 7µs | $self->_module($zone); # spent 7µs making 2 calls to Date::Manip::TZ::_module, avg 3µs/call |
1057 | |||||
1058 | 2 | 2µs | my $dmb = $$self{'objs'}{'base'}; | ||
1059 | 2 | 3µs | my @date = @$date; | ||
1060 | 2 | 800ns | my $year = $date[0]; | ||
1061 | 2 | 7µs | 2 | 23µs | my $dates= $dmb->_join_date($date); # spent 23µs making 2 calls to Date::Manip::Base::_join_date, avg 12µs/call |
1062 | |||||
1063 | 2 | 1µs | if ($wallclock) { | ||
1064 | # A wallclock date | ||||
1065 | |||||
1066 | 2 | 8µs | 2 | 47µs | my @period = $self->_all_periods($zone,$year); # spent 47µs making 2 calls to Date::Manip::TZ::_all_periods, avg 24µs/call |
1067 | 2 | 2µs | my $beg = $period[0]->[9]; | ||
1068 | 2 | 1µs | my $end = $period[-1]->[11]; | ||
1069 | 2 | 6µs | if (($dates cmp $beg) == -1) { | ||
1070 | @period = $self->_all_periods($zone,$year-1); | ||||
1071 | } elsif (($dates cmp $end) == 1) { | ||||
1072 | @period = $self->_all_periods($zone,$year+1); | ||||
1073 | } | ||||
1074 | |||||
1075 | 2 | 500ns | my(@per); | ||
1076 | 2 | 2µs | foreach my $period (@period) { | ||
1077 | 2 | 4µs | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||
1078 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
1079 | 2 | 4µs | if (($dates cmp $begLTs) != -1 && ($dates cmp $endLTs) != 1) { | ||
1080 | push(@per,$period); | ||||
1081 | } | ||||
1082 | } | ||||
1083 | |||||
1084 | 2 | 19µs | if ($#per == -1) { | ||
1085 | return (); | ||||
1086 | } elsif ($#per == 0) { | ||||
1087 | return $per[0]; | ||||
1088 | } elsif ($#per == 1) { | ||||
1089 | if ($per[0][5] == $isdst) { | ||||
1090 | return $per[0]; | ||||
1091 | } else { | ||||
1092 | return $per[1]; | ||||
1093 | } | ||||
1094 | } else { | ||||
1095 | warn "ERROR: [date_period] Impossible error\n"; | ||||
1096 | return; | ||||
1097 | } | ||||
1098 | |||||
1099 | } else { | ||||
1100 | # A GMT date | ||||
1101 | |||||
1102 | my @period = $self->_all_periods($zone,$year); | ||||
1103 | foreach my $period (@period) { | ||||
1104 | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$isdst,$endUT,$endLT, | ||||
1105 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
1106 | if (($dates cmp $begUTs) != -1 && ($dates cmp $endUTs) != 1) { | ||||
1107 | return $period; | ||||
1108 | } | ||||
1109 | } | ||||
1110 | warn "ERROR: [date_period] Impossible error\n"; | ||||
1111 | return; | ||||
1112 | } | ||||
1113 | } | ||||
1114 | |||||
1115 | # Calculate critical dates from the last rule. If $endonly is passed | ||||
1116 | # in, it only calculates the ending of the zone period before the | ||||
1117 | # start of the first one. This is necessary so that the last period in | ||||
1118 | # one year can find out when it ends (which is determined in the | ||||
1119 | # following year). | ||||
1120 | # | ||||
1121 | # Returns: | ||||
1122 | # [begUT, begLT, offsetstr, offset, abb, ISDST, endUT, endLT, | ||||
1123 | # begUTstr, begLTstr, endUTstr, endLTstr] | ||||
1124 | # for each. | ||||
1125 | # | ||||
1126 | sub _lastrule { | ||||
1127 | my($self,$zone,$year,$endonly) = @_; | ||||
1128 | |||||
1129 | # | ||||
1130 | # Get the list of rules (actually, the month in which the | ||||
1131 | # rule triggers a time change). If there are none, then | ||||
1132 | # this zone doesn't have a LAST RULE. | ||||
1133 | # | ||||
1134 | |||||
1135 | my @mon = (sort keys | ||||
1136 | %{ $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'} }); | ||||
1137 | return () if (! @mon); | ||||
1138 | |||||
1139 | # | ||||
1140 | # Analyze each time change. | ||||
1141 | # | ||||
1142 | |||||
1143 | my @dates = (); | ||||
1144 | my $dmb = $$self{'objs'}{'base'}; | ||||
1145 | |||||
1146 | my $stdoff = $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}{'stdoff'}; | ||||
1147 | my $dstoff = $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}{'dstoff'}; | ||||
1148 | |||||
1149 | my (@period); | ||||
1150 | |||||
1151 | foreach my $mon (@mon) { | ||||
1152 | my $flag = | ||||
1153 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'flag'}; | ||||
1154 | my $dow = | ||||
1155 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'dow'}; | ||||
1156 | my $num = | ||||
1157 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'num'}; | ||||
1158 | my $isdst= | ||||
1159 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'isdst'}; | ||||
1160 | my $time = | ||||
1161 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'time'}; | ||||
1162 | my $type = | ||||
1163 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'type'}; | ||||
1164 | my $abb = | ||||
1165 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'abb'}; | ||||
1166 | |||||
1167 | # The end of the current period and the beginning of the next | ||||
1168 | my($endUT,$endLT,$begUT,$begLT) = | ||||
1169 | $dmb->_critical_date($year,$mon,$flag,$num,$dow, | ||||
1170 | $isdst,$time,$type,$stdoff,$dstoff); | ||||
1171 | return ($endUT,$endLT) if ($endonly); | ||||
1172 | |||||
1173 | if (@period) { | ||||
1174 | push(@period,$endUT,$endLT); | ||||
1175 | push(@dates,[@period]); | ||||
1176 | } | ||||
1177 | my $offsetstr = ($isdst ? $dstoff : $stdoff); | ||||
1178 | my $offset = $dmb->split('offset',$offsetstr); | ||||
1179 | |||||
1180 | @period = ($begUT,$begLT,$offsetstr,$offset,$abb,$isdst); | ||||
1181 | } | ||||
1182 | |||||
1183 | push(@period,$self->_lastrule($zone,$year+1,1)); | ||||
1184 | push(@dates,[@period]); | ||||
1185 | |||||
1186 | foreach my $period (@dates) { | ||||
1187 | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT) = @$period; | ||||
1188 | my $begUTstr = $dmb->join("date",$begUT); | ||||
1189 | my $begLTstr = $dmb->join("date",$begLT); | ||||
1190 | my $endUTstr = $dmb->join("date",$endUT); | ||||
1191 | my $endLTstr = $dmb->join("date",$endLT); | ||||
1192 | $period = [$begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||||
1193 | $begUTstr,$begLTstr,$endUTstr,$endLTstr]; | ||||
1194 | } | ||||
1195 | |||||
1196 | return @dates; | ||||
1197 | } | ||||
1198 | |||||
1199 | ######################################################################## | ||||
1200 | # CONVERSION | ||||
1201 | ######################################################################## | ||||
1202 | |||||
1203 | sub convert { | ||||
1204 | my($self,$date,$from,$to,$isdst) = @_; | ||||
1205 | $self->_convert('convert',$date,$from,$to,$isdst); | ||||
1206 | } | ||||
1207 | |||||
1208 | # spent 137µs (23+114) within Date::Manip::TZ::convert_to_gmt which was called:
# once (23µs+114µs) by Date::Manip::Base::_config_var_setdate at line 1815 of Date/Manip/Base.pm | ||||
1209 | 1 | 6µs | my($self,$date,@arg) = @_; | ||
1210 | 1 | 5µs | 1 | 11µs | my($err,$from,$isdst) = _convert_args('convert_to_gmt',@arg); # spent 11µs making 1 call to Date::Manip::TZ::_convert_args |
1211 | 1 | 300ns | return (1) if ($err); | ||
1212 | |||||
1213 | 1 | 2µs | my $dmb = $$self{'objs'}{'base'}; | ||
1214 | |||||
1215 | 1 | 500ns | if (! $from) { | ||
1216 | ($from) = $dmb->_now('tz',1); | ||||
1217 | } | ||||
1218 | 1 | 8µs | 1 | 103µs | $self->_convert('convert_to_gmt',$date,$from,'GMT',$isdst); # spent 103µs making 1 call to Date::Manip::TZ::_convert |
1219 | } | ||||
1220 | |||||
1221 | sub convert_from_gmt { | ||||
1222 | my($self,$date,@arg) = @_; | ||||
1223 | my($err,$to,$isdst) = _convert_args('convert_from_gmt',@arg); | ||||
1224 | return (1) if ($err); | ||||
1225 | |||||
1226 | my $dmb = $$self{'objs'}{'base'}; | ||||
1227 | |||||
1228 | if (! $to) { | ||||
1229 | ($to) = $dmb->_now('tz',1); | ||||
1230 | } | ||||
1231 | $self->_convert('convert_from_gmt',$date,'GMT',$to,$isdst); | ||||
1232 | } | ||||
1233 | |||||
1234 | sub convert_to_local { | ||||
1235 | my($self,$date,@arg) = @_; | ||||
1236 | my($err,$from,$isdst) = _convert_args('convert_to_local',@arg); | ||||
1237 | return (1) if ($err); | ||||
1238 | |||||
1239 | my $dmb = $$self{'objs'}{'base'}; | ||||
1240 | |||||
1241 | if (! $from) { | ||||
1242 | $from = 'GMT'; | ||||
1243 | } | ||||
1244 | $self->_convert('convert_to_local',$date,$from,$dmb->_now('tz',1),$isdst); | ||||
1245 | } | ||||
1246 | |||||
1247 | sub convert_from_local { | ||||
1248 | my($self,$date,@arg) = @_; | ||||
1249 | my($err,$to,$isdst) = _convert_args('convert_from_local',@arg); | ||||
1250 | return (1) if ($err); | ||||
1251 | |||||
1252 | my $dmb = $$self{'objs'}{'base'}; | ||||
1253 | |||||
1254 | if (! $to) { | ||||
1255 | $to = 'GMT'; | ||||
1256 | } | ||||
1257 | $self->_convert('convert_from_local',$date,$dmb->_now('tz',1),$to,$isdst); | ||||
1258 | } | ||||
1259 | |||||
1260 | # spent 11µs within Date::Manip::TZ::_convert_args which was called:
# once (11µs+0s) by Date::Manip::TZ::convert_to_gmt at line 1210 | ||||
1261 | 1 | 2µs | my($caller,@args) = @_; | ||
1262 | |||||
1263 | 1 | 5µs | if ($#args == -1) { | ||
1264 | return (0,'',0); | ||||
1265 | } elsif ($#args == 0) { | ||||
1266 | if ($args[0] eq '0' || | ||||
1267 | $args[0] eq '1') { | ||||
1268 | return (0,'',$args[0]); | ||||
1269 | } else { | ||||
1270 | 1 | 6µs | return (0,$args[0],0); | ||
1271 | } | ||||
1272 | } elsif ($#args == 1) { | ||||
1273 | return (0,@args); | ||||
1274 | } else { | ||||
1275 | return (1,'',0); | ||||
1276 | } | ||||
1277 | } | ||||
1278 | |||||
1279 | # spent 103µs (35+68) within Date::Manip::TZ::_convert which was called:
# once (35µs+68µs) by Date::Manip::TZ::convert_to_gmt at line 1218 | ||||
1280 | 1 | 2µs | my($self,$caller,$date,$from,$to,$isdst) = @_; | ||
1281 | 1 | 1µs | my $dmb = $$self{'objs'}{'base'}; | ||
1282 | |||||
1283 | # Handle $date as a reference and a string | ||||
1284 | 1 | 800ns | my (@date); | ||
1285 | 1 | 3µs | if (ref($date)) { | ||
1286 | @date = @$date; | ||||
1287 | } else { | ||||
1288 | @date = @{ $dmb->split('date',$date) }; | ||||
1289 | $date = [@date]; | ||||
1290 | } | ||||
1291 | |||||
1292 | 1 | 1µs | if ($from ne $to) { | ||
1293 | 1 | 2µs | 1 | 3µs | my $tmp = $self->_zone($from); # spent 3µs making 1 call to Date::Manip::TZ::_zone |
1294 | 1 | 700ns | if (! $tmp) { | ||
1295 | return (2); | ||||
1296 | } | ||||
1297 | 1 | 400ns | $from = $tmp; | ||
1298 | |||||
1299 | 1 | 2µs | 1 | 4µs | $tmp = $self->_zone($to); # spent 4µs making 1 call to Date::Manip::TZ::_zone |
1300 | 1 | 400ns | if (! $tmp) { | ||
1301 | return (3); | ||||
1302 | } | ||||
1303 | 1 | 500ns | $to = $tmp; | ||
1304 | } | ||||
1305 | |||||
1306 | 1 | 1µs | if ($from eq $to) { | ||
1307 | 1 | 3µs | 1 | 61µs | my $per = $self->date_period($date,$from,1,$isdst); # spent 61µs making 1 call to Date::Manip::TZ::date_period |
1308 | 1 | 800ns | my $offset = $$per[3]; | ||
1309 | 1 | 800ns | my $abb = $$per[4]; | ||
1310 | 1 | 6µs | return (0,$date,$offset,$isdst,$abb); | ||
1311 | } | ||||
1312 | |||||
1313 | # Convert $date from $from to GMT | ||||
1314 | |||||
1315 | if ($from ne "Etc/GMT") { | ||||
1316 | my $per = $self->date_period($date,$from,1,$isdst); | ||||
1317 | if (! $per) { | ||||
1318 | return (4); | ||||
1319 | } | ||||
1320 | my $offset = $$per[3]; | ||||
1321 | @date = @{ $dmb->calc_date_time(\@date,$offset,1) }; | ||||
1322 | } | ||||
1323 | |||||
1324 | # Convert $date from GMT to $to | ||||
1325 | |||||
1326 | $isdst = 0; | ||||
1327 | my $offset = [0,0,0]; | ||||
1328 | my $abb = 'GMT'; | ||||
1329 | |||||
1330 | if ($to ne "Etc/GMT") { | ||||
1331 | my $per = $self->date_period([@date],$to,0); | ||||
1332 | $offset = $$per[3]; | ||||
1333 | $isdst = $$per[5]; | ||||
1334 | $abb = $$per[4]; | ||||
1335 | @date = @{ $dmb->calc_date_time(\@date,$offset) }; | ||||
1336 | } | ||||
1337 | |||||
1338 | return (0,[@date],$offset,$isdst,$abb); | ||||
1339 | } | ||||
1340 | |||||
1341 | ######################################################################## | ||||
1342 | # REGULAR EXPRESSIONS FOR TIMEZONE INFORMATION | ||||
1343 | ######################################################################## | ||||
1344 | |||||
1345 | # Returns a regular expression capable of matching all timezone names | ||||
1346 | # and aliases. | ||||
1347 | # | ||||
1348 | # The regular expression will have the following named matches: | ||||
1349 | # zone = a zone name or alias | ||||
1350 | # | ||||
1351 | sub _zonerx { | ||||
1352 | my($self) = @_; | ||||
1353 | return $$self{'data'}{'zonerx'} if (defined $$self{'data'}{'zonerx'}); | ||||
1354 | my @zone = (keys %{ $$self{'data'}{'Alias'} }, | ||||
1355 | keys %{ $$self{'data'}{'MyAlias'} }); | ||||
1356 | @zone = sort _sortByLength(@zone); | ||||
1357 | foreach my $zone (@zone) { | ||||
1358 | $zone =~ s/\057/\\057/g; # / | ||||
1359 | $zone =~ s/\055/\\055/g; # - | ||||
1360 | $zone =~ s/\056/\\056/g; # . | ||||
1361 | $zone =~ s/\050/\\050/g; # ( | ||||
1362 | $zone =~ s/\051/\\051/g; # ) | ||||
1363 | $zone =~ s/\053/\\053/g; # + | ||||
1364 | } | ||||
1365 | my $re = join('|',@zone); | ||||
1366 | $$self{'data'}{'zonerx'} = qr/(?<zone>$re)/i; | ||||
1367 | return $$self{'data'}{'zonerx'}; | ||||
1368 | } | ||||
1369 | |||||
1370 | # Returns a regular expression capable of matching all abbreviations. | ||||
1371 | # | ||||
1372 | # The regular expression will have the following named matches: | ||||
1373 | # abb = a zone abbreviation | ||||
1374 | # | ||||
1375 | sub _abbrx { | ||||
1376 | my($self) = @_; | ||||
1377 | return $$self{'data'}{'abbrx'} if (defined $$self{'data'}{'abbrx'}); | ||||
1378 | my @abb = (keys %{ $$self{'data'}{'Abbrev'} }, | ||||
1379 | keys %{ $$self{'data'}{'MyAbbrev'} }); | ||||
1380 | @abb = sort _sortByLength(@abb); | ||||
1381 | foreach my $abb (@abb) { | ||||
1382 | $abb =~ s/\055/\\055/g; # - | ||||
1383 | $abb =~ s/\053/\\053/g; # + | ||||
1384 | } | ||||
1385 | my $re = join('|',@abb); | ||||
1386 | $$self{'data'}{'abbrx'} = qr/(?<abb>$re)/i; | ||||
1387 | return $$self{'data'}{'abbrx'}; | ||||
1388 | } | ||||
1389 | |||||
1390 | # Returns a regular expression capable of matching a valid timezone as | ||||
1391 | # an offset. Known formats are: | ||||
1392 | # +07 +07 (HST) | ||||
1393 | # +0700 +0700 (HST) | ||||
1394 | # +07:00 +07:00 (HST) | ||||
1395 | # +070000 +070000 (HST) | ||||
1396 | # +07:00:00 +07:00:00 (HST) | ||||
1397 | # | ||||
1398 | # The regular expression will have the following named matches: | ||||
1399 | # off = the offset | ||||
1400 | # abb = the abbreviation | ||||
1401 | # | ||||
1402 | sub _offrx { | ||||
1403 | my($self) = @_; | ||||
1404 | return $$self{'data'}{'offrx'} if (defined $$self{'data'}{'offrx'}); | ||||
1405 | |||||
1406 | my($hr) = qr/(?:[0-1][0-9]|2[0-3])/; # 00 - 23 | ||||
1407 | my($mn) = qr/(?:[0-5][0-9])/; # 00 - 59 | ||||
1408 | my($ss) = qr/(?:[0-5][0-9])/; # 00 - 59 | ||||
1409 | my($abb)= $self->_abbrx(); | ||||
1410 | |||||
1411 | my($re) = qr/ (?<off> [+-] (?: $hr:$mn:$ss | | ||||
1412 | $hr$mn$ss | | ||||
1413 | $hr:?$mn | | ||||
1414 | $hr | ||||
1415 | ) | ||||
1416 | ) | ||||
1417 | (?: \s* \( $abb \))? /ix; | ||||
1418 | |||||
1419 | $$self{'data'}{'offrx'} = $re; | ||||
1420 | return $$self{'data'}{'offrx'}; | ||||
1421 | } | ||||
1422 | |||||
1423 | # Returns a regular expression capable of matching all timezone | ||||
1424 | # information available. It will match a full timezone, an | ||||
1425 | # abbreviation, or an offset/abbreviation combination. The regular | ||||
1426 | # expression will have the following named matches: | ||||
1427 | # tzstring = the full string matched | ||||
1428 | # in addition to the matches from the _zonerx, _abbrx, and _offrx | ||||
1429 | # functions. | ||||
1430 | # | ||||
1431 | sub _zrx { | ||||
1432 | my($self) = @_; | ||||
1433 | return $$self{'data'}{'zrx'} if (defined $$self{'data'}{'zrx'}); | ||||
1434 | |||||
1435 | my $zonerx = $self->_zonerx(); # (?<zone>america/new_york|...) | ||||
1436 | my $zoneabbrx = $self->_abbrx(); # (?<abb>edt|est|...) | ||||
1437 | my $zoneoffrx = $self->_offrx(); # (?<off>07:00) (?<abb>GMT) | ||||
1438 | |||||
1439 | my $zrx = qr/(?<tzstring>$zonerx|$zoneabbrx|$zoneoffrx)/; | ||||
1440 | $$self{'data'}{'zrx'} = $zrx; | ||||
1441 | return $zrx; | ||||
1442 | } | ||||
1443 | |||||
1444 | # This sorts from longest to shortest element | ||||
1445 | # | ||||
1446 | 3 | 80µs | 2 | 64µs | # spent 41µs (18+23) within Date::Manip::TZ::BEGIN@1446 which was called:
# once (18µs+23µs) by Date::Manip::Obj::BEGIN@16 at line 1446 # spent 41µs making 1 call to Date::Manip::TZ::BEGIN@1446
# spent 23µs making 1 call to strict::unimport |
1447 | sub _sortByLength { | ||||
1448 | return (length $b <=> length $a); | ||||
1449 | } | ||||
1450 | 3 | 81µs | 2 | 54µs | # spent 35µs (17+18) within Date::Manip::TZ::BEGIN@1450 which was called:
# once (17µs+18µs) by Date::Manip::Obj::BEGIN@16 at line 1450 # spent 35µs making 1 call to Date::Manip::TZ::BEGIN@1450
# spent 18µs making 1 call to strict::import |
1451 | |||||
1452 | 1 | 16µs | 1; | ||
1453 | # Local Variables: | ||||
1454 | # mode: cperl | ||||
1455 | # indent-tabs-mode: nil | ||||
1456 | # cperl-indent-level: 3 | ||||
1457 | # cperl-continued-statement-offset: 2 | ||||
1458 | # cperl-continued-brace-offset: 0 | ||||
1459 | # cperl-brace-offset: 0 | ||||
1460 | # cperl-brace-imaginary-offset: 0 | ||||
1461 | # cperl-label-offset: -2 | ||||
1462 | # End: | ||||
# spent 5µs within Date::Manip::TZ::CORE:close which was called 2 times, avg 2µs/call:
# 2 times (5µs+0s) by Date::Manip::TZ::_get_curr_zone at line 435, avg 2µs/call | |||||
# spent 26µs within Date::Manip::TZ::CORE:ftfile which was called 4 times, avg 6µs/call:
# 4 times (26µs+0s) by Date::Manip::TZ::_get_curr_zone at line 413, avg 6µs/call | |||||
# spent 22µs within Date::Manip::TZ::CORE:match which was called 8 times, avg 3µs/call:
# 4 times (10µs+0s) by Date::Manip::TZ::_get_curr_zone at line 420, avg 2µs/call
# 2 times (8µs+0s) by Date::Manip::TZ::zone at line 638, avg 4µs/call
# 2 times (4µs+0s) by Date::Manip::TZ::_get_curr_zone at line 422, avg 2µs/call | |||||
# spent 5µs within Date::Manip::TZ::CORE:readline which was called 2 times, avg 3µs/call:
# 2 times (5µs+0s) by Date::Manip::TZ::_get_curr_zone at line 419, avg 3µs/call | |||||
# spent 3µs within Date::Manip::TZ::CORE:sort which was called:
# once (3µs+0s) by Date::Manip::TZ::_all_periods at line 935 | |||||
# spent 9µs within Date::Manip::TZ::CORE:subst which was called 6 times, avg 2µs/call:
# 2 times (6µs+0s) by Date::Manip::TZ::_get_curr_zone at line 430, avg 3µs/call
# 2 times (2µs+0s) by Date::Manip::TZ::_get_curr_zone at line 431, avg 1µs/call
# 2 times (2µs+0s) by Date::Manip::TZ::_get_curr_zone at line 497, avg 850ns/call |