Filename | /usr/share/perl5/Date/Manip/TZ.pm |
Statements | Executed 453 statements in 8.53ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 2 | 1 | 1.09ms | 1.14ms | _module | Date::Manip::TZ::
2 | 1 | 1 | 262µs | 286µs | _init | Date::Manip::TZ::
2 | 1 | 1 | 216µs | 392µs | _get_curr_zone | Date::Manip::TZ::
1 | 1 | 1 | 157µs | 374µs | BEGIN@1601 | Date::Manip::TZ::
1 | 1 | 1 | 69µs | 1.46ms | _config_var_setdate | Date::Manip::TZ::
1 | 1 | 1 | 62µs | 1.25ms | zone | Date::Manip::TZ::
3 | 2 | 1 | 42µs | 54µs | _all_periods | Date::Manip::TZ::
1 | 1 | 1 | 40µs | 50µs | BEGIN@1605 | Date::Manip::TZ::
2 | 2 | 1 | 37µs | 70µs | date_period | Date::Manip::TZ::
10 | 7 | 1 | 27µs | 27µs | _zone | Date::Manip::TZ::
1 | 1 | 1 | 22µs | 22µs | CORE:regcomp (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 16µs | 47µs | _convert | Date::Manip::TZ::
2 | 1 | 1 | 16µs | 412µs | _set_curr_zone | Date::Manip::TZ::
9 | 4 | 1 | 16µs | 16µs | CORE:match (opcode) | Date::Manip::TZ::
10 | 5 | 1 | 12µs | 12µs | CORE:subst (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 11µs | 1.47ms | _config_var_tz | Date::Manip::TZ::
1 | 1 | 1 | 10µs | 24µs | BEGIN@721 | Date::Manip::TZ::
1 | 1 | 1 | 10µs | 10µs | _periods | Date::Manip::TZ::
2 | 1 | 1 | 10µs | 10µs | END | Date::Manip::TZ::
1 | 1 | 1 | 10µs | 61µs | convert_to_gmt | Date::Manip::TZ::
1 | 1 | 1 | 9µs | 9µs | BEGIN@14 | Date::Manip::TZ::
1 | 1 | 1 | 8µs | 110µs | BEGIN@22 | Date::Manip::TZ::
1 | 1 | 1 | 8µs | 12µs | BEGIN@731 | Date::Manip::TZ::
4 | 1 | 1 | 8µs | 8µs | CORE:ftfile (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 7µs | 12µs | BEGIN@19 | Date::Manip::TZ::
1 | 1 | 1 | 6µs | 15µs | BEGIN@158 | Date::Manip::TZ::
2 | 1 | 1 | 6µs | 418µs | _init_final | Date::Manip::TZ::
4 | 4 | 1 | 6µs | 6µs | CORE:qr (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 6µs | 13µs | BEGIN@189 | Date::Manip::TZ::
1 | 1 | 1 | 5µs | 14µs | BEGIN@20 | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 4µs | BEGIN@15 | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 4µs | _convert_args | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 4µs | BEGIN@24 | Date::Manip::TZ::
2 | 1 | 1 | 2µs | 2µs | CORE:readline (opcode) | Date::Manip::TZ::
2 | 1 | 1 | 1µs | 1µs | CORE:close (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 1µs | 1µ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 |
---|---|---|---|---|---|
1 | package Date::Manip::TZ; | ||||
2 | # Copyright (c) 2008-2014 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 | 2 | 25µs | 1 | 9µs | # spent 9µs within Date::Manip::TZ::BEGIN@14 which was called:
# once (9µs+0s) by Date::Manip::Date::BEGIN@27 at line 14 # spent 9µs making 1 call to Date::Manip::TZ::BEGIN@14 |
15 | 2 | 33µs | 1 | 4µs | # spent 4µs within Date::Manip::TZ::BEGIN@15 which was called:
# once (4µs+0s) by Date::Manip::Date::BEGIN@27 at line 15 # spent 4µs making 1 call to Date::Manip::TZ::BEGIN@15 |
16 | 1 | 7µs | @ISA = qw(Date::Manip::Obj Date::Manip::TZ_Base); | ||
17 | |||||
18 | 1 | 7µs | require 5.010000; | ||
19 | 2 | 18µs | 2 | 16µs | # spent 12µs (7+5) within Date::Manip::TZ::BEGIN@19 which was called:
# once (7µs+5µs) by Date::Manip::Date::BEGIN@27 at line 19 # spent 12µs making 1 call to Date::Manip::TZ::BEGIN@19
# spent 4µs making 1 call to warnings::import |
20 | 2 | 19µs | 2 | 23µs | # spent 14µs (5+9) within Date::Manip::TZ::BEGIN@20 which was called:
# once (5µs+9µs) by Date::Manip::Date::BEGIN@27 at line 20 # spent 14µs making 1 call to Date::Manip::TZ::BEGIN@20
# spent 9µs making 1 call to strict::import |
21 | |||||
22 | 2 | 26µs | 2 | 212µs | # spent 110µs (8+102) within Date::Manip::TZ::BEGIN@22 which was called:
# once (8µs+102µs) by Date::Manip::Date::BEGIN@27 at line 22 # spent 110µs making 1 call to Date::Manip::TZ::BEGIN@22
# spent 102µs making 1 call to Exporter::import |
23 | 1 | 1.03ms | require Date::Manip::Zones; | ||
24 | 2 | 318µs | 1 | 4µs | # spent 4µs within Date::Manip::TZ::BEGIN@24 which was called:
# once (4µs+0s) by Date::Manip::Date::BEGIN@27 at line 24 # spent 4µs making 1 call to Date::Manip::TZ::BEGIN@24 |
25 | |||||
26 | 1 | 300ns | our $VERSION; | ||
27 | 1 | 400ns | $VERSION='6.47'; | ||
28 | 1 | 2µs | END { undef $VERSION; } | ||
29 | |||||
30 | # To get rid of a 'used only once' warnings. | ||||
31 | # spent 10µs within Date::Manip::TZ::END which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by main::RUNTIME at line 131 of C4/Service.pm, avg 5µs/call | ||||
32 | 1 | 1µs | my $tmp = \%Date::Manip::Zones::Module; | ||
33 | 1 | 800ns | $tmp = \%Date::Manip::Zones::ZoneNames; | ||
34 | 1 | 400ns | $tmp = \%Date::Manip::Zones::Alias; | ||
35 | 1 | 500ns | $tmp = \%Date::Manip::Zones::Abbrev; | ||
36 | 1 | 200ns | $tmp = \%Date::Manip::Zones::Offmod; | ||
37 | 1 | 700ns | $tmp = $Date::Manip::Zones::FirstDate; | ||
38 | 1 | 300ns | $tmp = $Date::Manip::Zones::LastDate; | ||
39 | 1 | 200ns | $tmp = $Date::Manip::Zones::LastYear; | ||
40 | 1 | 300ns | $tmp = $Date::Manip::Zones::TzcodeVersion; | ||
41 | 1 | 4µs | $tmp = $Date::Manip::Zones::TzdataVersion; | ||
42 | } | ||||
43 | |||||
44 | ######################################################################## | ||||
45 | # BASE METHODS | ||||
46 | ######################################################################## | ||||
47 | |||||
48 | # spent 286µs (262+24) within Date::Manip::TZ::_init which was called 2 times, avg 143µs/call:
# 2 times (262µs+24µs) by Date::Manip::Obj::new at line 162 of Date/Manip/Obj.pm, avg 143µs/call | ||||
49 | 2 | 600ns | my($self) = @_; | ||
50 | |||||
51 | 2 | 236µs | $$self{'data'} = | ||
52 | { | ||||
53 | # These are the variables defined in Date::Manip::Zones | ||||
54 | 'Module' => \%Date::Manip::Zones::Module, | ||||
55 | 'ZoneNames' => \%Date::Manip::Zones::ZoneNames, | ||||
56 | 'Alias' => \%Date::Manip::Zones::Alias, | ||||
57 | 'Abbrev' => \%Date::Manip::Zones::Abbrev, | ||||
58 | 'Offmod' => \%Date::Manip::Zones::Offmod, | ||||
59 | 'FirstDate' => $Date::Manip::Zones::FirstDate, | ||||
60 | 'LastDate' => $Date::Manip::Zones::LastDate, | ||||
61 | 'LastYear' => $Date::Manip::Zones::LastYear, | ||||
62 | |||||
63 | # These override values from Date::Manip::Zones | ||||
64 | 'MyAlias' => {}, | ||||
65 | 'MyAbbrev' => {}, | ||||
66 | 'MyOffsets' => {}, | ||||
67 | |||||
68 | # Each timezone/offset module that is loaded goes here | ||||
69 | 'Zones' => {}, | ||||
70 | 'Offsets' => {}, | ||||
71 | |||||
72 | # methods a list of methods used for determining the | ||||
73 | # current zone | ||||
74 | # path the PATH to set for determining the current | ||||
75 | # zone | ||||
76 | # dates critical dates on a per/year (UT) basis | ||||
77 | # zonerx the regular expression for matching timezone | ||||
78 | # names/aliases | ||||
79 | # abbrx the regular expression for matching timezone | ||||
80 | # abbreviations | ||||
81 | # offrx the regular expression for matching a valid | ||||
82 | # timezone offset | ||||
83 | # zrx the regular expression to match all timezone | ||||
84 | # information | ||||
85 | 'methods' => [], | ||||
86 | 'path' => undef, | ||||
87 | 'zonerx' => undef, | ||||
88 | 'abbrx' => undef, | ||||
89 | 'offrx' => undef, | ||||
90 | 'zrx' => undef, | ||||
91 | }; | ||||
92 | |||||
93 | # OS specific stuff | ||||
94 | |||||
95 | 2 | 1µs | my $dmb = $$self{'base'}; | ||
96 | 2 | 4µs | 2 | 24µs | my $os = $dmb->_os(); # spent 24µs making 2 calls to Date::Manip::Base::_os, avg 12µs/call |
97 | |||||
98 | 2 | 5µs | if ($os eq 'Unix') { | ||
99 | 2 | 1µs | $$self{'data'}{'path'} = '/bin:/usr/bin'; | ||
100 | 2 | 13µs | $$self{'data'}{'methods'} = [ | ||
101 | qw(main TZ | ||||
102 | env zone TZ | ||||
103 | file /etc/TIMEZONE | ||||
104 | file /etc/timezone | ||||
105 | file /etc/sysconfig/clock | ||||
106 | file /etc/default/init | ||||
107 | ), | ||||
108 | 'command', '/bin/date +%Z', | ||||
109 | 'command', '/usr/bin/date +%Z', | ||||
110 | 'command', '/usr/local/bin/date +%Z', | ||||
111 | qw(cmdfield /bin/date -2 | ||||
112 | cmdfield /usr/bin/date -2 | ||||
113 | cmdfield /usr/local/bin/date -2 | ||||
114 | ), | ||||
115 | 'command', '/bin/date +%z', | ||||
116 | 'command', '/usr/bin/date +%z', | ||||
117 | 'command', '/usr/local/bin/date +%z', | ||||
118 | 'gmtoff' | ||||
119 | ]; | ||||
120 | |||||
121 | } elsif ($os eq 'Windows') { | ||||
122 | $$self{'data'}{'methods'} = [ | ||||
123 | qw(main TZ | ||||
124 | env zone TZ | ||||
125 | registry | ||||
126 | gmtoff), | ||||
127 | ]; | ||||
128 | |||||
129 | } elsif ($os eq 'VMS') { | ||||
130 | $$self{'data'}{'methods'} = [ | ||||
131 | qw(main TZ | ||||
132 | env zone TZ | ||||
133 | env zone SYS$TIMEZONE_NAME | ||||
134 | env zone UCX$TZ | ||||
135 | env zone TCPIP$TZ | ||||
136 | env zone MULTINET_TIMEZONE | ||||
137 | env offset SYS$TIMEZONE_DIFFERENTIAL | ||||
138 | gmtoff | ||||
139 | ), | ||||
140 | ]; | ||||
141 | |||||
142 | } else { | ||||
143 | $$self{'data'}{'methods'} = [ | ||||
144 | qw(main TZ | ||||
145 | env zone TZ | ||||
146 | gmtoff | ||||
147 | ), | ||||
148 | ]; | ||||
149 | } | ||||
150 | } | ||||
151 | |||||
152 | # spent 418µs (6+412) within Date::Manip::TZ::_init_final which was called 2 times, avg 209µs/call:
# 2 times (6µs+412µs) by Date::Manip::Obj::new at line 165 of Date/Manip/Obj.pm, avg 209µs/call | ||||
153 | 2 | 400ns | my($self) = @_; | ||
154 | |||||
155 | 2 | 7µs | 2 | 412µs | $self->_set_curr_zone(); # spent 412µs making 2 calls to Date::Manip::TZ::_set_curr_zone, avg 206µs/call |
156 | } | ||||
157 | |||||
158 | 2 | 165µs | 2 | 24µs | # spent 15µs (6+9) within Date::Manip::TZ::BEGIN@158 which was called:
# once (6µs+9µs) by Date::Manip::Date::BEGIN@27 at line 158 # spent 15µs making 1 call to Date::Manip::TZ::BEGIN@158
# spent 9µs making 1 call to strict::unimport |
159 | # This loads data from an offset module | ||||
160 | # | ||||
161 | sub _offmod { | ||||
162 | my($self,$offset) = @_; | ||||
163 | return if (exists $$self{'data'}{'Offsets'}{$offset}); | ||||
164 | |||||
165 | my $mod = $$self{'data'}{'Offmod'}{$offset}; | ||||
166 | eval "require Date::Manip::Offset::${mod}"; | ||||
167 | my %off = %{ "Date::Manip::Offset::${mod}::Offset" }; | ||||
168 | |||||
169 | $$self{'data'}{'Offsets'}{$offset} = { %off }; | ||||
170 | } | ||||
171 | |||||
172 | # This loads data from a zone module (takes a lowercase zone) | ||||
173 | # | ||||
174 | sub _module { | ||||
175 | 3 | 900ns | my($self,$zone) = @_; | ||
176 | 3 | 6µs | return if (exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||
177 | |||||
178 | 1 | 1µs | my $mod = $$self{'data'}{'Module'}{$zone}; | ||
179 | 1 | 43µs | eval "require Date::Manip::TZ::${mod}"; # spent 870µs executing statements in string eval | ||
180 | 1 | 3µs | my %dates = %{ "Date::Manip::TZ::${mod}::Dates" }; | ||
181 | 1 | 2µs | my %last = %{ "Date::Manip::TZ::${mod}::LastRule" }; | ||
182 | 1 | 8µs | $$self{'data'}{'Zones'}{$zone} = | ||
183 | { | ||||
184 | 'Dates' => { %dates }, | ||||
185 | 'LastRule' => { %last }, | ||||
186 | 'Loaded' => 1 | ||||
187 | }; | ||||
188 | } | ||||
189 | 2 | 2.10ms | 2 | 21µs | # spent 13µs (6+8) within Date::Manip::TZ::BEGIN@189 which was called:
# once (6µs+8µs) by Date::Manip::Date::BEGIN@27 at line 189 # spent 13µs making 1 call to Date::Manip::TZ::BEGIN@189
# spent 8µs making 1 call to strict::import |
190 | |||||
191 | ######################################################################## | ||||
192 | # CHECKING/MODIFYING ZONEINFO DATA | ||||
193 | ######################################################################## | ||||
194 | |||||
195 | # spent 27µs within Date::Manip::TZ::_zone which was called 10 times, avg 3µs/call:
# 2 times (10µs+0s) by Date::Manip::TZ::_get_curr_zone at line 635, avg 5µs/call
# 2 times (4µs+0s) by Date::Manip::TZ::date_period at line 1188, avg 2µs/call
# 2 times (4µs+0s) by Date::Manip::TZ::_set_curr_zone at line 388, avg 2µs/call
# once (4µs+0s) by Date::Manip::TZ::zone at line 773
# once (2µs+0s) by Date::Manip::TZ::_convert at line 1437
# once (2µs+0s) by Date::Manip::TZ::_config_var_setdate at line 1805
# once (2µs+0s) by Date::Manip::TZ::_convert at line 1431 | ||||
196 | 10 | 3µs | my($self,$zone) = @_; | ||
197 | 10 | 3µs | $zone = lc($zone); | ||
198 | |||||
199 | 10 | 32µs | if (exists $$self{'data'}{'MyAlias'}{$zone}) { | ||
200 | return $$self{'data'}{'MyAlias'}{$zone}; | ||||
201 | } elsif (exists $$self{'data'}{'Alias'}{$zone}) { | ||||
202 | return $$self{'data'}{'Alias'}{$zone}; | ||||
203 | } else { | ||||
204 | return ''; | ||||
205 | } | ||||
206 | } | ||||
207 | |||||
208 | sub tzdata { | ||||
209 | my($self) = @_; | ||||
210 | return $Date::Manip::Zones::TzdataVersion; | ||||
211 | } | ||||
212 | |||||
213 | sub tzcode { | ||||
214 | my($self) = @_; | ||||
215 | return $Date::Manip::Zones::TzcodeVersion; | ||||
216 | } | ||||
217 | |||||
218 | sub define_alias { | ||||
219 | my($self,$alias,$zone) = @_; | ||||
220 | $alias = lc($alias); | ||||
221 | |||||
222 | if ($alias eq 'reset') { | ||||
223 | $$self{'data'}{'MyAlias'} = {}; | ||||
224 | $$self{'data'}{'zonerx'} = undef; | ||||
225 | return 0; | ||||
226 | } | ||||
227 | if (lc($zone) eq 'reset') { | ||||
228 | delete $$self{'data'}{'MyAlias'}{$alias}; | ||||
229 | $$self{'data'}{'zonerx'} = undef; | ||||
230 | return 0; | ||||
231 | } | ||||
232 | |||||
233 | $zone = $self->_zone($zone); | ||||
234 | |||||
235 | return 1 if (! $zone); | ||||
236 | $$self{'data'}{'MyAlias'}{$alias} = $zone; | ||||
237 | $$self{'data'}{'zonerx'} = undef; | ||||
238 | return 0; | ||||
239 | } | ||||
240 | |||||
241 | sub define_abbrev { | ||||
242 | my($self,$abbrev,@zone) = @_; | ||||
243 | $abbrev = lc($abbrev); | ||||
244 | |||||
245 | if ($abbrev eq 'reset') { | ||||
246 | $$self{'data'}{'MyAbbrev'} = {}; | ||||
247 | $$self{'data'}{'abbrx'} = undef; | ||||
248 | return 0; | ||||
249 | } | ||||
250 | if ($#zone == 0 && lc($zone[0]) eq 'reset') { | ||||
251 | delete $$self{'data'}{'MyAbbrev'}{$abbrev}; | ||||
252 | $$self{'data'}{'abbrx'} = undef; | ||||
253 | return (0); | ||||
254 | } | ||||
255 | |||||
256 | if (! exists $$self{'data'}{'Abbrev'}{$abbrev}) { | ||||
257 | return (1); | ||||
258 | } | ||||
259 | |||||
260 | my (@z,%z); | ||||
261 | my %zone = map { $_,1 } @{ $$self{'data'}{'Abbrev'}{$abbrev} }; | ||||
262 | foreach my $z (@zone) { | ||||
263 | my $zone = $self->_zone($z); | ||||
264 | return (2,$z) if (! $zone); | ||||
265 | return (3,$z) if (! exists $zone{$zone}); | ||||
266 | next if (exists $z{$zone}); | ||||
267 | $z{$zone} = 1; | ||||
268 | push(@z,$zone); | ||||
269 | } | ||||
270 | |||||
271 | $$self{'data'}{'MyAbbrev'}{$abbrev} = [ @z ]; | ||||
272 | $$self{'data'}{'abbrx'} = undef; | ||||
273 | return (); | ||||
274 | } | ||||
275 | |||||
276 | sub define_offset { | ||||
277 | my($self,$offset,@args) = @_; | ||||
278 | my $dmb = $$self{'base'}; | ||||
279 | |||||
280 | if (lc($offset) eq 'reset') { | ||||
281 | $$self{'data'}{'MyOffsets'} = {}; | ||||
282 | return (0); | ||||
283 | } | ||||
284 | if ($#args == 0 && lc($args[0]) eq 'reset') { | ||||
285 | delete $$self{'data'}{'MyOffsets'}{$offset}; | ||||
286 | return (0); | ||||
287 | } | ||||
288 | |||||
289 | # Check that $offset is valid. If it is, load the | ||||
290 | # appropriate module. | ||||
291 | |||||
292 | if (ref($offset)) { | ||||
293 | $offset = $dmb->join('offset',$offset); | ||||
294 | } else { | ||||
295 | $offset = $dmb->_delta_convert('offset',$offset); | ||||
296 | } | ||||
297 | return (9) if (! $offset); | ||||
298 | return (1) if (! exists $$self{'data'}{'Offmod'}{$offset}); | ||||
299 | |||||
300 | $self->_offmod($offset); | ||||
301 | |||||
302 | # Find out whether we're handling STD, DST, or both. | ||||
303 | |||||
304 | my(@isdst) = (0,1); | ||||
305 | if ($args[0] =~ /^std|dst|stdonly|dstonly$/i) { | ||||
306 | my $tmp = lc(shift(@args)); | ||||
307 | if ($tmp eq 'stdonly') { | ||||
308 | @isdst = (0); | ||||
309 | } elsif ($tmp eq 'dstonly') { | ||||
310 | @isdst = (1); | ||||
311 | } | ||||
312 | } | ||||
313 | my @zone = @args; | ||||
314 | |||||
315 | if ($#isdst == 0 && | ||||
316 | ! exists($$self{'data'}{'Offsets'}{$offset}{$isdst[0]})) { | ||||
317 | return (2); | ||||
318 | } | ||||
319 | |||||
320 | # Check to see that each zone is valid, and contains this offset. | ||||
321 | |||||
322 | my %tmp; | ||||
323 | foreach my $isdst (0,1) { | ||||
324 | next if (! exists $$self{'data'}{'Offsets'}{$offset}{$isdst}); | ||||
325 | my @z = @{ $$self{'data'}{'Offsets'}{$offset}{$isdst} }; | ||||
326 | $tmp{$isdst} = { map { $_,1 } @z }; | ||||
327 | } | ||||
328 | |||||
329 | foreach my $z (@zone) { | ||||
330 | my $lcz = lc($z); | ||||
331 | if (! exists $$self{'data'}{'ZoneNames'}{$lcz}) { | ||||
332 | return (3,$z); | ||||
333 | } elsif (! exists $tmp{0}{$lcz} && | ||||
334 | ! exists $tmp{1}{$lcz}) { | ||||
335 | return (4,$z); | ||||
336 | } elsif ($#isdst == 0 && | ||||
337 | ! exists $tmp{$isdst[0]}{$lcz}) { | ||||
338 | return (5,$z); | ||||
339 | } | ||||
340 | $z = $lcz; | ||||
341 | } | ||||
342 | |||||
343 | # Set the zones accordingly. | ||||
344 | |||||
345 | foreach my $isdst (@isdst) { | ||||
346 | my @z; | ||||
347 | foreach my $z (@zone) { | ||||
348 | push(@z,$z) if (exists $tmp{$isdst}{$z}); | ||||
349 | } | ||||
350 | $$self{'data'}{'MyOffsets'}{$offset}{$isdst} = [ @z ]; | ||||
351 | } | ||||
352 | |||||
353 | return (0); | ||||
354 | } | ||||
355 | |||||
356 | ######################################################################## | ||||
357 | # SYSTEM ZONE | ||||
358 | ######################################################################## | ||||
359 | |||||
360 | sub curr_zone { | ||||
361 | my($self,$reset) = @_; | ||||
362 | my $dmb = $$self{'base'}; | ||||
363 | |||||
364 | if ($reset) { | ||||
365 | $self->_set_curr_zone(); | ||||
366 | } | ||||
367 | |||||
368 | my($ret) = $self->_now('systz',1); | ||||
369 | return $$self{'data'}{'ZoneNames'}{$ret} | ||||
370 | } | ||||
371 | |||||
372 | sub curr_zone_methods { | ||||
373 | my($self,@methods) = @_; | ||||
374 | |||||
375 | if (${^TAINT}) { | ||||
376 | warn "ERROR: [curr_zone_methods] not allowed when taint checking on\n"; | ||||
377 | return; | ||||
378 | } | ||||
379 | |||||
380 | $$self{'data'}{'methods'} = [ @methods ]; | ||||
381 | } | ||||
382 | |||||
383 | # spent 412µs (16+396) within Date::Manip::TZ::_set_curr_zone which was called 2 times, avg 206µs/call:
# 2 times (16µs+396µs) by Date::Manip::TZ::_init_final at line 155, avg 206µs/call | ||||
384 | 2 | 700ns | my($self) = @_; | ||
385 | 2 | 1µs | my $dmb = $$self{'base'}; | ||
386 | 2 | 4µs | 2 | 392µs | my $currzone = $self->_get_curr_zone(); # spent 392µs making 2 calls to Date::Manip::TZ::_get_curr_zone, avg 196µs/call |
387 | |||||
388 | 2 | 7µs | 2 | 4µs | $$dmb{'data'}{'now'}{'systz'} = $self->_zone($currzone); # spent 4µs making 2 calls to Date::Manip::TZ::_zone, avg 2µs/call |
389 | } | ||||
390 | |||||
391 | # This determines the system timezone using all of the methods | ||||
392 | # applicable to the operating system. The first match is used. | ||||
393 | # | ||||
394 | # spent 392µs (216+176) within Date::Manip::TZ::_get_curr_zone which was called 2 times, avg 196µs/call:
# 2 times (216µs+176µs) by Date::Manip::TZ::_set_curr_zone at line 386, avg 196µs/call | ||||
395 | 2 | 500ns | my($self) = @_; | ||
396 | 2 | 900ns | my $dmb = $$self{'base'}; | ||
397 | |||||
398 | 2 | 1µs | my $t = time; | ||
399 | 2 | 31µs | my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t); | ||
400 | 2 | 600ns | my $currzone = ''; | ||
401 | 2 | 700ns | my $dstflag = ($isdst ? 'dstonly' : 'stdonly'); | ||
402 | |||||
403 | 2 | 6µs | my (@methods) = @{ $$self{'data'}{'methods'} }; | ||
404 | 2 | 2µs | my $debug = ($ENV{DATE_MANIP_DEBUG} ? 1 : 0); | ||
405 | |||||
406 | 2 | 8µs | defined $$self{'data'}{'path'} | ||
407 | and local $ENV{PATH} = $$self{'data'}{'path'}; | ||||
408 | |||||
409 | METHOD: | ||||
410 | 2 | 1µs | while (@methods) { | ||
411 | 8 | 2µs | my $method = shift(@methods); | ||
412 | 8 | 2µs | my @zone = (); | ||
413 | |||||
414 | 8 | 4µs | if ($method eq 'main') { | ||
415 | |||||
416 | 2 | 400ns | if (! @methods) { | ||
417 | warn "ERROR: [_set_curr_zone] main requires argument\n"; | ||||
418 | return; | ||||
419 | } | ||||
420 | 2 | 700ns | my $var = shift(@methods); | ||
421 | 2 | 800ns | push(@zone,$$::var) if (defined $$::var); | ||
422 | |||||
423 | 2 | 600ns | if ($debug) { | ||
424 | print "*** DEBUG *** main $var = " . | ||||
425 | (defined $$::var ? $$::var : 'undef') . "\n"; | ||||
426 | } | ||||
427 | |||||
428 | } elsif ($method eq 'env') { | ||||
429 | 2 | 900ns | if (@methods < 2) { | ||
430 | warn "ERROR: [_set_curr_zone] env requires 2 argument\n"; | ||||
431 | return; | ||||
432 | } | ||||
433 | 2 | 2µs | my $type = lc( shift(@methods) ); | ||
434 | 2 | 800ns | if ($type ne 'zone' && | ||
435 | $type ne 'offset') { | ||||
436 | warn "ERROR: [_set_curr_zone] env requires 'offset' or 'zone' as the first argument\n"; | ||||
437 | return; | ||||
438 | } | ||||
439 | 2 | 1µs | my $var = shift(@methods); | ||
440 | 2 | 1µs | if (exists $ENV{$var}) { | ||
441 | if ($type eq 'zone') { | ||||
442 | push(@zone,$ENV{$var}); | ||||
443 | } else { | ||||
444 | my $off = $ENV{$var}; | ||||
445 | $off = $dmb->_delta_convert('time',"0:0:$off"); | ||||
446 | $off = $dmb->_delta_convert('offset',$off); | ||||
447 | push(@zone,$off); | ||||
448 | } | ||||
449 | } | ||||
450 | |||||
451 | 2 | 800ns | if ($debug) { | ||
452 | print "*** DEBUG *** env $type $var "; | ||||
453 | if (exists $ENV{$var}) { | ||||
454 | print $ENV{$var}; | ||||
455 | print $zone[$#zone] if ($type eq 'offset'); | ||||
456 | print "\n"; | ||||
457 | } else { | ||||
458 | print "-no result-\n"; | ||||
459 | } | ||||
460 | } | ||||
461 | |||||
462 | } elsif ($method eq 'file') { | ||||
463 | 4 | 700ns | if (! @methods) { | ||
464 | warn "ERROR: [_set_curr_zone] file requires argument\n"; | ||||
465 | return; | ||||
466 | } | ||||
467 | 4 | 800ns | my $file = shift(@methods); | ||
468 | 4 | 19µs | 4 | 8µs | next if (! -f $file); # spent 8µs making 4 calls to Date::Manip::TZ::CORE:ftfile, avg 2µs/call |
469 | |||||
470 | 2 | 9µs | 2 | 50µs | my $in = new IO::File; # spent 50µs making 2 calls to IO::File::new, avg 25µs/call |
471 | 2 | 4µs | 2 | 51µs | $in->open($file) || next; # spent 51µs making 2 calls to IO::File::open, avg 26µs/call |
472 | 2 | 800ns | my $firstline = 1; | ||
473 | |||||
474 | 2 | 300ns | my @z; | ||
475 | 2 | 21µs | 2 | 27µs | while (! $in->eof) { # spent 27µs making 2 calls to IO::Handle::eof, avg 14µs/call |
476 | 2 | 8µs | 2 | 2µs | my $line = <$in>; # spent 2µs making 2 calls to Date::Manip::TZ::CORE:readline, avg 1µs/call |
477 | 2 | 14µs | 4 | 5µs | next if ($line =~ /^\s*\043/ || # spent 5µs making 4 calls to Date::Manip::TZ::CORE:match, avg 1µs/call |
478 | $line =~ /^\s*$/); | ||||
479 | |||||
480 | # We're looking for lines of the form: | ||||
481 | # TZ = string | ||||
482 | # TIMEZONE = string | ||||
483 | # ZONE = string | ||||
484 | # | ||||
485 | # 'string' can be: | ||||
486 | # the name of a timezone enclosed in single/double quotes | ||||
487 | # with everything after the closing quote ignored (the | ||||
488 | # name of the timezone may have spaces instead of underscores) | ||||
489 | # | ||||
490 | # a space delimited list of tokens, the first of which | ||||
491 | # is the time zone | ||||
492 | # | ||||
493 | # the name of a timezone with underscores replaced by | ||||
494 | # spaces and nothing after the timezone | ||||
495 | # | ||||
496 | # For some reason, RHEL6 desktop version stores timezones as | ||||
497 | # America/New York | ||||
498 | # instead of | ||||
499 | # America/New_York | ||||
500 | # which is why we have to handle the space/underscore | ||||
501 | # substitution. | ||||
502 | |||||
503 | 2 | 4µs | 2 | 800ns | if ($line =~ /^\s*(?:TZ|TIMEZONE|ZONE)\s*=\s*(.*)\s*$/) { # spent 800ns making 2 calls to Date::Manip::TZ::CORE:match, avg 400ns/call |
504 | my $val = $1; | ||||
505 | @z = (); | ||||
506 | last if (! $val); | ||||
507 | |||||
508 | if ($val =~ /^(["'])(.*?)\1/) { | ||||
509 | my $z = $2; | ||||
510 | last if (! $z); | ||||
511 | $z =~ s/\s+/_/g; | ||||
512 | push(@zone,$z); | ||||
513 | |||||
514 | } elsif ($val =~ /\s/) { | ||||
515 | $val =~ /^(\S+)/; | ||||
516 | push(@zone,$1); | ||||
517 | $val =~ s/\s+/_/g; | ||||
518 | push(@zone,$val); | ||||
519 | |||||
520 | } else { | ||||
521 | push(@zone,$val); | ||||
522 | } | ||||
523 | |||||
524 | last; | ||||
525 | } | ||||
526 | 2 | 4µs | 2 | 9µs | if ($firstline) { # spent 9µs making 2 calls to IO::Handle::eof, avg 4µs/call |
527 | 2 | 700ns | $firstline = 0; | ||
528 | 2 | 8µs | 2 | 4µs | $line =~ s/^\s*//; # spent 4µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 2µs/call |
529 | 2 | 8µs | 2 | 5µs | $line =~ s/\s*$//; # spent 5µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 2µs/call |
530 | 2 | 4µs | 2 | 1µs | $line =~ s/["']//g; # " # spent 1µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 600ns/call |
531 | 2 | 3µs | 2 | 800ns | $line =~ s/\s+/_/g; # spent 800ns making 2 calls to Date::Manip::TZ::CORE:subst, avg 400ns/call |
532 | 2 | 2µs | push(@z,$line); | ||
533 | } | ||||
534 | } | ||||
535 | 2 | 8µs | 2 | 1µs | close(IN); # spent 1µs making 2 calls to Date::Manip::TZ::CORE:close, avg 650ns/call |
536 | |||||
537 | 2 | 1µs | push(@zone,@z) if (@z); | ||
538 | |||||
539 | 2 | 10µs | if ($debug) { | ||
540 | print "*** DEBUG *** file $file\n"; | ||||
541 | if (@z) { | ||||
542 | print " @z\n"; | ||||
543 | } else { | ||||
544 | print " -no result-\n"; | ||||
545 | } | ||||
546 | } | ||||
547 | |||||
548 | } elsif ($method eq 'command') { | ||||
549 | if (! @methods) { | ||||
550 | warn "ERROR: [_set_curr_zone] command requires argument\n"; | ||||
551 | return; | ||||
552 | } | ||||
553 | my $command = shift(@methods); | ||||
554 | my ($out) = _cmd($command); | ||||
555 | push(@zone,$out) if ($out); | ||||
556 | |||||
557 | if ($debug) { | ||||
558 | print "*** DEBUG *** command $command\n"; | ||||
559 | if ($out) { | ||||
560 | print " $out\n"; | ||||
561 | } else { | ||||
562 | print " -no result-\n"; | ||||
563 | } | ||||
564 | } | ||||
565 | |||||
566 | } elsif ($method eq 'cmdfield') { | ||||
567 | if ($#methods < 1) { | ||||
568 | warn "ERROR: [_set_curr_zone] cmdfield requires 2 arguments\n"; | ||||
569 | return; | ||||
570 | } | ||||
571 | my $command = shift(@methods); | ||||
572 | my $n = shift(@methods); | ||||
573 | my ($out) = _cmd($command); | ||||
574 | my @z; | ||||
575 | |||||
576 | if ($out) { | ||||
577 | $out =~ s/^\s*//; | ||||
578 | $out =~ s/\s*$//; | ||||
579 | my @out = split(/\s+/,$out); | ||||
580 | push(@z,$out[$n]) if (defined $out[$n]); | ||||
581 | } | ||||
582 | |||||
583 | push(@zone,@z) if (@z); | ||||
584 | |||||
585 | if ($debug) { | ||||
586 | print "*** DEBUG *** cmdfield $command $n\n"; | ||||
587 | if (@z) { | ||||
588 | print " @z\n"; | ||||
589 | } else { | ||||
590 | print " -no result-\n"; | ||||
591 | } | ||||
592 | } | ||||
593 | |||||
594 | } elsif ($method eq 'gmtoff') { | ||||
595 | my($secUT,$minUT,$hourUT,$mdayUT,$monUT,$yearUT,$wdayUT,$ydayUT, | ||||
596 | $isdstUT) = gmtime($t); | ||||
597 | if ($mdayUT>($mday+1)) { | ||||
598 | # UT = 28-31 LT = 1 | ||||
599 | $mdayUT=0; | ||||
600 | } elsif ($mdayUT<($mday-1)) { | ||||
601 | # UT = 1 LT = 28-31 | ||||
602 | $mday=0; | ||||
603 | } | ||||
604 | $sec = (($mday*24 + $hour)*60 + $min)*60 + $sec; | ||||
605 | $secUT = (($mdayUT*24 + $hourUT)*60 + $minUT)*60 + $secUT; | ||||
606 | my $off = $sec-$secUT; | ||||
607 | |||||
608 | $off = $dmb->_delta_convert('time',"0:0:$off"); | ||||
609 | $off = $dmb->_delta_convert('offset',$off); | ||||
610 | push(@zone,$off); | ||||
611 | |||||
612 | if ($debug) { | ||||
613 | print "*** DEBUG *** gmtoff $off\n"; | ||||
614 | } | ||||
615 | |||||
616 | } elsif ($method eq 'registry') { | ||||
617 | my $z = $self->_windows_registry_val(); | ||||
618 | push(@zone,$z) if ($z); | ||||
619 | |||||
620 | if ($debug) { | ||||
621 | print "*** DEBUG *** registry $z\n"; | ||||
622 | } | ||||
623 | |||||
624 | } else { | ||||
625 | warn "ERROR: [_set_curr_zone] invalid method: $method\n"; | ||||
626 | return; | ||||
627 | } | ||||
628 | |||||
629 | 6 | 4µs | foreach my $zone (@zone) { | ||
630 | 2 | 2µs | $zone = lc($zone); | ||
631 | # OpenUNIX puts a colon at the start | ||||
632 | 2 | 5µs | 2 | 1µs | $zone =~ s/^://; # spent 1µs making 2 calls to Date::Manip::TZ::CORE:subst, avg 500ns/call |
633 | |||||
634 | # If we got a zone name/alias | ||||
635 | 2 | 4µs | 2 | 10µs | $currzone = $self->_zone($zone); # spent 10µs making 2 calls to Date::Manip::TZ::_zone, avg 5µs/call |
636 | 2 | 3µs | last METHOD if ($currzone); | ||
637 | |||||
638 | # If we got an abbreviation (EST) | ||||
639 | if (exists $$self{'data'}{'Abbrev'}{$zone}) { | ||||
640 | $currzone = $$self{'data'}{'Abbrev'}{$zone}[0]; | ||||
641 | last METHOD; | ||||
642 | } | ||||
643 | |||||
644 | # If we got an offset | ||||
645 | |||||
646 | $currzone = $self->zone($zone,$dstflag); | ||||
647 | last METHOD if ($currzone); | ||||
648 | } | ||||
649 | } | ||||
650 | |||||
651 | 2 | 600ns | if (! $currzone) { | ||
652 | warn "ERROR: Date::Manip unable to determine Time Zone.\n"; | ||||
653 | die; | ||||
654 | } | ||||
655 | |||||
656 | 2 | 22µs | return $currzone; | ||
657 | } | ||||
658 | |||||
659 | # This comes from the DateTime-TimeZone module | ||||
660 | # | ||||
661 | sub _windows_registry_val { | ||||
662 | my($self) = @_; | ||||
663 | |||||
664 | require Win32::TieRegistry; | ||||
665 | |||||
666 | my $lmachine = new Win32::TieRegistry 'LMachine', | ||||
667 | { Access => Win32::TieRegistry::KEY_READ(), | ||||
668 | Delimiter => '/' } | ||||
669 | or return ''; | ||||
670 | |||||
671 | my $tzinfo = $lmachine->Open('SYSTEM/CurrentControlSet/Control/TimeZoneInformation/'); | ||||
672 | |||||
673 | # | ||||
674 | # Windows Vista, Windows 2008 Server | ||||
675 | # | ||||
676 | |||||
677 | my $tzkn = $tzinfo->GetValue('TimeZoneKeyName'); | ||||
678 | if (defined($tzkn) && $tzkn) { | ||||
679 | # For some reason, Vista is tacking on a bunch of stuff at the | ||||
680 | # end of the timezone, starting with a chr(0). Strip it off. | ||||
681 | |||||
682 | my $c = chr(0); | ||||
683 | my $i = index($tzkn,$c); | ||||
684 | if ($i != -1) { | ||||
685 | $tzkn = substr($tzkn,0,$i); | ||||
686 | } | ||||
687 | my $z = $self->_zone($tzkn); | ||||
688 | return $z if ($z); | ||||
689 | } | ||||
690 | |||||
691 | # | ||||
692 | # Windows NT, Windows 2000, Windows XP, Windows 2003 Server | ||||
693 | # | ||||
694 | |||||
695 | my $stdnam = $tzinfo->GetValue('StandardName'); | ||||
696 | my $z = $self->_zone($stdnam); | ||||
697 | return $z if ($z); | ||||
698 | |||||
699 | # | ||||
700 | # For non-English versions, we have to determine which timezone it | ||||
701 | # actually is. | ||||
702 | # | ||||
703 | |||||
704 | my $atz = $lmachine->Open('SOFTWARE/Microsoft/Windows NT/CurrentVersion/Time Zones/'); | ||||
705 | if (! defined($atz) || ! $atz) { | ||||
706 | $atz = $lmachine->Open('SOFTWARE/Microsoft/Windows/CurrentVersion/Time Zones/'); | ||||
707 | } | ||||
708 | |||||
709 | return "" if (! defined($atz) || ! $atz); | ||||
710 | |||||
711 | foreach my $z ($atz->SubKeyNames()) { | ||||
712 | my $tmp = $atz->Open("$z/"); | ||||
713 | my $znam = $tmp->GetValue('Std'); | ||||
714 | return $z if ($znam eq $stdnam); | ||||
715 | } | ||||
716 | } | ||||
717 | |||||
718 | # We will be testing commands that don't exist on all architectures, | ||||
719 | # so disable warnings. | ||||
720 | # | ||||
721 | 2 | 77µs | 2 | 37µs | # spent 24µs (10+13) within Date::Manip::TZ::BEGIN@721 which was called:
# once (10µs+13µs) by Date::Manip::Date::BEGIN@27 at line 721 # spent 24µs making 1 call to Date::Manip::TZ::BEGIN@721
# spent 13µs making 1 call to warnings::unimport |
722 | sub _cmd { | ||||
723 | my($cmd) = @_; | ||||
724 | local(*IN); | ||||
725 | open(IN,"$cmd |") || return (); | ||||
726 | my @out = <IN>; | ||||
727 | close(IN); | ||||
728 | chomp(@out); | ||||
729 | return @out; | ||||
730 | } | ||||
731 | 2 | 2.82ms | 2 | 15µs | # spent 12µs (8+4) within Date::Manip::TZ::BEGIN@731 which was called:
# once (8µs+4µs) by Date::Manip::Date::BEGIN@27 at line 731 # spent 12µs making 1 call to Date::Manip::TZ::BEGIN@731
# spent 4µs making 1 call to warnings::import |
732 | |||||
733 | ######################################################################## | ||||
734 | # DETERMINING A TIMEZONE | ||||
735 | ######################################################################## | ||||
736 | |||||
737 | # spent 1.25ms (62µs+1.19) within Date::Manip::TZ::zone which was called:
# once (62µs+1.19ms) by Date::Manip::TZ::_config_var_setdate at line 1745 | ||||
738 | 1 | 800ns | my($self,@args) = @_; | ||
739 | 1 | 600ns | my $dmb = $$self{'base'}; | ||
740 | 1 | 500ns | if (! @args) { | ||
741 | my($tz) = $self->_now('tz',1); | ||||
742 | return $$self{'data'}{'ZoneNames'}{$tz} | ||||
743 | } | ||||
744 | |||||
745 | # Parse the arguments | ||||
746 | |||||
747 | 1 | 900ns | my($zone,$abbrev,$offset,$dstflag) = ('','','',''); | ||
748 | 1 | 200ns | my(@abbrev,$date,$tmp); | ||
749 | 1 | 1µs | foreach my $arg (@args) { | ||
750 | |||||
751 | 3 | 2µs | if (ref($arg) eq 'ARRAY') { | ||
752 | 1 | 800ns | if ($#$arg == 5) { | ||
753 | # [Y,M,D,H,Mn,S] | ||||
754 | 1 | 100ns | return undef if ($date); | ||
755 | 1 | 200ns | $date = $arg; | ||
756 | |||||
757 | } elsif ($#$arg == 2) { | ||||
758 | # [H,Mn,S] | ||||
759 | return undef if ($offset); | ||||
760 | $offset = $dmb->join('offset',$arg); | ||||
761 | return undef if (! $offset); | ||||
762 | |||||
763 | } else { | ||||
764 | return undef; | ||||
765 | } | ||||
766 | |||||
767 | } elsif (ref($arg)) { | ||||
768 | return undef; | ||||
769 | |||||
770 | } else { | ||||
771 | 2 | 1µs | $arg = lc($arg); | ||
772 | |||||
773 | 2 | 23µs | 3 | 8µs | if ($arg =~ /^(std|dst|stdonly|dstonly)$/) { # spent 4µs making 1 call to Date::Manip::TZ::_zone
# spent 4µs making 2 calls to Date::Manip::TZ::CORE:match, avg 2µs/call |
774 | 1 | 200ns | return undef if ($dstflag); | ||
775 | 1 | 400ns | $dstflag = $arg; | ||
776 | |||||
777 | } elsif ($tmp = $self->_zone($arg)) { | ||||
778 | 1 | 200ns | return undef if ($zone); | ||
779 | 1 | 300ns | $zone = $tmp; | ||
780 | |||||
781 | } elsif (exists $$self{'data'}{'MyAbbrev'}{$arg}) { | ||||
782 | return undef if (@abbrev); | ||||
783 | $abbrev = $arg; | ||||
784 | @abbrev = @{ $$self{'data'}{'MyAbbrev'}{$arg} }; | ||||
785 | } elsif (exists $$self{'data'}{'Abbrev'}{$arg}) { | ||||
786 | return undef if (@abbrev); | ||||
787 | $abbrev = $arg; | ||||
788 | @abbrev = @{ $$self{'data'}{'Abbrev'}{$arg} }; | ||||
789 | |||||
790 | } elsif ($tmp = $dmb->split('offset',$arg)) { | ||||
791 | return undef if ($offset); | ||||
792 | $offset = $dmb->_delta_convert('offset',$arg); | ||||
793 | |||||
794 | } elsif ($tmp = $dmb->split('date',$arg)) { | ||||
795 | return undef if ($date); | ||||
796 | $date = $tmp; | ||||
797 | |||||
798 | } else { | ||||
799 | return undef; | ||||
800 | } | ||||
801 | } | ||||
802 | } | ||||
803 | |||||
804 | # | ||||
805 | # Determine the zones that match all data. | ||||
806 | # | ||||
807 | |||||
808 | 1 | 200ns | my @zone; | ||
809 | |||||
810 | 1 | 200ns | while (1) { | ||
811 | |||||
812 | # No information | ||||
813 | |||||
814 | 1 | 200ns | if (! $zone && | ||
815 | ! $abbrev && | ||||
816 | ! $offset) { | ||||
817 | my($z) = $self->_now('tz',1); | ||||
818 | @zone = (lc($z)); | ||||
819 | } | ||||
820 | |||||
821 | # $dstflag | ||||
822 | # | ||||
823 | # $dstflag is "dst' if | ||||
824 | # zone is passed in as an offset | ||||
825 | # date is passed in | ||||
826 | |||||
827 | 1 | 300ns | $dstflag = "dst" if ($offset && $date && ! $dstflag); | ||
828 | |||||
829 | 1 | 400ns | my(@isdst); | ||
830 | 1 | 1µs | if ($dstflag eq 'stdonly') { | ||
831 | @isdst = (0); | ||||
832 | } elsif ($dstflag eq 'dstonly') { | ||||
833 | @isdst = (1); | ||||
834 | } elsif ($dstflag eq 'dst') { | ||||
835 | @isdst = (1,0); | ||||
836 | } else { | ||||
837 | 1 | 900ns | @isdst = (0,1); | ||
838 | } | ||||
839 | |||||
840 | # $zone | ||||
841 | |||||
842 | 1 | 600ns | if ($zone) { | ||
843 | @zone = ($zone); | ||||
844 | } | ||||
845 | |||||
846 | # $abbrev | ||||
847 | |||||
848 | 1 | 200ns | if ($abbrev) { | ||
849 | my @z; | ||||
850 | foreach my $isdst (@isdst) { | ||||
851 | my @tmp = $self->_check_abbrev_isdst($abbrev,$isdst,@abbrev); | ||||
852 | if (@tmp) { | ||||
853 | if (@z) { | ||||
854 | @z = _list_add(\@z,\@tmp); | ||||
855 | } else { | ||||
856 | @z = @tmp; | ||||
857 | } | ||||
858 | } | ||||
859 | } | ||||
860 | |||||
861 | if (@zone) { | ||||
862 | @zone = _list_union(\@z,\@zone); | ||||
863 | } else { | ||||
864 | @zone = @z; | ||||
865 | } | ||||
866 | last if (! @zone); | ||||
867 | } | ||||
868 | |||||
869 | # $offset | ||||
870 | |||||
871 | 1 | 300ns | if ($offset) { | ||
872 | return undef if (! exists $$self{'data'}{'Offmod'}{$offset}); | ||||
873 | $self->_offmod($offset); | ||||
874 | |||||
875 | my @z; | ||||
876 | foreach my $isdst (@isdst) { | ||||
877 | my @tmp; | ||||
878 | if (exists $$self{'data'}{'MyOffsets'}{$offset}{$isdst}) { | ||||
879 | @tmp = @{ $$self{'data'}{'MyOffsets'}{$offset}{$isdst} }; | ||||
880 | } elsif (exists $$self{'data'}{'Offsets'}{$offset}{$isdst}) { | ||||
881 | @tmp = @{ $$self{'data'}{'Offsets'}{$offset}{$isdst} }; | ||||
882 | } | ||||
883 | @tmp = $self->_check_offset_abbrev_isdst($offset,$abbrev,$isdst,@tmp) | ||||
884 | if ($abbrev); | ||||
885 | if (@tmp) { | ||||
886 | if (@z) { | ||||
887 | @z = _list_add(\@z,\@tmp); | ||||
888 | } else { | ||||
889 | @z = @tmp; | ||||
890 | } | ||||
891 | } | ||||
892 | } | ||||
893 | |||||
894 | if (@zone) { | ||||
895 | @zone = _list_union(\@zone,\@z); | ||||
896 | } else { | ||||
897 | @zone = @z; | ||||
898 | } | ||||
899 | last if (! @zone); | ||||
900 | } | ||||
901 | |||||
902 | # $date | ||||
903 | |||||
904 | 1 | 400ns | if ($date) { | ||
905 | # Get all periods for the year. | ||||
906 | # | ||||
907 | # Test all periods to make sure that $date is between the | ||||
908 | # wallclock times AND matches other criteria. All periods | ||||
909 | # must be tested since the same wallclock time can be in | ||||
910 | # multiple periods. | ||||
911 | |||||
912 | 1 | 200ns | my @tmp; | ||
913 | 1 | 400ns | my $isdst = ''; | ||
914 | 1 | 100ns | $isdst = 0 if ($dstflag eq 'stdonly'); | ||
915 | 1 | 100ns | $isdst = 1 if ($dstflag eq 'dstonly'); | ||
916 | |||||
917 | ZONE: | ||||
918 | 1 | 1µs | foreach my $z (@zone) { | ||
919 | 1 | 3µs | 1 | 1.14ms | $self->_module($z); # spent 1.14ms making 1 call to Date::Manip::TZ::_module |
920 | 1 | 600ns | my $y = $$date[0]; | ||
921 | 1 | 3µs | 1 | 42µs | my @periods = $self->_all_periods($z,$y); # spent 42µs making 1 call to Date::Manip::TZ::_all_periods |
922 | |||||
923 | 1 | 500ns | foreach my $period (@periods) { | ||
924 | 1 | 900ns | my($begUT,$begLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||
925 | 1 | 5µs | 2 | 4µs | next if ($dmb->cmp($date,$begLT) == -1 || # spent 4µs making 2 calls to Date::Manip::Base::cmp, avg 2µs/call |
926 | $dmb->cmp($date,$endLT) == 1 || | ||||
927 | ($offset ne '' && $offset ne $off) || | ||||
928 | ($isdst ne '' && $isdst ne $dst) || | ||||
929 | ($abbrev ne '' && lc($abbrev) ne lc($abb)) | ||||
930 | ); | ||||
931 | 1 | 500ns | push(@tmp,$z); | ||
932 | 1 | 2µs | next ZONE; | ||
933 | } | ||||
934 | } | ||||
935 | 1 | 400ns | @zone = @tmp; | ||
936 | 1 | 400ns | last if (! @zone); | ||
937 | } | ||||
938 | |||||
939 | 1 | 600ns | last; | ||
940 | } | ||||
941 | |||||
942 | # Return the value/list | ||||
943 | |||||
944 | 1 | 900ns | if (wantarray) { | ||
945 | my @ret; | ||||
946 | foreach my $z (@zone) { | ||||
947 | push(@ret,$$self{'data'}{'ZoneNames'}{$z}); | ||||
948 | } | ||||
949 | return @ret; | ||||
950 | } | ||||
951 | |||||
952 | 1 | 300ns | return '' if (! @zone); | ||
953 | 1 | 5µs | return $$self{'data'}{'ZoneNames'}{$zone[0]} | ||
954 | } | ||||
955 | |||||
956 | # This returns a list of all timezones which have the correct | ||||
957 | # abbrev/isdst combination. | ||||
958 | # | ||||
959 | sub _check_abbrev_isdst { | ||||
960 | my($self,$abbrev,$isdst,@zones) = @_; | ||||
961 | |||||
962 | my @ret; | ||||
963 | ZONE: | ||||
964 | foreach my $zone (@zones) { | ||||
965 | $self->_module($zone); | ||||
966 | |||||
967 | foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
968 | my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} }; | ||||
969 | foreach my $period (@periods) { | ||||
970 | my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||||
971 | next if (lc($abbrev) ne lc($abb) || | ||||
972 | $isdst != $dst); | ||||
973 | push(@ret,$zone); | ||||
974 | next ZONE; | ||||
975 | } | ||||
976 | } | ||||
977 | } | ||||
978 | |||||
979 | return @ret; | ||||
980 | } | ||||
981 | |||||
982 | # This returns a list of all timezones which have the correct | ||||
983 | # abbrev/isdst combination. | ||||
984 | # | ||||
985 | sub _check_offset_abbrev_isdst { | ||||
986 | my($self,$offset,$abbrev,$isdst,@zones) = @_; | ||||
987 | |||||
988 | my @ret; | ||||
989 | ZONE: foreach my $zone (@zones) { | ||||
990 | $self->_module($zone); | ||||
991 | |||||
992 | foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
993 | my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} }; | ||||
994 | foreach my $period (@periods) { | ||||
995 | my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||||
996 | next if (lc($abbrev) ne lc($abb) || | ||||
997 | $offset ne $off || | ||||
998 | $isdst != $dst); | ||||
999 | push(@ret,$zone); | ||||
1000 | next ZONE; | ||||
1001 | } | ||||
1002 | } | ||||
1003 | } | ||||
1004 | |||||
1005 | return @ret; | ||||
1006 | } | ||||
1007 | |||||
1008 | # This finds the elements common to two lists, and preserves the order | ||||
1009 | # from the first list. | ||||
1010 | # | ||||
1011 | sub _list_union { | ||||
1012 | my($list1,$list2) = @_; | ||||
1013 | my(%list2) = map { $_,1 } @$list2; | ||||
1014 | my(@ret); | ||||
1015 | foreach my $ele (@$list1) { | ||||
1016 | push(@ret,$ele) if (exists $list2{$ele}); | ||||
1017 | } | ||||
1018 | return @ret; | ||||
1019 | } | ||||
1020 | |||||
1021 | # This adds elements from the second list to the first list, provided | ||||
1022 | # they are not already there. | ||||
1023 | # | ||||
1024 | sub _list_add { | ||||
1025 | my($list1,$list2) = @_; | ||||
1026 | my(%list1) = map { $_,1 } @$list1; | ||||
1027 | my(@ret) = @$list1; | ||||
1028 | foreach my $ele (@$list2) { | ||||
1029 | next if (exists $list1{$ele}); | ||||
1030 | push(@ret,$ele); | ||||
1031 | $list1{$ele} = 1; | ||||
1032 | } | ||||
1033 | return @ret; | ||||
1034 | } | ||||
1035 | |||||
1036 | ######################################################################## | ||||
1037 | # PERIODS METHODS | ||||
1038 | ######################################################################## | ||||
1039 | |||||
1040 | sub all_periods { | ||||
1041 | my($self,$zone,$year) = @_; | ||||
1042 | |||||
1043 | my $z = $self->_zone($zone); | ||||
1044 | if (! $z) { | ||||
1045 | warn "ERROR: [periods] Invalid zone: $zone\n"; | ||||
1046 | return; | ||||
1047 | } | ||||
1048 | $zone = $z; | ||||
1049 | $self->_module($zone); | ||||
1050 | |||||
1051 | return $self->_all_periods($zone,$year); | ||||
1052 | } | ||||
1053 | |||||
1054 | sub _all_periods { | ||||
1055 | 3 | 1µs | my($self,$zone,$year) = @_; | ||
1056 | 3 | 800ns | $year += 0; | ||
1057 | |||||
1058 | 3 | 3µs | if (! exists $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year}) { | ||
1059 | |||||
1060 | # | ||||
1061 | # $ym1 is the year prior to $year which contains a rule (which will | ||||
1062 | # end in $year or later). $y is $year IF the zone contains rules | ||||
1063 | # for this year. | ||||
1064 | # | ||||
1065 | |||||
1066 | 1 | 200ns | my($ym1,$ym0); | ||
1067 | 1 | 2µs | if ($year > $$self{'data'}{'LastYear'} && | ||
1068 | exists $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}) { | ||||
1069 | $ym1 = $year-1; | ||||
1070 | $ym0 = $year; | ||||
1071 | |||||
1072 | } else { | ||||
1073 | 1 | 8µs | 1 | 1µs | foreach my $y (sort { $a <=> $b } # spent 1µs making 1 call to Date::Manip::TZ::CORE:sort |
1074 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
1075 | 1 | 500ns | if ($y < $year) { | ||
1076 | 1 | 400ns | $ym1 = $y; | ||
1077 | 1 | 400ns | next; | ||
1078 | } | ||||
1079 | $ym0 = $year if ($year == $y); | ||||
1080 | last; | ||||
1081 | } | ||||
1082 | } | ||||
1083 | 1 | 300ns | $ym1 = 0 if (! $ym1); | ||
1084 | |||||
1085 | # | ||||
1086 | # Get the periods from the prior year. The last one is used (any others | ||||
1087 | # are discarded). | ||||
1088 | # | ||||
1089 | |||||
1090 | 1 | 100ns | my(@periods); | ||
1091 | |||||
1092 | # $ym1 will be 0 in 0001 | ||||
1093 | 1 | 500ns | if ($ym1) { | ||
1094 | 1 | 3µs | 1 | 10µs | my @tmp = $self->_periods($zone,$ym1); # spent 10µs making 1 call to Date::Manip::TZ::_periods |
1095 | 1 | 800ns | push(@periods,pop(@tmp)) if (@tmp); | ||
1096 | } | ||||
1097 | |||||
1098 | # | ||||
1099 | # Add on any periods from the current year. | ||||
1100 | # | ||||
1101 | |||||
1102 | 1 | 200ns | if ($ym0) { | ||
1103 | push(@periods,$self->_periods($zone,$year)); | ||||
1104 | } | ||||
1105 | |||||
1106 | 1 | 2µs | $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} = [ @periods ]; | ||
1107 | } | ||||
1108 | |||||
1109 | # A faster 'dclone' so we don't return the actual data | ||||
1110 | 3 | 500ns | my @ret; | ||
1111 | 3 | 3µs | foreach my $ele (@{ $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} }) { | ||
1112 | push(@ret, | ||||
1113 | [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4],$$ele[5], | ||||
1114 | 3 | 12µs | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
1115 | } | ||||
1116 | 3 | 6µs | return @ret; | ||
1117 | } | ||||
1118 | |||||
1119 | sub periods { | ||||
1120 | my($self,$zone,$year,$year1) = @_; | ||||
1121 | |||||
1122 | my $z = $self->_zone($zone); | ||||
1123 | if (! $z) { | ||||
1124 | warn "ERROR: [periods] Invalid zone: $zone\n"; | ||||
1125 | return; | ||||
1126 | } | ||||
1127 | $zone = $z; | ||||
1128 | $self->_module($zone); | ||||
1129 | |||||
1130 | if (! defined($year1)) { | ||||
1131 | return $self->_periods($zone,$year); | ||||
1132 | } | ||||
1133 | |||||
1134 | $year = 1 if (! defined($year)); | ||||
1135 | |||||
1136 | my @ret; | ||||
1137 | my $lastyear = $$self{'data'}{'LastYear'}; | ||||
1138 | |||||
1139 | if ($year <= $lastyear) { | ||||
1140 | foreach my $y (sort { $a <=> $b } | ||||
1141 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
1142 | last if ($y > $year1 || $y > $lastyear); | ||||
1143 | next if ($y < $year); | ||||
1144 | push(@ret,$self->_periods($zone,$y)); | ||||
1145 | } | ||||
1146 | } | ||||
1147 | |||||
1148 | if ($year1 > $lastyear) { | ||||
1149 | $year = $lastyear + 1 if ($year <= $lastyear); | ||||
1150 | foreach my $y ($year..$year1) { | ||||
1151 | push(@ret,$self->_periods($zone,$y)); | ||||
1152 | } | ||||
1153 | } | ||||
1154 | |||||
1155 | return @ret; | ||||
1156 | } | ||||
1157 | |||||
1158 | # spent 10µs within Date::Manip::TZ::_periods which was called:
# once (10µs+0s) by Date::Manip::TZ::_all_periods at line 1094 | ||||
1159 | 1 | 700ns | my($self,$zone,$year) = @_; | ||
1160 | 1 | 400ns | $year += 0; | ||
1161 | |||||
1162 | 1 | 1µs | if (! exists $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year}) { | ||
1163 | |||||
1164 | my @periods = (); | ||||
1165 | if ($year > $$self{'data'}{'LastYear'}) { | ||||
1166 | # Calculate periods using the LastRule method | ||||
1167 | @periods = $self->_lastrule($zone,$year); | ||||
1168 | } | ||||
1169 | |||||
1170 | $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} = [ @periods ]; | ||||
1171 | } | ||||
1172 | |||||
1173 | # A faster 'dclone' so we don't return the actual data | ||||
1174 | 1 | 100ns | my @ret; | ||
1175 | 1 | 2µs | foreach my $ele (@{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} }) { | ||
1176 | push(@ret, | ||||
1177 | [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4],$$ele[5], | ||||
1178 | 1 | 4µs | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
1179 | } | ||||
1180 | 1 | 4µs | return @ret; | ||
1181 | } | ||||
1182 | |||||
1183 | sub date_period { | ||||
1184 | 2 | 900ns | my($self,$date,$zone,$wallclock,$isdst) = @_; | ||
1185 | 2 | 500ns | $wallclock = 0 if (! $wallclock); | ||
1186 | 2 | 600ns | $isdst = 0 if (! $isdst); | ||
1187 | |||||
1188 | 2 | 2µs | 2 | 4µs | my $z = $self->_zone($zone); # spent 4µs making 2 calls to Date::Manip::TZ::_zone, avg 2µs/call |
1189 | 2 | 400ns | if (! $z) { | ||
1190 | warn "ERROR: [date_period] Invalid zone: $zone\n"; | ||||
1191 | return; | ||||
1192 | } | ||||
1193 | 2 | 300ns | $zone = $z; | ||
1194 | 2 | 2µs | 2 | 3µs | $self->_module($zone); # spent 3µs making 2 calls to Date::Manip::TZ::_module, avg 2µs/call |
1195 | |||||
1196 | 2 | 800ns | my $dmb = $$self{'base'}; | ||
1197 | 2 | 1µs | my @date = @$date; | ||
1198 | 2 | 400ns | my $year = $date[0]; | ||
1199 | 2 | 3µs | 2 | 14µs | my $dates= $dmb->_date_fields(@$date); # spent 14µs making 2 calls to Date::Manip::Base::_date_fields, avg 7µs/call |
1200 | |||||
1201 | 2 | 600ns | if ($wallclock) { | ||
1202 | # A wallclock date | ||||
1203 | |||||
1204 | 2 | 2µs | 2 | 12µs | my @period = $self->_all_periods($zone,$year); # spent 12µs making 2 calls to Date::Manip::TZ::_all_periods, avg 6µs/call |
1205 | 2 | 800ns | my $beg = $period[0]->[9]; | ||
1206 | 2 | 500ns | my $end = $period[-1]->[11]; | ||
1207 | 2 | 1µs | if (($dates cmp $beg) == -1) { | ||
1208 | @period = $self->_all_periods($zone,$year-1); | ||||
1209 | } elsif (($dates cmp $end) == 1) { | ||||
1210 | @period = $self->_all_periods($zone,$year+1); | ||||
1211 | } | ||||
1212 | |||||
1213 | 2 | 400ns | my(@per); | ||
1214 | 2 | 1µs | foreach my $period (@period) { | ||
1215 | 2 | 2µs | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||
1216 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
1217 | 2 | 3µs | if (($dates cmp $begLTs) != -1 && ($dates cmp $endLTs) != 1) { | ||
1218 | push(@per,$period); | ||||
1219 | } | ||||
1220 | } | ||||
1221 | |||||
1222 | 2 | 8µs | if ($#per == -1) { | ||
1223 | return (); | ||||
1224 | } elsif ($#per == 0) { | ||||
1225 | return $per[0]; | ||||
1226 | } elsif ($#per == 1) { | ||||
1227 | if ($per[0][5] == $isdst) { | ||||
1228 | return $per[0]; | ||||
1229 | } else { | ||||
1230 | return $per[1]; | ||||
1231 | } | ||||
1232 | } else { | ||||
1233 | warn "ERROR: [date_period] Impossible error\n"; | ||||
1234 | return; | ||||
1235 | } | ||||
1236 | |||||
1237 | } else { | ||||
1238 | # A GMT date | ||||
1239 | |||||
1240 | my @period = $self->_all_periods($zone,$year); | ||||
1241 | foreach my $period (@period) { | ||||
1242 | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$isdst,$endUT,$endLT, | ||||
1243 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
1244 | if (($dates cmp $begUTs) != -1 && ($dates cmp $endUTs) != 1) { | ||||
1245 | return $period; | ||||
1246 | } | ||||
1247 | } | ||||
1248 | warn "ERROR: [date_period] Impossible error\n"; | ||||
1249 | return; | ||||
1250 | } | ||||
1251 | } | ||||
1252 | |||||
1253 | # Calculate critical dates from the last rule. If $endonly is passed | ||||
1254 | # in, it only calculates the ending of the zone period before the | ||||
1255 | # start of the first one. This is necessary so that the last period in | ||||
1256 | # one year can find out when it ends (which is determined in the | ||||
1257 | # following year). | ||||
1258 | # | ||||
1259 | # Returns: | ||||
1260 | # [begUT, begLT, offsetstr, offset, abb, ISDST, endUT, endLT, | ||||
1261 | # begUTstr, begLTstr, endUTstr, endLTstr] | ||||
1262 | # for each. | ||||
1263 | # | ||||
1264 | sub _lastrule { | ||||
1265 | my($self,$zone,$year,$endonly) = @_; | ||||
1266 | |||||
1267 | # | ||||
1268 | # Get the list of rules (actually, the month in which the | ||||
1269 | # rule triggers a time change). If there are none, then | ||||
1270 | # this zone doesn't have a LAST RULE. | ||||
1271 | # | ||||
1272 | |||||
1273 | my @mon = (sort keys | ||||
1274 | %{ $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'} }); | ||||
1275 | return () if (! @mon); | ||||
1276 | |||||
1277 | # | ||||
1278 | # Analyze each time change. | ||||
1279 | # | ||||
1280 | |||||
1281 | my @dates = (); | ||||
1282 | my $dmb = $$self{'base'}; | ||||
1283 | |||||
1284 | my $stdoff = $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}{'stdoff'}; | ||||
1285 | my $dstoff = $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}{'dstoff'}; | ||||
1286 | |||||
1287 | my (@period); | ||||
1288 | |||||
1289 | foreach my $mon (@mon) { | ||||
1290 | my $flag = | ||||
1291 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'flag'}; | ||||
1292 | my $dow = | ||||
1293 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'dow'}; | ||||
1294 | my $num = | ||||
1295 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'num'}; | ||||
1296 | my $isdst= | ||||
1297 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'isdst'}; | ||||
1298 | my $time = | ||||
1299 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'time'}; | ||||
1300 | my $type = | ||||
1301 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'type'}; | ||||
1302 | my $abb = | ||||
1303 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'abb'}; | ||||
1304 | |||||
1305 | # The end of the current period and the beginning of the next | ||||
1306 | my($endUT,$endLT,$begUT,$begLT) = | ||||
1307 | $dmb->_critical_date($year,$mon,$flag,$num,$dow, | ||||
1308 | $isdst,$time,$type,$stdoff,$dstoff); | ||||
1309 | return ($endUT,$endLT) if ($endonly); | ||||
1310 | |||||
1311 | if (@period) { | ||||
1312 | push(@period,$endUT,$endLT); | ||||
1313 | push(@dates,[@period]); | ||||
1314 | } | ||||
1315 | my $offsetstr = ($isdst ? $dstoff : $stdoff); | ||||
1316 | my $offset = $dmb->split('offset',$offsetstr); | ||||
1317 | |||||
1318 | @period = ($begUT,$begLT,$offsetstr,$offset,$abb,$isdst); | ||||
1319 | } | ||||
1320 | |||||
1321 | push(@period,$self->_lastrule($zone,$year+1,1)); | ||||
1322 | push(@dates,[@period]); | ||||
1323 | |||||
1324 | foreach my $period (@dates) { | ||||
1325 | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT) = @$period; | ||||
1326 | my $begUTstr = $dmb->join("date",$begUT); | ||||
1327 | my $begLTstr = $dmb->join("date",$begLT); | ||||
1328 | my $endUTstr = $dmb->join("date",$endUT); | ||||
1329 | my $endLTstr = $dmb->join("date",$endLT); | ||||
1330 | $period = [$begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||||
1331 | $begUTstr,$begLTstr,$endUTstr,$endLTstr]; | ||||
1332 | } | ||||
1333 | |||||
1334 | return @dates; | ||||
1335 | } | ||||
1336 | |||||
1337 | ######################################################################## | ||||
1338 | # CONVERSION | ||||
1339 | ######################################################################## | ||||
1340 | |||||
1341 | sub convert { | ||||
1342 | my($self,$date,$from,$to,$isdst) = @_; | ||||
1343 | $self->_convert('convert',$date,$from,$to,$isdst); | ||||
1344 | } | ||||
1345 | |||||
1346 | # spent 61µs (10+51) within Date::Manip::TZ::convert_to_gmt which was called:
# once (10µs+51µs) by Date::Manip::TZ::_config_var_setdate at line 1821 | ||||
1347 | 1 | 700ns | my($self,$date,@arg) = @_; | ||
1348 | 1 | 3µs | 1 | 4µs | my($err,$from,$isdst) = _convert_args('convert_to_gmt',@arg); # spent 4µs making 1 call to Date::Manip::TZ::_convert_args |
1349 | 1 | 300ns | return (1) if ($err); | ||
1350 | |||||
1351 | 1 | 500ns | my $dmb = $$self{'base'}; | ||
1352 | |||||
1353 | 1 | 200ns | if (! $from) { | ||
1354 | $from = $self->_now('tz',1); | ||||
1355 | } | ||||
1356 | 1 | 5µs | 1 | 47µs | $self->_convert('convert_to_gmt',$date,$from,'GMT',$isdst); # spent 47µs making 1 call to Date::Manip::TZ::_convert |
1357 | } | ||||
1358 | |||||
1359 | sub convert_from_gmt { | ||||
1360 | my($self,$date,@arg) = @_; | ||||
1361 | my($err,$to,$isdst) = _convert_args('convert_from_gmt',@arg); | ||||
1362 | return (1) if ($err); | ||||
1363 | |||||
1364 | my $dmb = $$self{'base'}; | ||||
1365 | |||||
1366 | if (! $to) { | ||||
1367 | $to = $self->_now('tz',1); | ||||
1368 | } | ||||
1369 | $self->_convert('convert_from_gmt',$date,'GMT',$to,$isdst); | ||||
1370 | } | ||||
1371 | |||||
1372 | sub convert_to_local { | ||||
1373 | my($self,$date,@arg) = @_; | ||||
1374 | my($err,$from,$isdst) = _convert_args('convert_to_local',@arg); | ||||
1375 | return (1) if ($err); | ||||
1376 | |||||
1377 | my $dmb = $$self{'base'}; | ||||
1378 | |||||
1379 | if (! $from) { | ||||
1380 | $from = 'GMT'; | ||||
1381 | } | ||||
1382 | $self->_convert('convert_to_local',$date,$from,$self->_now('tz',1),$isdst); | ||||
1383 | } | ||||
1384 | |||||
1385 | sub convert_from_local { | ||||
1386 | my($self,$date,@arg) = @_; | ||||
1387 | my($err,$to,$isdst) = _convert_args('convert_from_local',@arg); | ||||
1388 | return (1) if ($err); | ||||
1389 | |||||
1390 | my $dmb = $$self{'base'}; | ||||
1391 | |||||
1392 | if (! $to) { | ||||
1393 | $to = 'GMT'; | ||||
1394 | } | ||||
1395 | $self->_convert('convert_from_local',$date,$self->_now('tz',1),$to,$isdst); | ||||
1396 | } | ||||
1397 | |||||
1398 | # spent 4µs within Date::Manip::TZ::_convert_args which was called:
# once (4µs+0s) by Date::Manip::TZ::convert_to_gmt at line 1348 | ||||
1399 | 1 | 600ns | my($caller,@args) = @_; | ||
1400 | |||||
1401 | 1 | 1µs | if ($#args == -1) { | ||
1402 | return (0,'',0); | ||||
1403 | } elsif ($#args == 0) { | ||||
1404 | if ($args[0] eq '0' || | ||||
1405 | $args[0] eq '1') { | ||||
1406 | return (0,'',$args[0]); | ||||
1407 | } else { | ||||
1408 | 1 | 3µs | return (0,$args[0],0); | ||
1409 | } | ||||
1410 | } elsif ($#args == 1) { | ||||
1411 | return (0,@args); | ||||
1412 | } else { | ||||
1413 | return (1,'',0); | ||||
1414 | } | ||||
1415 | } | ||||
1416 | |||||
1417 | # spent 47µs (16+30) within Date::Manip::TZ::_convert which was called:
# once (16µs+30µs) by Date::Manip::TZ::convert_to_gmt at line 1356 | ||||
1418 | 1 | 600ns | my($self,$caller,$date,$from,$to,$isdst) = @_; | ||
1419 | 1 | 500ns | my $dmb = $$self{'base'}; | ||
1420 | |||||
1421 | # Handle $date as a reference and a string | ||||
1422 | 1 | 100ns | my (@date); | ||
1423 | 1 | 2µs | if (ref($date)) { | ||
1424 | @date = @$date; | ||||
1425 | } else { | ||||
1426 | @date = @{ $dmb->split('date',$date) }; | ||||
1427 | $date = [@date]; | ||||
1428 | } | ||||
1429 | |||||
1430 | 1 | 600ns | if ($from ne $to) { | ||
1431 | 1 | 1µs | 1 | 2µs | my $tmp = $self->_zone($from); # spent 2µs making 1 call to Date::Manip::TZ::_zone |
1432 | 1 | 400ns | if (! $tmp) { | ||
1433 | return (2); | ||||
1434 | } | ||||
1435 | 1 | 200ns | $from = $tmp; | ||
1436 | |||||
1437 | 1 | 800ns | 1 | 2µs | $tmp = $self->_zone($to); # spent 2µs making 1 call to Date::Manip::TZ::_zone |
1438 | 1 | 100ns | if (! $tmp) { | ||
1439 | return (3); | ||||
1440 | } | ||||
1441 | 1 | 400ns | $to = $tmp; | ||
1442 | } | ||||
1443 | |||||
1444 | 1 | 700ns | if ($from eq $to) { | ||
1445 | 1 | 1µs | 1 | 27µs | my $per = $self->date_period($date,$from,1,$isdst); # spent 27µs making 1 call to Date::Manip::TZ::date_period |
1446 | 1 | 300ns | my $offset = $$per[3]; | ||
1447 | 1 | 400ns | my $abb = $$per[4]; | ||
1448 | 1 | 4µs | return (0,$date,$offset,$isdst,$abb); | ||
1449 | } | ||||
1450 | |||||
1451 | # Convert $date from $from to GMT | ||||
1452 | |||||
1453 | if ($from ne "Etc/GMT") { | ||||
1454 | my $per = $self->date_period($date,$from,1,$isdst); | ||||
1455 | if (! $per) { | ||||
1456 | return (4); | ||||
1457 | } | ||||
1458 | my $offset = $$per[3]; | ||||
1459 | @date = @{ $dmb->calc_date_time(\@date,$offset,1) }; | ||||
1460 | } | ||||
1461 | |||||
1462 | # Convert $date from GMT to $to | ||||
1463 | |||||
1464 | $isdst = 0; | ||||
1465 | my $offset = [0,0,0]; | ||||
1466 | my $abb = 'GMT'; | ||||
1467 | |||||
1468 | if ($to ne "Etc/GMT") { | ||||
1469 | my $per = $self->date_period([@date],$to,0); | ||||
1470 | $offset = $$per[3]; | ||||
1471 | $isdst = $$per[5]; | ||||
1472 | $abb = $$per[4]; | ||||
1473 | @date = @{ $dmb->calc_date_time(\@date,$offset) }; | ||||
1474 | } | ||||
1475 | |||||
1476 | return (0,[@date],$offset,$isdst,$abb); | ||||
1477 | } | ||||
1478 | |||||
1479 | ######################################################################## | ||||
1480 | # REGULAR EXPRESSIONS FOR TIMEZONE INFORMATION | ||||
1481 | ######################################################################## | ||||
1482 | |||||
1483 | # Returns a regular expression capable of matching all timezone names | ||||
1484 | # and aliases. | ||||
1485 | # | ||||
1486 | # The regular expression will have the following named matches: | ||||
1487 | # zone = a zone name or alias | ||||
1488 | # | ||||
1489 | sub _zonerx { | ||||
1490 | my($self) = @_; | ||||
1491 | return $$self{'data'}{'zonerx'} if (defined $$self{'data'}{'zonerx'}); | ||||
1492 | my @zone = (keys %{ $$self{'data'}{'Alias'} }, | ||||
1493 | keys %{ $$self{'data'}{'MyAlias'} }); | ||||
1494 | @zone = sort _sortByLength(@zone); | ||||
1495 | foreach my $zone (@zone) { | ||||
1496 | $zone =~ s/\057/\\057/g; # / | ||||
1497 | $zone =~ s/\055/\\055/g; # - | ||||
1498 | $zone =~ s/\056/\\056/g; # . | ||||
1499 | $zone =~ s/\050/\\050/g; # ( | ||||
1500 | $zone =~ s/\051/\\051/g; # ) | ||||
1501 | $zone =~ s/\053/\\053/g; # + | ||||
1502 | } | ||||
1503 | my $re = join('|',@zone); | ||||
1504 | $$self{'data'}{'zonerx'} = qr/(?<zone>$re)/i; | ||||
1505 | return $$self{'data'}{'zonerx'}; | ||||
1506 | } | ||||
1507 | |||||
1508 | # Returns a regular expression capable of matching all abbreviations. | ||||
1509 | # | ||||
1510 | # The regular expression will have the following named matches: | ||||
1511 | # abb = a zone abbreviation | ||||
1512 | # | ||||
1513 | sub _abbrx { | ||||
1514 | my($self) = @_; | ||||
1515 | return $$self{'data'}{'abbrx'} if (defined $$self{'data'}{'abbrx'}); | ||||
1516 | my @abb = (keys %{ $$self{'data'}{'Abbrev'} }, | ||||
1517 | keys %{ $$self{'data'}{'MyAbbrev'} }); | ||||
1518 | @abb = sort _sortByLength(@abb); | ||||
1519 | foreach my $abb (@abb) { | ||||
1520 | $abb =~ s/\055/\\055/g; # - | ||||
1521 | $abb =~ s/\053/\\053/g; # + | ||||
1522 | } | ||||
1523 | my $re = join('|',@abb); | ||||
1524 | $$self{'data'}{'abbrx'} = qr/(?<abb>$re)/i; | ||||
1525 | return $$self{'data'}{'abbrx'}; | ||||
1526 | } | ||||
1527 | |||||
1528 | # Returns a regular expression capable of matching a valid timezone as | ||||
1529 | # an offset. Known formats are: | ||||
1530 | # +07 +07 (HST) | ||||
1531 | # +0700 +0700 (HST) | ||||
1532 | # +07:00 +07:00 (HST) | ||||
1533 | # +070000 +070000 (HST) | ||||
1534 | # +07:00:00 +07:00:00 (HST) | ||||
1535 | # | ||||
1536 | # The regular expression will have the following named matches: | ||||
1537 | # off = the offset | ||||
1538 | # abb = the abbreviation | ||||
1539 | # | ||||
1540 | # If $simple is passed in, it will return the simple form (i.e. no | ||||
1541 | # appended abbreviation). | ||||
1542 | # | ||||
1543 | sub _offrx { | ||||
1544 | my($self,$simple) = @_; | ||||
1545 | if ($simple) { | ||||
1546 | return $$self{'data'}{'offsimprx'} if (defined $$self{'data'}{'offsimprx'}); | ||||
1547 | } else { | ||||
1548 | return $$self{'data'}{'offrx'} if (defined $$self{'data'}{'offrx'}); | ||||
1549 | } | ||||
1550 | |||||
1551 | my($hr) = qr/(?:[0-1][0-9]|2[0-3])/; # 00 - 23 | ||||
1552 | my($mn) = qr/(?:[0-5][0-9])/; # 00 - 59 | ||||
1553 | my($ss) = qr/(?:[0-5][0-9])/; # 00 - 59 | ||||
1554 | my($abb)= $self->_abbrx(); | ||||
1555 | |||||
1556 | my($re) = qr/ (?<off> [+-] (?: $hr:$mn:$ss | | ||||
1557 | $hr$mn$ss | | ||||
1558 | $hr:?$mn | | ||||
1559 | $hr | ||||
1560 | ) | ||||
1561 | ) | ||||
1562 | (?: \s* (?: \( $abb \) | $abb))? /ix; | ||||
1563 | my($re2) = qr/ (?<off> [+-] (?: $hr:$mn:$ss | | ||||
1564 | $hr$mn$ss | | ||||
1565 | $hr:?$mn | | ||||
1566 | $hr | ||||
1567 | ) | ||||
1568 | ) /ix; | ||||
1569 | my $simprx = qr/(?<tzstring>$re2)/; | ||||
1570 | |||||
1571 | $$self{'data'}{'offsimprx'} = $simprx; | ||||
1572 | $$self{'data'}{'offrx'} = $re; | ||||
1573 | |||||
1574 | return $$self{'data'}{'offsimprx'} if ($simple); | ||||
1575 | return $$self{'data'}{'offrx'}; | ||||
1576 | } | ||||
1577 | |||||
1578 | # Returns a regular expression capable of matching all timezone | ||||
1579 | # information available. It will match a full timezone, an | ||||
1580 | # abbreviation, or an offset/abbreviation combination. The regular | ||||
1581 | # expression will have the following named matches: | ||||
1582 | # tzstring = the full string matched | ||||
1583 | # in addition to the matches from the _zonerx, _abbrx, and _offrx | ||||
1584 | # functions. | ||||
1585 | # | ||||
1586 | sub _zrx { | ||||
1587 | my($self,$simple) = @_; | ||||
1588 | return $$self{'data'}{'zrx'} if (defined $$self{'data'}{'zrx'}); | ||||
1589 | |||||
1590 | my $zonerx = $self->_zonerx(); # (?<zone>america/new_york|...) | ||||
1591 | my $zoneabbrx = $self->_abbrx(); # (?<abb>edt|est|...) | ||||
1592 | my $zoneoffrx = $self->_offrx(); # (?<off>07:00) (?<abb>GMT) | ||||
1593 | |||||
1594 | my $zrx = qr/(?<tzstring>$zoneabbrx|$zoneoffrx|$zonerx)/; | ||||
1595 | $$self{'data'}{'zrx'} = $zrx; | ||||
1596 | return $zrx; | ||||
1597 | } | ||||
1598 | |||||
1599 | # This sorts from longest to shortest element | ||||
1600 | # | ||||
1601 | 2 | 202µs | 2 | 591µs | # spent 374µs (157+217) within Date::Manip::TZ::BEGIN@1601 which was called:
# once (157µs+217µs) by Date::Manip::Date::BEGIN@27 at line 1601 # spent 374µs making 1 call to Date::Manip::TZ::BEGIN@1601
# spent 217µs making 1 call to strict::unimport |
1602 | sub _sortByLength { | ||||
1603 | return (length $b <=> length $a); | ||||
1604 | } | ||||
1605 | 2 | 761µs | 2 | 61µs | # spent 50µs (40+10) within Date::Manip::TZ::BEGIN@1605 which was called:
# once (40µs+10µs) by Date::Manip::Date::BEGIN@27 at line 1605 # spent 50µs making 1 call to Date::Manip::TZ::BEGIN@1605
# spent 10µs making 1 call to strict::import |
1606 | |||||
1607 | ######################################################################## | ||||
1608 | # CONFIG VARS | ||||
1609 | ######################################################################## | ||||
1610 | |||||
1611 | # This sets a config variable. It also performs all side effects from | ||||
1612 | # setting that variable. | ||||
1613 | # | ||||
1614 | # spent 1.47ms (11µs+1.46) within Date::Manip::TZ::_config_var_tz which was called:
# once (11µs+1.46ms) by Date::Manip::TZ_Base::_config_var at line 32 of Date/Manip/TZ_Base.pm | ||||
1615 | 1 | 600ns | my($self,$var,$val) = @_; | ||
1616 | |||||
1617 | 1 | 1µs | if ($var eq 'tz') { | ||
1618 | my $err = $self->_config_var_setdate("now,$val",0); | ||||
1619 | return if ($err); | ||||
1620 | $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0; | ||||
1621 | $val = 1; | ||||
1622 | |||||
1623 | } elsif ($var eq 'setdate') { | ||||
1624 | 1 | 2µs | 1 | 1.46ms | my $err = $self->_config_var_setdate($val,0); # spent 1.46ms making 1 call to Date::Manip::TZ::_config_var_setdate |
1625 | 1 | 200ns | return if ($err); | ||
1626 | 1 | 2µs | $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0; | ||
1627 | 1 | 300ns | $val = 1; | ||
1628 | |||||
1629 | } elsif ($var eq 'forcedate') { | ||||
1630 | my $err = $self->_config_var_setdate($val,1); | ||||
1631 | return if ($err); | ||||
1632 | $$self{'data'}{'sections'}{'conf'}{'setdate'} = 0; | ||||
1633 | $val = 1; | ||||
1634 | |||||
1635 | } elsif ($var eq 'configfile') { | ||||
1636 | $self->_config_file($val); | ||||
1637 | return; | ||||
1638 | } | ||||
1639 | |||||
1640 | 1 | 600ns | my $base = $$self{'base'}; | ||
1641 | 1 | 900ns | $$base{'data'}{'sections'}{'conf'}{$var} = $val; | ||
1642 | 1 | 2µs | return; | ||
1643 | } | ||||
1644 | |||||
1645 | # spent 1.46ms (69µs+1.39) within Date::Manip::TZ::_config_var_setdate which was called:
# once (69µs+1.39ms) by Date::Manip::TZ::_config_var_tz at line 1624 | ||||
1646 | 1 | 400ns | my($self,$val,$force) = @_; | ||
1647 | 1 | 700ns | my $base = $$self{'base'}; | ||
1648 | |||||
1649 | 1 | 6µs | 1 | 2µs | my $dstrx = qr/(?:,\s*(stdonly|dstonly|std|dst))?/i; # spent 2µs making 1 call to Date::Manip::TZ::CORE:qr |
1650 | 1 | 2µs | 1 | 600ns | my $zonrx = qr/,\s*(.+)/; # spent 600ns making 1 call to Date::Manip::TZ::CORE:qr |
1651 | 1 | 5µs | 1 | 3µs | my $da1rx = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d):(\d\d):(\d\d)/; # spent 3µs making 1 call to Date::Manip::TZ::CORE:qr |
1652 | 1 | 2µs | 1 | 700ns | my $da2rx = qr/(\d\d\d\d)\-(\d\d)\-(\d\d)\-(\d\d):(\d\d):(\d\d)/; # spent 700ns making 1 call to Date::Manip::TZ::CORE:qr |
1653 | 1 | 900ns | my $time = time; | ||
1654 | |||||
1655 | 1 | 200ns | my($op,$date,$dstflag,$zone,@date,$offset,$abb); | ||
1656 | |||||
1657 | # | ||||
1658 | # Parse the argument | ||||
1659 | # | ||||
1660 | |||||
1661 | 1 | 34µs | 2 | 28µs | if ($val =~ /^now${dstrx}${zonrx}$/oi) { # spent 22µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 6µs making 1 call to Date::Manip::TZ::CORE:match |
1662 | # now,ZONE | ||||
1663 | # now,DSTFLAG,ZONE | ||||
1664 | # Sets now to the system date/time but sets the timezone to be ZONE | ||||
1665 | |||||
1666 | 1 | 300ns | $op = 'nowzone'; | ||
1667 | 1 | 2µs | ($dstflag,$zone) = ($1,$2); | ||
1668 | |||||
1669 | } elsif ($val =~ /^zone${dstrx}${zonrx}$/oi) { | ||||
1670 | # zone,ZONE | ||||
1671 | # zone,DSTFLAG,ZONE | ||||
1672 | # Converts 'now' to the alternate zone | ||||
1673 | |||||
1674 | $op = 'zone'; | ||||
1675 | ($dstflag,$zone) = ($1,$2); | ||||
1676 | |||||
1677 | } elsif ($val =~ /^${da1rx}${dstrx}${zonrx}$/o || | ||||
1678 | $val =~ /^${da2rx}${dstrx}${zonrx}$/o) { | ||||
1679 | # DATE,ZONE | ||||
1680 | # DATE,DSTFLAG,ZONE | ||||
1681 | # Sets the date and zone | ||||
1682 | |||||
1683 | $op = 'datezone'; | ||||
1684 | my($y,$m,$d,$h,$mn,$s); | ||||
1685 | ($y,$m,$d,$h,$mn,$s,$dstflag,$zone) = ($1,$2,$3,$4,$5,$6,$7,$8); | ||||
1686 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1687 | |||||
1688 | } elsif ($val =~ /^${da1rx}$/o || | ||||
1689 | $val =~ /^${da2rx}$/o) { | ||||
1690 | # DATE | ||||
1691 | # Sets the date in the system timezone | ||||
1692 | |||||
1693 | $op = 'date'; | ||||
1694 | my($y,$m,$d,$h,$mn,$s) = ($1,$2,$3,$4,$5,$6); | ||||
1695 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1696 | $zone = $self->_now('systz',1); | ||||
1697 | |||||
1698 | } elsif (lc($val) eq 'now') { | ||||
1699 | # now | ||||
1700 | # Resets everything | ||||
1701 | |||||
1702 | my $systz = $$base{'data'}{'now'}{'systz'}; | ||||
1703 | $base->_init_now(); | ||||
1704 | $$base{'data'}{'now'}{'systz'} = $systz; | ||||
1705 | return 0; | ||||
1706 | |||||
1707 | } else { | ||||
1708 | warn "ERROR: [config_var] invalid SetDate/ForceDate value: $val\n"; | ||||
1709 | return 1; | ||||
1710 | } | ||||
1711 | |||||
1712 | 1 | 600ns | $dstflag = 'std' if (! $dstflag); | ||
1713 | |||||
1714 | # | ||||
1715 | # Get the date we're setting 'now' to | ||||
1716 | # | ||||
1717 | |||||
1718 | 1 | 700ns | if ($op eq 'nowzone') { | ||
1719 | # Use the system localtime | ||||
1720 | |||||
1721 | 1 | 9µs | my($s,$mn,$h,$d,$m,$y) = localtime($time); | ||
1722 | 1 | 900ns | $y += 1900; | ||
1723 | 1 | 200ns | $m++; | ||
1724 | 1 | 1µs | $date = [$y,$m,$d,$h,$mn,$s]; | ||
1725 | |||||
1726 | } elsif ($op eq 'zone') { | ||||
1727 | # Use the system GMT time | ||||
1728 | |||||
1729 | my($s,$mn,$h,$d,$m,$y) = gmtime($time); | ||||
1730 | $y += 1900; | ||||
1731 | $m++; | ||||
1732 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1733 | } | ||||
1734 | |||||
1735 | # | ||||
1736 | # Find out what zone was passed in. It can be an alias or an offset. | ||||
1737 | # | ||||
1738 | |||||
1739 | 1 | 400ns | if ($zone) { | ||
1740 | 1 | 100ns | my ($err,@args); | ||
1741 | 1 | 700ns | push(@args,$date) if ($date); | ||
1742 | 1 | 700ns | push(@args,$zone); | ||
1743 | 1 | 200ns | push(@args,$dstflag); | ||
1744 | |||||
1745 | 1 | 3µs | 1 | 1.25ms | $zone = $self->zone(@args); # spent 1.25ms making 1 call to Date::Manip::TZ::zone |
1746 | 1 | 700ns | if (! $zone) { | ||
1747 | warn "ERROR: [config_var] invalid zone in SetDate: @args\n"; | ||||
1748 | return 1; | ||||
1749 | } | ||||
1750 | |||||
1751 | } else { | ||||
1752 | $zone = $$base{'data'}{'now'}{'systz'}; | ||||
1753 | } | ||||
1754 | |||||
1755 | # | ||||
1756 | # Handle the zone | ||||
1757 | # | ||||
1758 | |||||
1759 | 1 | 300ns | my($isdst,@isdst); | ||
1760 | 1 | 1µs | if ($dstflag eq 'std') { | ||
1761 | @isdst = (0,1); | ||||
1762 | } elsif ($dstflag eq 'stdonly') { | ||||
1763 | @isdst = (0); | ||||
1764 | } elsif ($dstflag eq 'dst') { | ||||
1765 | @isdst = (1,0); | ||||
1766 | } else { | ||||
1767 | @isdst = (1); | ||||
1768 | } | ||||
1769 | |||||
1770 | 1 | 700ns | if ($op eq 'nowzone' || | ||
1771 | $op eq 'datezone' || | ||||
1772 | $op eq 'date') { | ||||
1773 | |||||
1774 | # Check to make sure that the date can exist in this zone. | ||||
1775 | 1 | 200ns | my $per; | ||
1776 | 1 | 1µs | foreach my $dst (@isdst) { | ||
1777 | 2 | 600ns | next if ($per); | ||
1778 | 1 | 3µs | 1 | 43µs | $per = $self->date_period($date,$zone,1,$dst); # spent 43µs making 1 call to Date::Manip::TZ::date_period |
1779 | } | ||||
1780 | |||||
1781 | 1 | 200ns | if (! $per) { | ||
1782 | warn "ERROR: [config_var] invalid date: SetDate: $date, $zone\n"; | ||||
1783 | return 1; | ||||
1784 | } | ||||
1785 | 1 | 500ns | $isdst = $$per[5]; | ||
1786 | 1 | 300ns | $abb = $$per[4]; | ||
1787 | 1 | 900ns | $offset = $$per[3]; | ||
1788 | |||||
1789 | } elsif ($op eq 'zone') { | ||||
1790 | |||||
1791 | # Convert to that zone | ||||
1792 | my($err); | ||||
1793 | ($err,$date,$offset,$isdst,$abb) = $self->convert_from_gmt($date,$zone); | ||||
1794 | if ($err) { | ||||
1795 | warn "ERROR: [config_var] invalid SetDate date/offset values: $date, $zone\n"; | ||||
1796 | return 1; | ||||
1797 | } | ||||
1798 | } | ||||
1799 | |||||
1800 | # | ||||
1801 | # Set NOW | ||||
1802 | # | ||||
1803 | |||||
1804 | 1 | 1µs | $$base{'data'}{'now'}{'date'} = $date; | ||
1805 | 1 | 2µs | 1 | 2µs | $$base{'data'}{'now'}{'tz'} = $self->_zone($zone); # spent 2µs making 1 call to Date::Manip::TZ::_zone |
1806 | 1 | 600ns | $$base{'data'}{'now'}{'isdst'} = $isdst; | ||
1807 | 1 | 1µs | $$base{'data'}{'now'}{'abb'} = $abb; | ||
1808 | 1 | 1µs | $$base{'data'}{'now'}{'offset'} = $offset; | ||
1809 | |||||
1810 | # | ||||
1811 | # Treate SetDate/ForceDate | ||||
1812 | # | ||||
1813 | |||||
1814 | 1 | 800ns | if ($force) { | ||
1815 | $$base{'data'}{'now'}{'force'} = 1; | ||||
1816 | $$base{'data'}{'now'}{'set'} = 0; | ||||
1817 | } else { | ||||
1818 | 1 | 800ns | $$base{'data'}{'now'}{'force'} = 0; | ||
1819 | 1 | 1µs | $$base{'data'}{'now'}{'set'} = 1; | ||
1820 | 1 | 600ns | $$base{'data'}{'now'}{'setsecs'} = $time; | ||
1821 | 1 | 2µs | 1 | 61µs | my($err,$setdate) = $self->convert_to_gmt($date,$zone); # spent 61µs making 1 call to Date::Manip::TZ::convert_to_gmt |
1822 | 1 | 900ns | $$base{'data'}{'now'}{'setdate'} = $setdate; | ||
1823 | } | ||||
1824 | |||||
1825 | 1 | 6µs | return 0; | ||
1826 | } | ||||
1827 | |||||
1828 | 1 | 3µs | 1; | ||
1829 | # Local Variables: | ||||
1830 | # mode: cperl | ||||
1831 | # indent-tabs-mode: nil | ||||
1832 | # cperl-indent-level: 3 | ||||
1833 | # cperl-continued-statement-offset: 2 | ||||
1834 | # cperl-continued-brace-offset: 0 | ||||
1835 | # cperl-brace-offset: 0 | ||||
1836 | # cperl-brace-imaginary-offset: 0 | ||||
1837 | # cperl-label-offset: 0 | ||||
1838 | # End: | ||||
# spent 1µs within Date::Manip::TZ::CORE:close which was called 2 times, avg 650ns/call:
# 2 times (1µs+0s) by Date::Manip::TZ::_get_curr_zone at line 535, avg 650ns/call | |||||
# spent 8µs within Date::Manip::TZ::CORE:ftfile which was called 4 times, avg 2µs/call:
# 4 times (8µs+0s) by Date::Manip::TZ::_get_curr_zone at line 468, avg 2µs/call | |||||
# spent 16µs within Date::Manip::TZ::CORE:match which was called 9 times, avg 2µs/call:
# 4 times (5µs+0s) by Date::Manip::TZ::_get_curr_zone at line 477, avg 1µs/call
# 2 times (4µs+0s) by Date::Manip::TZ::zone at line 773, avg 2µs/call
# 2 times (800ns+0s) by Date::Manip::TZ::_get_curr_zone at line 503, avg 400ns/call
# once (6µs+0s) by Date::Manip::TZ::_config_var_setdate at line 1661 | |||||
# spent 6µs within Date::Manip::TZ::CORE:qr which was called 4 times, avg 2µs/call:
# once (3µs+0s) by Date::Manip::TZ::_config_var_setdate at line 1651
# once (2µs+0s) by Date::Manip::TZ::_config_var_setdate at line 1649
# once (700ns+0s) by Date::Manip::TZ::_config_var_setdate at line 1652
# once (600ns+0s) by Date::Manip::TZ::_config_var_setdate at line 1650 | |||||
# spent 2µs within Date::Manip::TZ::CORE:readline which was called 2 times, avg 1µs/call:
# 2 times (2µs+0s) by Date::Manip::TZ::_get_curr_zone at line 476, avg 1µs/call | |||||
# spent 22µs within Date::Manip::TZ::CORE:regcomp which was called:
# once (22µs+0s) by Date::Manip::TZ::_config_var_setdate at line 1661 | |||||
# spent 1µs within Date::Manip::TZ::CORE:sort which was called:
# once (1µs+0s) by Date::Manip::TZ::_all_periods at line 1073 | |||||
# spent 12µs within Date::Manip::TZ::CORE:subst which was called 10 times, avg 1µs/call:
# 2 times (5µs+0s) by Date::Manip::TZ::_get_curr_zone at line 529, avg 2µs/call
# 2 times (4µs+0s) by Date::Manip::TZ::_get_curr_zone at line 528, avg 2µs/call
# 2 times (1µs+0s) by Date::Manip::TZ::_get_curr_zone at line 530, avg 600ns/call
# 2 times (1µs+0s) by Date::Manip::TZ::_get_curr_zone at line 632, avg 500ns/call
# 2 times (800ns+0s) by Date::Manip::TZ::_get_curr_zone at line 531, avg 400ns/call |