Filename | /home/sulbeck/local/lib/perl5/5.20.1/Date/Manip/TZ.pm |
Statements | Executed 1957871 statements in 797ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2430 | 1 | 1 | 487ms | 1.33s | __zone | Date::Manip::TZ::
336 | 1 | 1 | 464ms | 472ms | _module | Date::Manip::TZ::
112286 | 2 | 1 | 159ms | 193ms | _all_periods | Date::Manip::TZ::
2423 | 1 | 1 | 58.9ms | 58.9ms | _list_add | Date::Manip::TZ::
4859 | 3 | 2 | 53.0ms | 88.3ms | date_period | Date::Manip::TZ::
12 | 1 | 1 | 34.6ms | 37.4ms | _check_abbrev_isdst | Date::Manip::TZ::
2600 | 2 | 1 | 20.7ms | 20.7ms | _periods | Date::Manip::TZ::
1984 | 4 | 1 | 17.4ms | 17.4ms | CORE:sort (opcode) | Date::Manip::TZ::
7291 | 4 | 2 | 10.6ms | 10.6ms | _zone | Date::Manip::TZ::
10 | 10 | 1 | 9.38ms | 9.38ms | CORE:regcomp (opcode) | Date::Manip::TZ::
2424 | 1 | 1 | 5.64ms | 6.07ms | _offmod | Date::Manip::TZ::
4 | 4 | 1 | 4.79ms | 15.7ms | _zrx | Date::Manip::TZ::
1 | 1 | 1 | 320µs | 498µs | _get_curr_zone | Date::Manip::TZ::
5762 | 14 | 1 | 297µs | 297µs | CORE:subst (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 25µs | 32µs | _init | Date::Manip::TZ::
91 | 3 | 1 | 24µs | 24µs | CORE:match (opcode) | Date::Manip::TZ::
13 | 13 | 1 | 11µs | 11µs | CORE:qr (opcode) | Date::Manip::TZ::
74 | 1 | 1 | 9µs | 9µs | CORE:readline (opcode) | Date::Manip::TZ::
2 | 1 | 1 | 8µs | 8µs | END | Date::Manip::TZ::
1 | 1 | 1 | 7µs | 16µs | BEGIN@721 | Date::Manip::TZ::
1 | 1 | 1 | 7µs | 515µs | _set_curr_zone | Date::Manip::TZ::
1 | 1 | 1 | 6µs | 14µs | BEGIN@1612 | Date::Manip::TZ::
1 | 1 | 1 | 5µs | 106µs | BEGIN@22 | Date::Manip::TZ::
1 | 1 | 1 | 5µs | 5µs | BEGIN@14 | Date::Manip::TZ::
1 | 1 | 1 | 5µs | 8µs | BEGIN@731 | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 10µs | BEGIN@189 | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 11µs | BEGIN@158 | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 7µs | BEGIN@19 | Date::Manip::TZ::
1 | 1 | 1 | 4µs | 9µs | BEGIN@1616 | Date::Manip::TZ::
1 | 1 | 1 | 3µs | 3µs | BEGIN@24 | Date::Manip::TZ::
3 | 1 | 1 | 3µs | 3µs | CORE:ftfile (opcode) | Date::Manip::TZ::
1 | 1 | 1 | 3µs | 10µs | BEGIN@20 | Date::Manip::TZ::
1 | 1 | 1 | 3µs | 518µs | _init_final | Date::Manip::TZ::
1 | 1 | 1 | 2µs | 2µs | BEGIN@15 | Date::Manip::TZ::
1 | 1 | 1 | 500ns | 500ns | CORE:close (opcode) | 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 | _config_var_setdate | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _config_var_tz | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _convert | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _convert_args | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _lastrule | Date::Manip::TZ::
0 | 0 | 0 | 0s | 0s | _list_union | 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 | 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_gmt | 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::
0 | 0 | 0 | 0s | 0s | zone | Date::Manip::TZ::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Date::Manip::TZ; | ||||
2 | # Copyright (c) 2008-2015 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 | 12µs | 1 | 5µs | # spent 5µs within Date::Manip::TZ::BEGIN@14 which was called:
# once (5µs+0s) by Date::Manip::Date::BEGIN@27 at line 14 # spent 5µs making 1 call to Date::Manip::TZ::BEGIN@14 |
15 | 2 | 17µs | 1 | 2µs | # spent 2µs within Date::Manip::TZ::BEGIN@15 which was called:
# once (2µs+0s) by Date::Manip::Date::BEGIN@27 at line 15 # spent 2µs making 1 call to Date::Manip::TZ::BEGIN@15 |
16 | 1 | 5µs | @ISA = qw(Date::Manip::Obj Date::Manip::TZ_Base); | ||
17 | |||||
18 | 1 | 6µs | require 5.010000; | ||
19 | 2 | 9µs | 2 | 10µs | # spent 7µs (4+3) within Date::Manip::TZ::BEGIN@19 which was called:
# once (4µs+3µs) by Date::Manip::Date::BEGIN@27 at line 19 # spent 7µs making 1 call to Date::Manip::TZ::BEGIN@19
# spent 3µs making 1 call to warnings::import |
20 | 2 | 10µs | 2 | 17µs | # spent 10µs (3+7) within Date::Manip::TZ::BEGIN@20 which was called:
# once (3µs+7µs) by Date::Manip::Date::BEGIN@27 at line 20 # spent 10µs making 1 call to Date::Manip::TZ::BEGIN@20
# spent 7µs making 1 call to strict::import |
21 | |||||
22 | 2 | 18µs | 2 | 207µs | # spent 106µs (5+101) within Date::Manip::TZ::BEGIN@22 which was called:
# once (5µs+101µs) by Date::Manip::Date::BEGIN@27 at line 22 # spent 106µs making 1 call to Date::Manip::TZ::BEGIN@22
# spent 101µs making 1 call to Exporter::import |
23 | 1 | 46µs | require Date::Manip::Zones; | ||
24 | 2 | 211µs | 1 | 3µs | # spent 3µs within Date::Manip::TZ::BEGIN@24 which was called:
# once (3µs+0s) by Date::Manip::Date::BEGIN@27 at line 24 # spent 3µs making 1 call to Date::Manip::TZ::BEGIN@24 |
25 | |||||
26 | 1 | 100ns | our $VERSION; | ||
27 | 1 | 300ns | $VERSION='6.49'; | ||
28 | 1 | 1µs | END { undef $VERSION; } | ||
29 | |||||
30 | # To get rid of a 'used only once' warnings. | ||||
31 | # spent 8µs within Date::Manip::TZ::END which was called 2 times, avg 4µs/call:
# 2 times (8µs+0s) by main::RUNTIME at line 0 of ../dm5dm6_ex3, avg 4µs/call | ||||
32 | 1 | 1µs | my $tmp = \%Date::Manip::Zones::Module; | ||
33 | 1 | 700ns | $tmp = \%Date::Manip::Zones::ZoneNames; | ||
34 | 1 | 400ns | $tmp = \%Date::Manip::Zones::Alias; | ||
35 | 1 | 800ns | $tmp = \%Date::Manip::Zones::Abbrev; | ||
36 | 1 | 300ns | $tmp = \%Date::Manip::Zones::Offmod; | ||
37 | 1 | 600ns | $tmp = $Date::Manip::Zones::FirstDate; | ||
38 | 1 | 200ns | $tmp = $Date::Manip::Zones::LastDate; | ||
39 | 1 | 300ns | $tmp = $Date::Manip::Zones::LastYear; | ||
40 | 1 | 200ns | $tmp = $Date::Manip::Zones::TzcodeVersion; | ||
41 | 1 | 2µs | $tmp = $Date::Manip::Zones::TzdataVersion; | ||
42 | } | ||||
43 | |||||
44 | ######################################################################## | ||||
45 | # BASE METHODS | ||||
46 | ######################################################################## | ||||
47 | |||||
48 | # spent 32µs (25+7) within Date::Manip::TZ::_init which was called:
# once (25µs+7µs) by Date::Manip::Obj::new at line 162 of Date/Manip/Obj.pm | ||||
49 | 1 | 300ns | my($self) = @_; | ||
50 | |||||
51 | 1 | 14µ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 | 1 | 500ns | my $dmb = $$self{'base'}; | ||
96 | 1 | 900ns | 1 | 7µs | my $os = $dmb->_os(); # spent 7µs making 1 call to Date::Manip::Base::_os |
97 | |||||
98 | 1 | 2µs | if ($os eq 'Unix') { | ||
99 | 1 | 400ns | $$self{'data'}{'path'} = '/bin:/usr/bin'; | ||
100 | 1 | 7µ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 518µs (3+515) within Date::Manip::TZ::_init_final which was called:
# once (3µs+515µs) by Date::Manip::Obj::new at line 165 of Date/Manip/Obj.pm | ||||
153 | 1 | 300ns | my($self) = @_; | ||
154 | |||||
155 | 1 | 4µs | 1 | 515µs | $self->_set_curr_zone(); # spent 515µs making 1 call to Date::Manip::TZ::_set_curr_zone |
156 | } | ||||
157 | |||||
158 | 2 | 105µs | 2 | 18µs | # spent 11µs (4+7) within Date::Manip::TZ::BEGIN@158 which was called:
# once (4µs+7µs) by Date::Manip::Date::BEGIN@27 at line 158 # spent 11µs making 1 call to Date::Manip::TZ::BEGIN@158
# spent 7µs making 1 call to strict::unimport |
159 | # This loads data from an offset module | ||||
160 | # | ||||
161 | # spent 6.07ms (5.64+434µs) within Date::Manip::TZ::_offmod which was called 2424 times, avg 3µs/call:
# 2424 times (5.64ms+434µs) by Date::Manip::TZ::__zone at line 893, avg 3µs/call | ||||
162 | 2424 | 449µs | my($self,$offset) = @_; | ||
163 | 2424 | 3.18ms | return if (exists $$self{'data'}{'Offsets'}{$offset}); | ||
164 | |||||
165 | 15 | 11µs | my $mod = $$self{'data'}{'Offmod'}{$offset}; | ||
166 | 15 | 409µs | eval "require Date::Manip::Offset::${mod}"; # spent 134µs executing statements in 2 string evals (merged)
# spent 114µs executing statements in string eval
# spent 108µs executing statements in 2 string evals (merged)
# spent 104µs executing statements in string eval
# spent 99µs executing statements in 2 string evals (merged)
# spent 89µs executing statements in string eval
# spent 80µs executing statements in string eval
# spent 79µs executing statements in string eval
# spent 70µs executing statements in string eval
# spent 48µs executing statements in string eval
# spent 47µs executing statements in string eval
# spent 46µs executing statements in string eval | ||
167 | 15 | 52µs | my %off = %{ "Date::Manip::Offset::${mod}::Offset" }; | ||
168 | |||||
169 | 15 | 98µs | $$self{'data'}{'Offsets'}{$offset} = { %off }; | ||
170 | } | ||||
171 | |||||
172 | # This loads data from a zone module (takes a lowercase zone) | ||||
173 | # | ||||
174 | # spent 472ms (464+7.85) within Date::Manip::TZ::_module which was called 336 times, avg 1.40ms/call:
# 336 times (464ms+7.85ms) by Date::Manip::TZ::__zone at line 947, avg 1.40ms/call | ||||
175 | 336 | 74µs | my($self,$zone) = @_; | ||
176 | 336 | 125µs | return if (exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||
177 | |||||
178 | 336 | 248µs | my $mod = $$self{'data'}{'Module'}{$zone}; | ||
179 | 336 | 4.67ms | eval "require Date::Manip::TZ::${mod}"; # spent 575µs executing statements in 13 string evals (merged)
# spent 540µs executing statements in 12 string evals (merged)
# spent 536µs executing statements in 11 string evals (merged)
# spent 526µs executing statements in 12 string evals (merged)
# spent 455µs executing statements in 10 string evals (merged)
# spent 443µs executing statements in 9 string evals (merged)
# spent 429µs executing statements in 8 string evals (merged)
# spent 415µs executing statements in 9 string evals (merged)
# spent 392µs executing statements in 9 string evals (merged)
# spent 378µs executing statements in 8 string evals (merged)
# spent 364µs executing statements in 8 string evals (merged)
# spent 361µs executing statements in 7 string evals (merged)
# spent 361µs executing statements in 7 string evals (merged)
# spent 350µs executing statements in 8 string evals (merged)
# spent 328µs executing statements in 7 string evals (merged)
# spent 314µs executing statements in 7 string evals (merged)
# spent 311µs executing statements in 7 string evals (merged)
# spent 310µs executing statements in 7 string evals (merged)
# spent 306µs executing statements in 6 string evals (merged)
# spent 281µs executing statements in 6 string evals (merged)
# spent 281µs executing statements in 6 string evals (merged)
# spent 277µs executing statements in 6 string evals (merged)
# spent 273µs executing statements in 5 string evals (merged)
# spent 272µs executing statements in 6 string evals (merged)
# spent 265µs executing statements in 6 string evals (merged)
# spent 230µs executing statements in 5 string evals (merged)
# spent 229µs executing statements in 5 string evals (merged)
# spent 224µs executing statements in 5 string evals (merged)
# spent 221µs executing statements in 5 string evals (merged)
# spent 220µs executing statements in 5 string evals (merged)
# spent 205µs executing statements in 4 string evals (merged)
# spent 200µs executing statements in 4 string evals (merged)
# spent 186µs executing statements in 4 string evals (merged)
# spent 184µs executing statements in 4 string evals (merged)
# spent 182µs executing statements in 4 string evals (merged)
# spent 174µs executing statements in 4 string evals (merged)
# spent 174µs executing statements in 4 string evals (merged)
# spent 172µs executing statements in 4 string evals (merged)
# spent 168µs executing statements in 4 string evals (merged)
# spent 154µs executing statements in 3 string evals (merged)
# spent 153µs executing statements in 3 string evals (merged)
# spent 144µs executing statements in 3 string evals (merged)
# spent 140µs executing statements in 3 string evals (merged)
# spent 139µs executing statements in 3 string evals (merged)
# spent 138µs executing statements in 3 string evals (merged)
# spent 138µs executing statements in 3 string evals (merged)
# spent 133µs executing statements in 3 string evals (merged)
# spent 131µs executing statements in 3 string evals (merged)
# spent 129µs executing statements in 3 string evals (merged)
# spent 103µs executing statements in 2 string evals (merged)
# spent 94µs executing statements in 2 string evals (merged)
# spent 91µs executing statements in 2 string evals (merged)
# spent 90µs executing statements in 2 string evals (merged)
# spent 89µs executing statements in 2 string evals (merged)
# spent 89µs executing statements in 2 string evals (merged)
# spent 87µs executing statements in 2 string evals (merged)
# spent 67µs executing statements in string eval
# spent 53µs executing statements in string eval
# spent 48µs executing statements in string eval
# spent 47µs executing statements in string eval
# spent 47µs executing statements in string eval
# spent 46µs executing statements in string eval
# spent 46µs executing statements in string eval
# spent 45µs executing statements in string eval
# spent 45µs executing statements in string eval
# spent 44µs executing statements in string eval
# spent 43µs executing statements in string eval
# spent 43µs executing statements in string eval
# spent 43µs executing statements in string eval
# spent 43µs executing statements in string eval
# spent 43µs executing statements in string eval
# spent 42µs executing statements in string eval
# spent 42µs executing statements in string eval
# spent 42µs executing statements in string eval
# spent 42µs executing statements in string eval
# spent 42µs executing statements in string eval
# spent 42µs executing statements in string eval
# spent 41µs executing statements in string eval
# spent 41µs executing statements in string eval
# spent 41µs executing statements in string eval
# spent 40µs executing statements in string eval
# spent 40µs executing statements in string eval
# spent 40µs executing statements in string eval
# spent 40µs executing statements in string eval
# spent 39µs executing statements in string eval
# spent 38µs executing statements in string eval
# spent 38µs executing statements in string eval | ||
180 | 336 | 2.86ms | my %dates = %{ "Date::Manip::TZ::${mod}::Dates" }; | ||
181 | 336 | 353µs | my %last = %{ "Date::Manip::TZ::${mod}::LastRule" }; | ||
182 | 336 | 4.22ms | $$self{'data'}{'Zones'}{$zone} = | ||
183 | { | ||||
184 | 'Dates' => { %dates }, | ||||
185 | 'LastRule' => { %last }, | ||||
186 | 'Loaded' => 1 | ||||
187 | }; | ||||
188 | } | ||||
189 | 2 | 1.24ms | 2 | 16µs | # spent 10µs (4+6) within Date::Manip::TZ::BEGIN@189 which was called:
# once (4µs+6µs) by Date::Manip::Date::BEGIN@27 at line 189 # spent 10µs making 1 call to Date::Manip::TZ::BEGIN@189
# spent 6µs making 1 call to strict::import |
190 | |||||
191 | ######################################################################## | ||||
192 | # CHECKING/MODIFYING ZONEINFO DATA | ||||
193 | ######################################################################## | ||||
194 | |||||
195 | # spent 10.6ms within Date::Manip::TZ::_zone which was called 7291 times, avg 1µs/call:
# 4859 times (7.24ms+0s) by Date::Manip::TZ::date_period at line 1218, avg 1µs/call
# 2430 times (3.30ms+0s) by Date::Manip::Date::set at line 2657 of Date/Manip/Date.pm, avg 1µs/call
# once (11µs+0s) by Date::Manip::TZ::_set_curr_zone at line 388
# once (6µs+0s) by Date::Manip::TZ::_get_curr_zone at line 635 | ||||
196 | 7291 | 1.20ms | my($self,$zone) = @_; | ||
197 | 7291 | 1.62ms | $zone = lc($zone); | ||
198 | |||||
199 | 7291 | 12.5ms | 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 515µs (7+509) within Date::Manip::TZ::_set_curr_zone which was called:
# once (7µs+509µs) by Date::Manip::TZ::_init_final at line 155 | ||||
384 | 1 | 300ns | my($self) = @_; | ||
385 | 1 | 300ns | my $dmb = $$self{'base'}; | ||
386 | 1 | 2µs | 1 | 498µs | my $currzone = $self->_get_curr_zone(); # spent 498µs making 1 call to Date::Manip::TZ::_get_curr_zone |
387 | |||||
388 | 1 | 12µs | 1 | 11µs | $$dmb{'data'}{'now'}{'systz'} = $self->_zone($currzone); # spent 11µs making 1 call to Date::Manip::TZ::_zone |
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 498µs (320+178) within Date::Manip::TZ::_get_curr_zone which was called:
# once (320µs+178µs) by Date::Manip::TZ::_set_curr_zone at line 386 | ||||
395 | 1 | 400ns | my($self) = @_; | ||
396 | 1 | 500ns | my $dmb = $$self{'base'}; | ||
397 | |||||
398 | 1 | 500ns | my $t = time; | ||
399 | 1 | 15µs | my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t); | ||
400 | 1 | 300ns | my $currzone = ''; | ||
401 | 1 | 300ns | my $dstflag = ($isdst ? 'dstonly' : 'stdonly'); | ||
402 | |||||
403 | 1 | 2µs | my (@methods) = @{ $$self{'data'}{'methods'} }; | ||
404 | 1 | 700ns | my $debug = ($ENV{DATE_MANIP_DEBUG} ? 1 : 0); | ||
405 | |||||
406 | 1 | 5µs | defined $$self{'data'}{'path'} | ||
407 | and local $ENV{PATH} = $$self{'data'}{'path'}; | ||||
408 | |||||
409 | METHOD: | ||||
410 | 1 | 500ns | while (@methods) { | ||
411 | 5 | 900ns | my $method = shift(@methods); | ||
412 | 5 | 800ns | my @zone = (); | ||
413 | |||||
414 | 5 | 2µs | if ($method eq 'main') { | ||
415 | |||||
416 | 1 | 300ns | if (! @methods) { | ||
417 | warn "ERROR: [_set_curr_zone] main requires argument\n"; | ||||
418 | return; | ||||
419 | } | ||||
420 | 1 | 100ns | my $var = shift(@methods); | ||
421 | 1 | 500ns | push(@zone,$$::var) if (defined $$::var); | ||
422 | |||||
423 | 1 | 200ns | if ($debug) { | ||
424 | print "*** DEBUG *** main $var = " . | ||||
425 | (defined $$::var ? $$::var : 'undef') . "\n"; | ||||
426 | } | ||||
427 | |||||
428 | } elsif ($method eq 'env') { | ||||
429 | 1 | 400ns | if (@methods < 2) { | ||
430 | warn "ERROR: [_set_curr_zone] env requires 2 argument\n"; | ||||
431 | return; | ||||
432 | } | ||||
433 | 1 | 600ns | my $type = lc( shift(@methods) ); | ||
434 | 1 | 300ns | 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 | 1 | 600ns | my $var = shift(@methods); | ||
440 | 1 | 800ns | 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 | 1 | 300ns | 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 | 3 | 400ns | if (! @methods) { | ||
464 | warn "ERROR: [_set_curr_zone] file requires argument\n"; | ||||
465 | return; | ||||
466 | } | ||||
467 | 3 | 400ns | my $file = shift(@methods); | ||
468 | 3 | 9µs | 3 | 3µs | next if (! -f $file); # spent 3µs making 3 calls to Date::Manip::TZ::CORE:ftfile, avg 1µs/call |
469 | |||||
470 | 1 | 3µs | 1 | 27µs | my $in = new IO::File; # spent 27µs making 1 call to IO::File::new |
471 | 1 | 2µs | 1 | 16µs | $in->open($file) || next; # spent 16µs making 1 call to IO::File::open |
472 | 1 | 300ns | my $firstline = 1; | ||
473 | |||||
474 | 1 | 300ns | my @z; | ||
475 | 1 | 39µs | 68 | 76µs | while (! $in->eof) { # spent 76µs making 68 calls to IO::Handle::eof, avg 1µs/call |
476 | 74 | 82µs | 74 | 9µs | my $line = <$in>; # spent 9µs making 74 calls to Date::Manip::TZ::CORE:readline, avg 126ns/call |
477 | 74 | 93µs | 83 | 19µs | next if ($line =~ /^\s*\043/ || # spent 19µs making 83 calls to Date::Manip::TZ::CORE:match, avg 234ns/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 | 7 | 8µs | 7 | 3µs | if ($line =~ /^\s*(?:TZ|TIMEZONE|ZONE)\s*=\s*(.*)\s*$/) { # spent 3µs making 7 calls to Date::Manip::TZ::CORE:match, avg 443ns/call |
504 | 1 | 800ns | my $val = $1; | ||
505 | 1 | 400ns | @z = (); | ||
506 | 1 | 100ns | last if (! $val); | ||
507 | |||||
508 | 1 | 3µs | 1 | 1µs | if ($val =~ /^(["'])(.*?)\1/) { # spent 1µs making 1 call to Date::Manip::TZ::CORE:match |
509 | 1 | 400ns | my $z = $2; | ||
510 | 1 | 200ns | last if (! $z); | ||
511 | 1 | 2µs | 1 | 300ns | $z =~ s/\s+/_/g; # spent 300ns making 1 call to Date::Manip::TZ::CORE:subst |
512 | 1 | 400ns | 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 | 1 | 600ns | last; | ||
525 | } | ||||
526 | 6 | 4µs | 6 | 11µs | if ($firstline) { # spent 11µs making 6 calls to IO::Handle::eof, avg 2µs/call |
527 | 1 | 300ns | $firstline = 0; | ||
528 | 1 | 3µs | 1 | 900ns | $line =~ s/^\s*//; # spent 900ns making 1 call to Date::Manip::TZ::CORE:subst |
529 | 1 | 3µs | 1 | 1µs | $line =~ s/\s*$//; # spent 1µs making 1 call to Date::Manip::TZ::CORE:subst |
530 | 1 | 2µs | 1 | 900ns | $line =~ s/["']//g; # " # spent 900ns making 1 call to Date::Manip::TZ::CORE:subst |
531 | 1 | 2µs | 1 | 300ns | $line =~ s/\s+/_/g; # spent 300ns making 1 call to Date::Manip::TZ::CORE:subst |
532 | 1 | 600ns | push(@z,$line); | ||
533 | } | ||||
534 | } | ||||
535 | 1 | 2µs | 1 | 500ns | close(IN); # spent 500ns making 1 call to Date::Manip::TZ::CORE:close |
536 | |||||
537 | 1 | 300ns | push(@zone,@z) if (@z); | ||
538 | |||||
539 | 1 | 7µ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 | 3 | 2µs | foreach my $zone (@zone) { | ||
630 | 1 | 700ns | $zone = lc($zone); | ||
631 | # OpenUNIX puts a colon at the start | ||||
632 | 1 | 12µs | 1 | 400ns | $zone =~ s/^://; # spent 400ns making 1 call to Date::Manip::TZ::CORE:subst |
633 | |||||
634 | # If we got a zone name/alias | ||||
635 | 1 | 2µs | 1 | 6µs | $currzone = $self->_zone($zone); # spent 6µs making 1 call to Date::Manip::TZ::_zone |
636 | 1 | 2µ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 | 1 | 200ns | if (! $currzone) { | ||
652 | warn "ERROR: Date::Manip unable to determine Time Zone.\n"; | ||||
653 | die; | ||||
654 | } | ||||
655 | |||||
656 | 1 | 4µ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 | 47µs | 2 | 25µs | # spent 16µs (7+9) within Date::Manip::TZ::BEGIN@721 which was called:
# once (7µs+9µs) by Date::Manip::Date::BEGIN@27 at line 721 # spent 16µs making 1 call to Date::Manip::TZ::BEGIN@721
# spent 9µ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.10ms | 2 | 11µs | # spent 8µs (5+3) within Date::Manip::TZ::BEGIN@731 which was called:
# once (5µs+3µs) by Date::Manip::Date::BEGIN@27 at line 731 # spent 8µs making 1 call to Date::Manip::TZ::BEGIN@731
# spent 3µs making 1 call to warnings::import |
732 | |||||
733 | ######################################################################## | ||||
734 | # DETERMINING A TIMEZONE | ||||
735 | ######################################################################## | ||||
736 | |||||
737 | sub zone { | ||||
738 | my($self,@args) = @_; | ||||
739 | my $dmb = $$self{'base'}; | ||||
740 | if (! @args) { | ||||
741 | my($tz) = $self->_now('tz',1); | ||||
742 | return $$self{'data'}{'ZoneNames'}{$tz} | ||||
743 | } | ||||
744 | |||||
745 | # Parse the arguments | ||||
746 | |||||
747 | my($zone,$abbrev,$offset,$dstflag) = ('','','',''); | ||||
748 | my $date = []; | ||||
749 | my $tmp; | ||||
750 | foreach my $arg (@args) { | ||||
751 | |||||
752 | if (ref($arg) eq 'ARRAY') { | ||||
753 | if ($#$arg == 5) { | ||||
754 | # [Y,M,D,H,Mn,S] | ||||
755 | return undef if (@$date); | ||||
756 | $date = $arg; | ||||
757 | |||||
758 | } elsif ($#$arg == 2) { | ||||
759 | # [H,Mn,S] | ||||
760 | return undef if ($offset); | ||||
761 | $offset = $dmb->join('offset',$arg); | ||||
762 | return undef if (! $offset); | ||||
763 | |||||
764 | } else { | ||||
765 | return undef; | ||||
766 | } | ||||
767 | |||||
768 | } elsif (ref($arg)) { | ||||
769 | return undef; | ||||
770 | |||||
771 | } else { | ||||
772 | $arg = lc($arg); | ||||
773 | |||||
774 | if ($arg =~ /^(std|dst|stdonly|dstonly)$/) { | ||||
775 | return undef if ($dstflag); | ||||
776 | $dstflag = $arg; | ||||
777 | |||||
778 | } elsif ($tmp = $self->_zone($arg)) { | ||||
779 | return undef if ($zone); | ||||
780 | $zone = $tmp; | ||||
781 | |||||
782 | } elsif (exists $$self{'data'}{'MyAbbrev'}{$arg} || | ||||
783 | exists $$self{'data'}{'Abbrev'}{$arg}) { | ||||
784 | return undef if ($abbrev); | ||||
785 | $abbrev = $arg; | ||||
786 | } elsif (exists $$self{'data'}{'Abbrev'}{$arg}) { | ||||
787 | return undef if ($abbrev); | ||||
788 | $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 | return $self->__zone($date,$offset,$zone,$abbrev,$dstflag); | ||||
805 | } | ||||
806 | |||||
807 | # $date = [Y,M,D,H,Mn,S] | ||||
808 | # $offset = '-HH:Mn:SS' | ||||
809 | # $zone = 'us/eastern' (lowercase) | ||||
810 | # $abbrev = 'est' (lowercase) | ||||
811 | # $dstflag= 'stdonly' (lowercase) | ||||
812 | # | ||||
813 | # spent 1.33s (487ms+842ms) within Date::Manip::TZ::__zone which was called 2430 times, avg 547µs/call:
# 2430 times (487ms+842ms) by Date::Manip::Date::_parse_check at line 986 of Date/Manip/Date.pm, avg 547µs/call | ||||
814 | 2430 | 963µs | my($self,$date,$offset,$zone,$abbrev,$dstflag) = @_; | ||
815 | 2430 | 466µs | my $dmb = $$self{'base'}; | ||
816 | |||||
817 | # | ||||
818 | # Determine the zones that match all data. | ||||
819 | # | ||||
820 | |||||
821 | 2430 | 165µs | my @zone; | ||
822 | |||||
823 | 2430 | 237µs | while (1) { | ||
824 | |||||
825 | # No information | ||||
826 | |||||
827 | 2430 | 432µs | if (! $zone && | ||
828 | ! $abbrev && | ||||
829 | ! $offset) { | ||||
830 | my($z) = $self->_now('tz',1); | ||||
831 | @zone = (lc($z)); | ||||
832 | } | ||||
833 | |||||
834 | # $dstflag | ||||
835 | # | ||||
836 | # $dstflag is "dst' if | ||||
837 | # zone is passed in as an offset | ||||
838 | # date is passed in | ||||
839 | |||||
840 | 2430 | 822µs | $dstflag = "dst" if ($offset && @$date && ! $dstflag); | ||
841 | |||||
842 | 2430 | 140µs | my(@isdst); | ||
843 | 2430 | 1.28ms | if ($dstflag eq 'stdonly') { | ||
844 | @isdst = (0); | ||||
845 | } elsif ($dstflag eq 'dstonly') { | ||||
846 | @isdst = (1); | ||||
847 | } elsif ($dstflag eq 'dst') { | ||||
848 | @isdst = (1,0); | ||||
849 | } else { | ||||
850 | 6 | 4µs | @isdst = (0,1); | ||
851 | } | ||||
852 | |||||
853 | # $zone | ||||
854 | |||||
855 | 2430 | 221µs | if ($zone) { | ||
856 | @zone = ($zone); | ||||
857 | } | ||||
858 | |||||
859 | # $abbrev | ||||
860 | |||||
861 | 2430 | 155µs | if ($abbrev) { | ||
862 | 6 | 900ns | my @abbrev_zones; | ||
863 | 6 | 26µs | if (exists $$self{'data'}{'MyAbbrev'}{$abbrev}) { | ||
864 | @abbrev_zones = @{ $$self{'data'}{'MyAbbrev'}{$abbrev} }; | ||||
865 | } elsif (exists $$self{'data'}{'Abbrev'}{$abbrev}) { | ||||
866 | @abbrev_zones = @{ $$self{'data'}{'Abbrev'}{$abbrev} }; | ||||
867 | } | ||||
868 | |||||
869 | 6 | 1µs | my @z; | ||
870 | 6 | 4µs | foreach my $isdst (@isdst) { | ||
871 | 12 | 27µs | 12 | 37.4ms | my @tmp = $self->_check_abbrev_isdst($abbrev,$isdst,@abbrev_zones); # spent 37.4ms making 12 calls to Date::Manip::TZ::_check_abbrev_isdst, avg 3.12ms/call |
872 | 12 | 12µs | if (@tmp) { | ||
873 | if (@z) { | ||||
874 | @z = _list_add(\@z,\@tmp); | ||||
875 | } else { | ||||
876 | 6 | 7µs | @z = @tmp; | ||
877 | } | ||||
878 | } | ||||
879 | } | ||||
880 | |||||
881 | 6 | 3µs | if (@zone) { | ||
882 | @zone = _list_union(\@z,\@zone); | ||||
883 | } else { | ||||
884 | 6 | 9µs | @zone = @z; | ||
885 | } | ||||
886 | 6 | 8µs | last if (! @zone); | ||
887 | } | ||||
888 | |||||
889 | # $offset | ||||
890 | |||||
891 | 2430 | 450µs | if ($offset) { | ||
892 | 2424 | 1.07ms | return undef if (! exists $$self{'data'}{'Offmod'}{$offset}); | ||
893 | 2424 | 1.39ms | 2424 | 6.07ms | $self->_offmod($offset); # spent 6.07ms making 2424 calls to Date::Manip::TZ::_offmod, avg 3µs/call |
894 | |||||
895 | 2424 | 166µs | my @z; | ||
896 | 2424 | 684µs | foreach my $isdst (@isdst) { | ||
897 | 4848 | 3.73ms | my $tmp = $$self{'data'}{'MyOffsets'}{$offset}{$isdst} || | ||
898 | $$self{'data'}{'Offsets'}{$offset}{$isdst}; | ||||
899 | # my @tmp; | ||||
900 | # if (exists $$self{'data'}{'MyOffsets'}{$offset}{$isdst}) { | ||||
901 | # @tmp = @{ $$self{'data'}{'MyOffsets'}{$offset}{$isdst} }; | ||||
902 | # } elsif (exists $$self{'data'}{'Offsets'}{$offset}{$isdst}) { | ||||
903 | # @tmp = @{ $$self{'data'}{'Offsets'}{$offset}{$isdst} }; | ||||
904 | # } | ||||
905 | |||||
906 | 4848 | 278µs | my @tmp; | ||
907 | 4848 | 692µs | if ($abbrev) { | ||
908 | @tmp = $self->_check_offset_abbrev_isdst($offset,$abbrev,$isdst,$tmp); | ||||
909 | } else { | ||||
910 | 4848 | 6.88ms | @tmp = @$tmp if ($tmp); | ||
911 | } | ||||
912 | |||||
913 | 4848 | 14.7ms | 2423 | 58.9ms | if (@tmp) { # spent 58.9ms making 2423 calls to Date::Manip::TZ::_list_add, avg 24µs/call |
914 | if (@z) { | ||||
915 | @z = _list_add(\@z,\@tmp); | ||||
916 | } else { | ||||
917 | 2424 | 1.84ms | @z = @tmp; | ||
918 | } | ||||
919 | } | ||||
920 | } | ||||
921 | |||||
922 | 2424 | 570µs | if (@zone) { | ||
923 | @zone = _list_union(\@zone,\@z); | ||||
924 | } else { | ||||
925 | 2424 | 3.46ms | @zone = @z; | ||
926 | } | ||||
927 | 2424 | 1.73ms | last if (! @zone); | ||
928 | } | ||||
929 | |||||
930 | # $date | ||||
931 | |||||
932 | 2430 | 636µs | if (@$date) { | ||
933 | # Get all periods for the year. | ||||
934 | # | ||||
935 | # Test all periods to make sure that $date is between the | ||||
936 | # wallclock times AND matches other criteria. All periods | ||||
937 | # must be tested since the same wallclock time can be in | ||||
938 | # multiple periods. | ||||
939 | |||||
940 | 2430 | 142µs | my @tmp; | ||
941 | 2430 | 303µs | my $isdst = ''; | ||
942 | 2430 | 279µs | $isdst = 0 if ($dstflag eq 'stdonly'); | ||
943 | 2430 | 190µs | $isdst = 1 if ($dstflag eq 'dstonly'); | ||
944 | |||||
945 | ZONE: | ||||
946 | 2430 | 4.86ms | foreach my $z (@zone) { | ||
947 | 107427 | 40.9ms | 336 | 472ms | $self->_module($z) if (! exists $$self{'data'}{'Zones'}{$z}{'Loaded'}); # spent 472ms making 336 calls to Date::Manip::TZ::_module, avg 1.40ms/call |
948 | 107427 | 13.2ms | my $y = $$date[0]; | ||
949 | 107427 | 56.3ms | 107427 | 186ms | my @periods = $self->_all_periods($z,$y); # spent 186ms making 107427 calls to Date::Manip::TZ::_all_periods, avg 2µs/call |
950 | |||||
951 | 107427 | 47.7ms | foreach my $period (@periods) { | ||
952 | 221967 | 109ms | 162405 | 82.2ms | next if (($abbrev ne '' && lc($abbrev) ne lc($$period[4])) || # spent 82.2ms making 162405 calls to Date::Manip::Base::cmp, avg 506ns/call |
953 | ($offset ne '' && $offset ne $$period[2]) || | ||||
954 | ($isdst ne '' && $isdst ne $$period[5]) || | ||||
955 | $dmb->cmp($date,$$period[1]) == -1 || | ||||
956 | $dmb->cmp($date,$$period[7]) == 1 | ||||
957 | ); | ||||
958 | 47526 | 5.70ms | push(@tmp,$z); | ||
959 | 47526 | 11.4ms | next ZONE; | ||
960 | } | ||||
961 | } | ||||
962 | 2430 | 3.82ms | @zone = @tmp; | ||
963 | 2430 | 1.14ms | last if (! @zone); | ||
964 | } | ||||
965 | |||||
966 | 2430 | 754µs | last; | ||
967 | } | ||||
968 | |||||
969 | # Return the value/list | ||||
970 | |||||
971 | 2430 | 315µs | if (wantarray) { | ||
972 | my @ret; | ||||
973 | foreach my $z (@zone) { | ||||
974 | push(@ret,$$self{'data'}{'ZoneNames'}{$z}); | ||||
975 | } | ||||
976 | return @ret; | ||||
977 | } | ||||
978 | |||||
979 | 2430 | 298µs | return '' if (! @zone); | ||
980 | 2430 | 4.89ms | return $$self{'data'}{'ZoneNames'}{$zone[0]} | ||
981 | } | ||||
982 | |||||
983 | # This returns a list of all timezones which have the correct | ||||
984 | # abbrev/isdst combination. | ||||
985 | # | ||||
986 | # spent 37.4ms (34.6+2.83) within Date::Manip::TZ::_check_abbrev_isdst which was called 12 times, avg 3.12ms/call:
# 12 times (34.6ms+2.83ms) by Date::Manip::TZ::__zone at line 871, avg 3.12ms/call | ||||
987 | 12 | 15µs | my($self,$abbrev,$isdst,@zones) = @_; | ||
988 | |||||
989 | 12 | 3µs | my @ret; | ||
990 | ZONE: | ||||
991 | 12 | 19µs | foreach my $zone (@zones) { | ||
992 | 302 | 153µs | $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||
993 | |||||
994 | 302 | 4.53ms | 302 | 2.83ms | foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { # spent 2.83ms making 302 calls to Date::Manip::TZ::CORE:sort, avg 9µs/call |
995 | 13098 | 8.67ms | my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} }; | ||
996 | 13098 | 6.82ms | foreach my $period (@periods) { | ||
997 | 25179 | 11.5ms | my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||
998 | 25179 | 5.44ms | next if (lc($abbrev) ne lc($abb) || | ||
999 | $isdst != $dst); | ||||
1000 | 151 | 21µs | push(@ret,$zone); | ||
1001 | 151 | 219µs | next ZONE; | ||
1002 | } | ||||
1003 | } | ||||
1004 | } | ||||
1005 | |||||
1006 | 12 | 37µs | return @ret; | ||
1007 | } | ||||
1008 | |||||
1009 | # This returns a list of all timezones which have the correct | ||||
1010 | # abbrev/isdst combination. | ||||
1011 | # | ||||
1012 | sub _check_offset_abbrev_isdst { | ||||
1013 | my($self,$offset,$abbrev,$isdst,$zones) = @_; | ||||
1014 | |||||
1015 | my @ret; | ||||
1016 | ZONE: foreach my $zone (@$zones) { | ||||
1017 | $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||||
1018 | |||||
1019 | foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
1020 | my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} }; | ||||
1021 | foreach my $period (@periods) { | ||||
1022 | my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||||
1023 | next if (lc($abbrev) ne lc($abb) || | ||||
1024 | $offset ne $off || | ||||
1025 | $isdst != $dst); | ||||
1026 | push(@ret,$zone); | ||||
1027 | next ZONE; | ||||
1028 | } | ||||
1029 | } | ||||
1030 | } | ||||
1031 | |||||
1032 | return @ret; | ||||
1033 | } | ||||
1034 | |||||
1035 | # This finds the elements common to two lists, and preserves the order | ||||
1036 | # from the first list. | ||||
1037 | # | ||||
1038 | sub _list_union { | ||||
1039 | my($list1,$list2) = @_; | ||||
1040 | my(%list2) = map { $_,1 } @$list2; | ||||
1041 | my(@ret); | ||||
1042 | foreach my $ele (@$list1) { | ||||
1043 | push(@ret,$ele) if (exists $list2{$ele}); | ||||
1044 | } | ||||
1045 | return @ret; | ||||
1046 | } | ||||
1047 | |||||
1048 | # This adds elements from the second list to the first list, provided | ||||
1049 | # they are not already there. | ||||
1050 | # | ||||
1051 | # spent 58.9ms within Date::Manip::TZ::_list_add which was called 2423 times, avg 24µs/call:
# 2423 times (58.9ms+0s) by Date::Manip::TZ::__zone at line 913, avg 24µs/call | ||||
1052 | 2423 | 363µs | my($list1,$list2) = @_; | ||
1053 | 2423 | 12.0ms | my(%list1) = map { $_,1 } @$list1; | ||
1054 | 2423 | 1.69ms | my(@ret) = @$list1; | ||
1055 | 2423 | 2.52ms | foreach my $ele (@$list2) { | ||
1056 | 87983 | 10.3ms | next if (exists $list1{$ele}); | ||
1057 | 66140 | 6.17ms | push(@ret,$ele); | ||
1058 | 66140 | 17.6ms | $list1{$ele} = 1; | ||
1059 | } | ||||
1060 | 2423 | 10.1ms | return @ret; | ||
1061 | } | ||||
1062 | |||||
1063 | ######################################################################## | ||||
1064 | # PERIODS METHODS | ||||
1065 | ######################################################################## | ||||
1066 | |||||
1067 | sub all_periods { | ||||
1068 | my($self,$zone,$year) = @_; | ||||
1069 | |||||
1070 | my $z = $self->_zone($zone); | ||||
1071 | if (! $z) { | ||||
1072 | warn "ERROR: [periods] Invalid zone: $zone\n"; | ||||
1073 | return; | ||||
1074 | } | ||||
1075 | $zone = $z; | ||||
1076 | $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||||
1077 | |||||
1078 | # Run a faster 'dclone' so we don't return the actual data. | ||||
1079 | |||||
1080 | my @tmp = $self->_all_periods($zone,$year); | ||||
1081 | my @ret; | ||||
1082 | foreach my $ele (@tmp) { | ||||
1083 | push(@ret, | ||||
1084 | [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4], | ||||
1085 | $$ele[5], [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9], | ||||
1086 | $$ele[10],$$ele[11] ]); | ||||
1087 | } | ||||
1088 | return @ret; | ||||
1089 | } | ||||
1090 | |||||
1091 | sub _all_periods { | ||||
1092 | 112286 | 16.1ms | my($self,$zone,$year) = @_; | ||
1093 | 112286 | 8.45ms | $year += 0; | ||
1094 | |||||
1095 | 112286 | 41.2ms | if (! exists $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year}) { | ||
1096 | |||||
1097 | # | ||||
1098 | # $ym1 is the year prior to $year which contains a rule (which will | ||||
1099 | # end in $year or later). $y is $year IF the zone contains rules | ||||
1100 | # for this year. | ||||
1101 | # | ||||
1102 | |||||
1103 | 1680 | 127µs | my($ym1,$ym0); | ||
1104 | 1680 | 2.00ms | if ($year > $$self{'data'}{'LastYear'} && | ||
1105 | exists $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}) { | ||||
1106 | $ym1 = $year-1; | ||||
1107 | $ym0 = $year; | ||||
1108 | |||||
1109 | } else { | ||||
1110 | 1680 | 25.7ms | 1680 | 13.3ms | foreach my $y (sort { $a <=> $b } # spent 13.3ms making 1680 calls to Date::Manip::TZ::CORE:sort, avg 8µs/call |
1111 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
1112 | 52547 | 4.26ms | if ($y < $year) { | ||
1113 | 51599 | 3.64ms | $ym1 = $y; | ||
1114 | 51599 | 3.40ms | next; | ||
1115 | } | ||||
1116 | 948 | 156µs | $ym0 = $year if ($year == $y); | ||
1117 | 948 | 189µs | last; | ||
1118 | } | ||||
1119 | } | ||||
1120 | 1680 | 134µs | $ym1 = 0 if (! $ym1); | ||
1121 | |||||
1122 | # | ||||
1123 | # Get the periods from the prior year. The last one is used (any others | ||||
1124 | # are discarded). | ||||
1125 | # | ||||
1126 | |||||
1127 | 1680 | 134µs | my(@periods); | ||
1128 | |||||
1129 | # $ym1 will be 0 in 0001 | ||||
1130 | 1680 | 335µs | if ($ym1) { | ||
1131 | 1680 | 1.24ms | 1680 | 13.6ms | my @tmp = $self->_periods($zone,$ym1); # spent 13.6ms making 1680 calls to Date::Manip::TZ::_periods, avg 8µs/call |
1132 | 1680 | 1.00ms | push(@periods,pop(@tmp)) if (@tmp); | ||
1133 | } | ||||
1134 | |||||
1135 | # | ||||
1136 | # Add on any periods from the current year. | ||||
1137 | # | ||||
1138 | |||||
1139 | 1680 | 585µs | 920 | 7.05ms | if ($ym0) { # spent 7.05ms making 920 calls to Date::Manip::TZ::_periods, avg 8µs/call |
1140 | push(@periods,$self->_periods($zone,$year)); | ||||
1141 | } | ||||
1142 | |||||
1143 | 1680 | 1.22ms | $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} = [ @periods ]; | ||
1144 | } | ||||
1145 | |||||
1146 | 112286 | 123ms | return @{ $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} }; | ||
1147 | } | ||||
1148 | |||||
1149 | sub periods { | ||||
1150 | my($self,$zone,$year,$year1) = @_; | ||||
1151 | |||||
1152 | my $z = $self->_zone($zone); | ||||
1153 | if (! $z) { | ||||
1154 | warn "ERROR: [periods] Invalid zone: $zone\n"; | ||||
1155 | return; | ||||
1156 | } | ||||
1157 | $zone = $z; | ||||
1158 | $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||||
1159 | |||||
1160 | if (! defined($year1)) { | ||||
1161 | return $self->_periods($zone,$year); | ||||
1162 | } | ||||
1163 | |||||
1164 | $year = 1 if (! defined($year)); | ||||
1165 | |||||
1166 | my @ret; | ||||
1167 | my $lastyear = $$self{'data'}{'LastYear'}; | ||||
1168 | |||||
1169 | if ($year <= $lastyear) { | ||||
1170 | foreach my $y (sort { $a <=> $b } | ||||
1171 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
1172 | last if ($y > $year1 || $y > $lastyear); | ||||
1173 | next if ($y < $year); | ||||
1174 | push(@ret,$self->_periods($zone,$y)); | ||||
1175 | } | ||||
1176 | } | ||||
1177 | |||||
1178 | if ($year1 > $lastyear) { | ||||
1179 | $year = $lastyear + 1 if ($year <= $lastyear); | ||||
1180 | foreach my $y ($year..$year1) { | ||||
1181 | push(@ret,$self->_periods($zone,$y)); | ||||
1182 | } | ||||
1183 | } | ||||
1184 | |||||
1185 | return @ret; | ||||
1186 | } | ||||
1187 | |||||
1188 | sub _periods { | ||||
1189 | 2600 | 487µs | my($self,$zone,$year) = @_; | ||
1190 | 2600 | 263µs | $year += 0; | ||
1191 | |||||
1192 | 2600 | 1.13ms | if (! exists $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year}) { | ||
1193 | |||||
1194 | my @periods = (); | ||||
1195 | if ($year > $$self{'data'}{'LastYear'}) { | ||||
1196 | # Calculate periods using the LastRule method | ||||
1197 | @periods = $self->_lastrule($zone,$year); | ||||
1198 | } | ||||
1199 | |||||
1200 | $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} = [ @periods ]; | ||||
1201 | } | ||||
1202 | |||||
1203 | # A faster 'dclone' so we don't return the actual data | ||||
1204 | 2600 | 155µs | my @ret; | ||
1205 | 2600 | 2.05ms | foreach my $ele (@{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} }) { | ||
1206 | push(@ret, | ||||
1207 | [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4],$$ele[5], | ||||
1208 | 4620 | 15.4ms | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
1209 | } | ||||
1210 | 2600 | 2.85ms | return @ret; | ||
1211 | } | ||||
1212 | |||||
1213 | # spent 88.3ms (53.0+35.3) within Date::Manip::TZ::date_period which was called 4859 times, avg 18µs/call:
# 2430 times (28.4ms+20.0ms) by Date::Manip::Date::__parse_check at line 1043 of Date/Manip/Date.pm, avg 20µs/call
# 2428 times (24.6ms+15.2ms) by Date::Manip::Date::set at line 2705 of Date/Manip/Date.pm, avg 16µs/call
# once (28µs+15µs) by Date::Manip::TZ_Base::_update_now at line 392 of Date/Manip/TZ_Base.pm | ||||
1214 | 4859 | 1.19ms | my($self,$date,$zone,$wallclock,$isdst) = @_; | ||
1215 | 4859 | 543µs | $wallclock = 0 if (! $wallclock); | ||
1216 | 4859 | 628µs | $isdst = 0 if (! $isdst); | ||
1217 | |||||
1218 | 4859 | 2.77ms | 4859 | 7.24ms | my $z = $self->_zone($zone); # spent 7.24ms making 4859 calls to Date::Manip::TZ::_zone, avg 1µs/call |
1219 | 4859 | 399µs | if (! $z) { | ||
1220 | warn "ERROR: [date_period] Invalid zone: $zone\n"; | ||||
1221 | return; | ||||
1222 | } | ||||
1223 | 4859 | 542µs | $zone = $z; | ||
1224 | 4859 | 1.94ms | $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||
1225 | |||||
1226 | 4859 | 703µs | my $dmb = $$self{'base'}; | ||
1227 | 4859 | 3.43ms | my @date = @$date; | ||
1228 | 4859 | 689µs | my $year = $date[0]; | ||
1229 | 4859 | 3.62ms | 4859 | 21.1ms | my $dates= $dmb->_date_fields(@$date); # spent 21.1ms making 4859 calls to Date::Manip::Base::_date_fields, avg 4µs/call |
1230 | |||||
1231 | 4859 | 601µs | if ($wallclock) { | ||
1232 | # A wallclock date | ||||
1233 | |||||
1234 | 4859 | 3.47ms | 4859 | 6.95ms | my @period = $self->_all_periods($zone,$year); # spent 6.95ms making 4859 calls to Date::Manip::TZ::_all_periods, avg 1µs/call |
1235 | 4859 | 1.27ms | my $beg = $period[0]->[9]; | ||
1236 | 4859 | 906µs | my $end = $period[-1]->[11]; | ||
1237 | 4859 | 1.80ms | if (($dates cmp $beg) == -1) { | ||
1238 | @period = $self->_all_periods($zone,$year-1); | ||||
1239 | } elsif (($dates cmp $end) == 1) { | ||||
1240 | @period = $self->_all_periods($zone,$year+1); | ||||
1241 | } | ||||
1242 | |||||
1243 | 4859 | 374µs | my(@per); | ||
1244 | 4859 | 1.57ms | foreach my $period (@period) { | ||
1245 | 10663 | 4.24ms | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||
1246 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
1247 | 10663 | 6.00ms | if (($dates cmp $begLTs) != -1 && ($dates cmp $endLTs) != 1) { | ||
1248 | push(@per,$period); | ||||
1249 | } | ||||
1250 | } | ||||
1251 | |||||
1252 | 4859 | 9.46ms | if ($#per == -1) { | ||
1253 | return (); | ||||
1254 | } elsif ($#per == 0) { | ||||
1255 | return $per[0]; | ||||
1256 | } elsif ($#per == 1) { | ||||
1257 | if ($per[0][5] == $isdst) { | ||||
1258 | return $per[0]; | ||||
1259 | } else { | ||||
1260 | return $per[1]; | ||||
1261 | } | ||||
1262 | } else { | ||||
1263 | warn "ERROR: [date_period] Impossible error\n"; | ||||
1264 | return; | ||||
1265 | } | ||||
1266 | |||||
1267 | } else { | ||||
1268 | # A GMT date | ||||
1269 | |||||
1270 | my @period = $self->_all_periods($zone,$year); | ||||
1271 | foreach my $period (@period) { | ||||
1272 | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$isdst,$endUT,$endLT, | ||||
1273 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
1274 | if (($dates cmp $begUTs) != -1 && ($dates cmp $endUTs) != 1) { | ||||
1275 | return $period; | ||||
1276 | } | ||||
1277 | } | ||||
1278 | warn "ERROR: [date_period] Impossible error\n"; | ||||
1279 | return; | ||||
1280 | } | ||||
1281 | } | ||||
1282 | |||||
1283 | # Calculate critical dates from the last rule. If $endonly is passed | ||||
1284 | # in, it only calculates the ending of the zone period before the | ||||
1285 | # start of the first one. This is necessary so that the last period in | ||||
1286 | # one year can find out when it ends (which is determined in the | ||||
1287 | # following year). | ||||
1288 | # | ||||
1289 | # Returns: | ||||
1290 | # [begUT, begLT, offsetstr, offset, abb, ISDST, endUT, endLT, | ||||
1291 | # begUTstr, begLTstr, endUTstr, endLTstr] | ||||
1292 | # for each. | ||||
1293 | # | ||||
1294 | sub _lastrule { | ||||
1295 | my($self,$zone,$year,$endonly) = @_; | ||||
1296 | |||||
1297 | # | ||||
1298 | # Get the list of rules (actually, the month in which the | ||||
1299 | # rule triggers a time change). If there are none, then | ||||
1300 | # this zone doesn't have a LAST RULE. | ||||
1301 | # | ||||
1302 | |||||
1303 | my @mon = (sort keys | ||||
1304 | %{ $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'} }); | ||||
1305 | return () if (! @mon); | ||||
1306 | |||||
1307 | # | ||||
1308 | # Analyze each time change. | ||||
1309 | # | ||||
1310 | |||||
1311 | my @dates = (); | ||||
1312 | my $dmb = $$self{'base'}; | ||||
1313 | |||||
1314 | my $stdoff = $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}{'stdoff'}; | ||||
1315 | my $dstoff = $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}{'dstoff'}; | ||||
1316 | |||||
1317 | my (@period); | ||||
1318 | |||||
1319 | foreach my $mon (@mon) { | ||||
1320 | my $flag = | ||||
1321 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'flag'}; | ||||
1322 | my $dow = | ||||
1323 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'dow'}; | ||||
1324 | my $num = | ||||
1325 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'num'}; | ||||
1326 | my $isdst= | ||||
1327 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'isdst'}; | ||||
1328 | my $time = | ||||
1329 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'time'}; | ||||
1330 | my $type = | ||||
1331 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'type'}; | ||||
1332 | my $abb = | ||||
1333 | $$self{'data'}{'Zones'}{$zone}{'LastRule'}{'rules'}{$mon}{'abb'}; | ||||
1334 | |||||
1335 | # The end of the current period and the beginning of the next | ||||
1336 | my($endUT,$endLT,$begUT,$begLT) = | ||||
1337 | $dmb->_critical_date($year,$mon,$flag,$num,$dow, | ||||
1338 | $isdst,$time,$type,$stdoff,$dstoff); | ||||
1339 | return ($endUT,$endLT) if ($endonly); | ||||
1340 | |||||
1341 | if (@period) { | ||||
1342 | push(@period,$endUT,$endLT); | ||||
1343 | push(@dates,[@period]); | ||||
1344 | } | ||||
1345 | my $offsetstr = ($isdst ? $dstoff : $stdoff); | ||||
1346 | my $offset = $dmb->split('offset',$offsetstr); | ||||
1347 | |||||
1348 | @period = ($begUT,$begLT,$offsetstr,$offset,$abb,$isdst); | ||||
1349 | } | ||||
1350 | |||||
1351 | push(@period,$self->_lastrule($zone,$year+1,1)); | ||||
1352 | push(@dates,[@period]); | ||||
1353 | |||||
1354 | foreach my $period (@dates) { | ||||
1355 | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT) = @$period; | ||||
1356 | my $begUTstr = $dmb->join("date",$begUT); | ||||
1357 | my $begLTstr = $dmb->join("date",$begLT); | ||||
1358 | my $endUTstr = $dmb->join("date",$endUT); | ||||
1359 | my $endLTstr = $dmb->join("date",$endLT); | ||||
1360 | $period = [$begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||||
1361 | $begUTstr,$begLTstr,$endUTstr,$endLTstr]; | ||||
1362 | } | ||||
1363 | |||||
1364 | return @dates; | ||||
1365 | } | ||||
1366 | |||||
1367 | ######################################################################## | ||||
1368 | # CONVERSION | ||||
1369 | ######################################################################## | ||||
1370 | |||||
1371 | sub convert { | ||||
1372 | my($self,$date,$from,$to,$isdst) = @_; | ||||
1373 | $self->_convert('convert',$date,$from,$to,$isdst); | ||||
1374 | } | ||||
1375 | |||||
1376 | sub convert_to_gmt { | ||||
1377 | my($self,$date,@arg) = @_; | ||||
1378 | my($err,$from,$isdst) = _convert_args('convert_to_gmt',@arg); | ||||
1379 | return (1) if ($err); | ||||
1380 | |||||
1381 | my $dmb = $$self{'base'}; | ||||
1382 | |||||
1383 | if (! $from) { | ||||
1384 | $from = $self->_now('tz',1); | ||||
1385 | } | ||||
1386 | $self->_convert('convert_to_gmt',$date,$from,'GMT',$isdst); | ||||
1387 | } | ||||
1388 | |||||
1389 | sub convert_from_gmt { | ||||
1390 | my($self,$date,@arg) = @_; | ||||
1391 | my($err,$to,$isdst) = _convert_args('convert_from_gmt',@arg); | ||||
1392 | return (1) if ($err); | ||||
1393 | |||||
1394 | my $dmb = $$self{'base'}; | ||||
1395 | |||||
1396 | if (! $to) { | ||||
1397 | $to = $self->_now('tz',1); | ||||
1398 | } | ||||
1399 | $self->_convert('convert_from_gmt',$date,'GMT',$to,$isdst); | ||||
1400 | } | ||||
1401 | |||||
1402 | sub convert_to_local { | ||||
1403 | my($self,$date,@arg) = @_; | ||||
1404 | my($err,$from,$isdst) = _convert_args('convert_to_local',@arg); | ||||
1405 | return (1) if ($err); | ||||
1406 | |||||
1407 | my $dmb = $$self{'base'}; | ||||
1408 | |||||
1409 | if (! $from) { | ||||
1410 | $from = 'GMT'; | ||||
1411 | } | ||||
1412 | $self->_convert('convert_to_local',$date,$from,$self->_now('tz',1),$isdst); | ||||
1413 | } | ||||
1414 | |||||
1415 | sub convert_from_local { | ||||
1416 | my($self,$date,@arg) = @_; | ||||
1417 | my($err,$to,$isdst) = _convert_args('convert_from_local',@arg); | ||||
1418 | return (1) if ($err); | ||||
1419 | |||||
1420 | my $dmb = $$self{'base'}; | ||||
1421 | |||||
1422 | if (! $to) { | ||||
1423 | $to = 'GMT'; | ||||
1424 | } | ||||
1425 | $self->_convert('convert_from_local',$date,$self->_now('tz',1),$to,$isdst); | ||||
1426 | } | ||||
1427 | |||||
1428 | sub _convert_args { | ||||
1429 | my($caller,@args) = @_; | ||||
1430 | |||||
1431 | if ($#args == -1) { | ||||
1432 | return (0,'',0); | ||||
1433 | } elsif ($#args == 0) { | ||||
1434 | if ($args[0] eq '0' || | ||||
1435 | $args[0] eq '1') { | ||||
1436 | return (0,'',$args[0]); | ||||
1437 | } else { | ||||
1438 | return (0,$args[0],0); | ||||
1439 | } | ||||
1440 | } elsif ($#args == 1) { | ||||
1441 | return (0,@args); | ||||
1442 | } else { | ||||
1443 | return (1,'',0); | ||||
1444 | } | ||||
1445 | } | ||||
1446 | |||||
1447 | sub _convert { | ||||
1448 | my($self,$caller,$date,$from,$to,$isdst) = @_; | ||||
1449 | my $dmb = $$self{'base'}; | ||||
1450 | |||||
1451 | # Handle $date as a reference and a string | ||||
1452 | my (@date); | ||||
1453 | if (ref($date)) { | ||||
1454 | @date = @$date; | ||||
1455 | } else { | ||||
1456 | @date = @{ $dmb->split('date',$date) }; | ||||
1457 | $date = [@date]; | ||||
1458 | } | ||||
1459 | |||||
1460 | if ($from ne $to) { | ||||
1461 | my $tmp = $self->_zone($from); | ||||
1462 | if (! $tmp) { | ||||
1463 | return (2); | ||||
1464 | } | ||||
1465 | $from = $tmp; | ||||
1466 | |||||
1467 | $tmp = $self->_zone($to); | ||||
1468 | if (! $tmp) { | ||||
1469 | return (3); | ||||
1470 | } | ||||
1471 | $to = $tmp; | ||||
1472 | } | ||||
1473 | |||||
1474 | if ($from eq $to) { | ||||
1475 | my $per = $self->date_period($date,$from,1,$isdst); | ||||
1476 | my $offset = $$per[3]; | ||||
1477 | my $abb = $$per[4]; | ||||
1478 | return (0,$date,$offset,$isdst,$abb); | ||||
1479 | } | ||||
1480 | |||||
1481 | # Convert $date from $from to GMT | ||||
1482 | |||||
1483 | if ($from ne "Etc/GMT") { | ||||
1484 | my $per = $self->date_period($date,$from,1,$isdst); | ||||
1485 | if (! $per) { | ||||
1486 | return (4); | ||||
1487 | } | ||||
1488 | my $offset = $$per[3]; | ||||
1489 | @date = @{ $dmb->calc_date_time(\@date,$offset,1) }; | ||||
1490 | } | ||||
1491 | |||||
1492 | # Convert $date from GMT to $to | ||||
1493 | |||||
1494 | $isdst = 0; | ||||
1495 | my $offset = [0,0,0]; | ||||
1496 | my $abb = 'GMT'; | ||||
1497 | |||||
1498 | if ($to ne "Etc/GMT") { | ||||
1499 | my $per = $self->date_period([@date],$to,0); | ||||
1500 | $offset = $$per[3]; | ||||
1501 | $isdst = $$per[5]; | ||||
1502 | $abb = $$per[4]; | ||||
1503 | @date = @{ $dmb->calc_date_time(\@date,$offset) }; | ||||
1504 | } | ||||
1505 | |||||
1506 | return (0,[@date],$offset,$isdst,$abb); | ||||
1507 | } | ||||
1508 | |||||
1509 | ######################################################################## | ||||
1510 | # REGULAR EXPRESSIONS FOR TIMEZONE INFORMATION | ||||
1511 | ######################################################################## | ||||
1512 | |||||
1513 | # Returns regular expressions capable of matching timezones. | ||||
1514 | # | ||||
1515 | # The timezone regular expressions are: | ||||
1516 | # namerx : this will match a zone name or alias (America/New_York) | ||||
1517 | # abbrx : this will match a zone abbreviation (EDT) | ||||
1518 | # zonerx : this will match a zone name or an abbreviation | ||||
1519 | # offrx : this will match a pure offset (+0400) | ||||
1520 | # offabbrx : this will match an offset with an abbreviation (+0400 WET) | ||||
1521 | # offparrx : this will match an offset and abbreviation if parentheses | ||||
1522 | # ("+0400 (WET)") | ||||
1523 | # zrx : this will match all forms | ||||
1524 | # | ||||
1525 | # The regular expression will have the following named matches: | ||||
1526 | # tzstring : the full string matched | ||||
1527 | # zone : the name/alias | ||||
1528 | # abb : the zone abbrevation | ||||
1529 | # off : the offset | ||||
1530 | # | ||||
1531 | # spent 15.7ms (4.79+11.0) within Date::Manip::TZ::_zrx which was called 4 times, avg 3.94ms/call:
# once (4.78ms+11.0ms) by Date::Manip::Date::_iso8601_rx at line 1156 of Date/Manip/Date.pm
# once (2µs+0s) by Date::Manip::Date::_other_rx at line 1523 of Date/Manip/Date.pm
# once (1µs+0s) by Date::Manip::Date::_other_rx at line 1418 of Date/Manip/Date.pm
# once (700ns+0s) by Date::Manip::Date::_other_rx at line 1524 of Date/Manip/Date.pm | ||||
1532 | 4 | 1µs | my($self,$re) = @_; | ||
1533 | 4 | 7µs | return $$self{'data'}{$re} if (defined $$self{'data'}{$re}); | ||
1534 | |||||
1535 | # Zone name | ||||
1536 | |||||
1537 | 1 | 300ns | my @zone; | ||
1538 | 1 | 12µs | if (exists $ENV{'DATE_MANIP_DEBUG_ZONES'}) { | ||
1539 | @zone = split(/\s+/,$ENV{'DATE_MANIP_DEBUG_ZONES'}); | ||||
1540 | } else { | ||||
1541 | @zone = (keys %{ $$self{'data'}{'Alias'} }, | ||||
1542 | 1 | 107µs | keys %{ $$self{'data'}{'MyAlias'} }); | ||
1543 | } | ||||
1544 | 1 | 4µs | 1 | 926µs | @zone = sort _sortByLength(@zone); # spent 926µs making 1 call to Date::Manip::TZ::CORE:sort |
1545 | 1 | 1µs | foreach my $zone (@zone) { | ||
1546 | 825 | 784µs | 825 | 176µs | $zone =~ s/\057/\\057/g; # / # spent 176µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 213ns/call |
1547 | 825 | 618µs | 825 | 49µs | $zone =~ s/\055/\\055/g; # - # spent 49µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 60ns/call |
1548 | 825 | 567µs | 825 | 15µs | $zone =~ s/\056/\\056/g; # . # spent 15µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 19ns/call |
1549 | 825 | 578µs | 825 | 13µs | $zone =~ s/\050/\\050/g; # ( # spent 13µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 16ns/call |
1550 | 825 | 571µs | 825 | 18µs | $zone =~ s/\051/\\051/g; # ) # spent 18µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 22ns/call |
1551 | 825 | 719µs | 825 | 11µs | $zone =~ s/\053/\\053/g; # + # spent 11µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 13ns/call |
1552 | } | ||||
1553 | |||||
1554 | 1 | 27µs | my $zone = join('|',@zone); | ||
1555 | 1 | 1.54ms | 2 | 1.48ms | $zone = qr/(?<zone>$zone)/i; # spent 1.48ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 1µs making 1 call to Date::Manip::TZ::CORE:qr |
1556 | |||||
1557 | # Abbreviation | ||||
1558 | |||||
1559 | 1 | 200ns | my @abb; | ||
1560 | 1 | 6µs | if (exists $ENV{'DATE_MANIP_DEBUG_ABBREVS'}) { | ||
1561 | @abb = split(/\s+/,$ENV{'DATE_MANIP_DEBUG_ABBREVS'}); | ||||
1562 | } else { | ||||
1563 | @abb = (keys %{ $$self{'data'}{'Abbrev'} }, | ||||
1564 | 1 | 71µs | keys %{ $$self{'data'}{'MyAbbrev'} }); | ||
1565 | } | ||||
1566 | 1 | 2µs | 1 | 348µs | @abb = sort _sortByLength(@abb); # spent 348µs making 1 call to Date::Manip::TZ::CORE:sort |
1567 | 1 | 800ns | foreach my $abb (@abb) { | ||
1568 | 403 | 291µs | 403 | 5µs | $abb =~ s/\055/\\055/g; # - # spent 5µs making 403 calls to Date::Manip::TZ::CORE:subst, avg 13ns/call |
1569 | 403 | 348µs | 403 | 5µs | $abb =~ s/\053/\\053/g; # + # spent 5µs making 403 calls to Date::Manip::TZ::CORE:subst, avg 12ns/call |
1570 | } | ||||
1571 | |||||
1572 | 1 | 10µs | my $abb = join('|',@abb); | ||
1573 | 1 | 485µs | 2 | 459µs | $abb = qr/(?<abb>$abb)/i; # spent 458µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
1574 | |||||
1575 | # Offset (+HH, +HHMM, +HH:MM, +HH:MM:SS, +HHMMSS) | ||||
1576 | |||||
1577 | 1 | 2µs | 1 | 700ns | my($hr) = qr/(?:[0-1][0-9]|2[0-3])/; # 00 - 23 # spent 700ns making 1 call to Date::Manip::TZ::CORE:qr |
1578 | 1 | 2µs | 1 | 400ns | my($mn) = qr/(?:[0-5][0-9])/; # 00 - 59 # spent 400ns making 1 call to Date::Manip::TZ::CORE:qr |
1579 | 1 | 2µs | 1 | 500ns | my($ss) = qr/(?:[0-5][0-9])/; # 00 - 59 # spent 500ns making 1 call to Date::Manip::TZ::CORE:qr |
1580 | |||||
1581 | 1 | 39µs | 2 | 35µs | my($off) = qr/ (?<off> [+-] (?: $hr:$mn:$ss | # spent 35µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 400ns making 1 call to Date::Manip::TZ::CORE:qr |
1582 | $hr$mn$ss | | ||||
1583 | $hr:?$mn | | ||||
1584 | $hr | ||||
1585 | ) | ||||
1586 | ) /ix; | ||||
1587 | |||||
1588 | # Assemble everything | ||||
1589 | # | ||||
1590 | # A timezone can be any of the following in this order: | ||||
1591 | # Offset (ABB) | ||||
1592 | # Offset ABB | ||||
1593 | # ABB | ||||
1594 | # Zone | ||||
1595 | # Offset | ||||
1596 | # We put ABB before Zone so CET gets parse as the more common abbreviation | ||||
1597 | # than the less common zone name. | ||||
1598 | |||||
1599 | 1 | 1.44ms | 2 | 1.39ms | $$self{'data'}{'namerx'} = qr/(?<tzstring>$zone)/; # spent 1.39ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
1600 | 1 | 503µs | 2 | 476µs | $$self{'data'}{'abbrx'} = qr/(?<tzstring>$abb)/; # spent 474µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 2µs making 1 call to Date::Manip::TZ::CORE:qr |
1601 | 1 | 1.98ms | 2 | 1.90ms | $$self{'data'}{'zonerx'} = qr/(?<tzstring>(?:$abb|$zone))/; # spent 1.90ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
1602 | 1 | 61µs | 2 | 56µs | $$self{'data'}{'offrx'} = qr/(?<tzstring>$off)/; # spent 56µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 600ns making 1 call to Date::Manip::TZ::CORE:qr |
1603 | 1 | 417µs | 2 | 412µs | $$self{'data'}{'offabbrx'} = qr/(?<tzstring>$off\s+$abb)/; # spent 411µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 1µs making 1 call to Date::Manip::TZ::CORE:qr |
1604 | 1 | 394µs | 2 | 389µs | $$self{'data'}{'offparrx'} = qr/(?<tzstring>$off\s*\($abb\))/; # spent 388µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
1605 | 1 | 2.87ms | 2 | 2.79ms | $$self{'data'}{'zrx'} = qr/(?<tzstring>(?:$off\s*\($abb\)|$off\s+$abb|$abb|$zone|$off))/; # spent 2.79ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
1606 | |||||
1607 | 1 | 29µs | return $$self{'data'}{$re}; | ||
1608 | } | ||||
1609 | |||||
1610 | # This sorts from longest to shortest element | ||||
1611 | # | ||||
1612 | 2 | 32µs | 2 | 22µs | # spent 14µs (6+8) within Date::Manip::TZ::BEGIN@1612 which was called:
# once (6µs+8µs) by Date::Manip::Date::BEGIN@27 at line 1612 # spent 14µs making 1 call to Date::Manip::TZ::BEGIN@1612
# spent 8µs making 1 call to strict::unimport |
1613 | sub _sortByLength { | ||||
1614 | 8992 | 1.27ms | return (length $b <=> length $a); | ||
1615 | } | ||||
1616 | 2 | 498µs | 2 | 14µs | # spent 9µs (4+5) within Date::Manip::TZ::BEGIN@1616 which was called:
# once (4µs+5µs) by Date::Manip::Date::BEGIN@27 at line 1616 # spent 9µs making 1 call to Date::Manip::TZ::BEGIN@1616
# spent 5µs making 1 call to strict::import |
1617 | |||||
1618 | ######################################################################## | ||||
1619 | # CONFIG VARS | ||||
1620 | ######################################################################## | ||||
1621 | |||||
1622 | # This sets a config variable. It also performs all side effects from | ||||
1623 | # setting that variable. | ||||
1624 | # | ||||
1625 | sub _config_var_tz { | ||||
1626 | my($self,$var,$val) = @_; | ||||
1627 | |||||
1628 | if ($var eq 'tz') { | ||||
1629 | my $err = $self->_config_var_setdate("now,$val",0); | ||||
1630 | return if ($err); | ||||
1631 | $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0; | ||||
1632 | $val = 1; | ||||
1633 | |||||
1634 | } elsif ($var eq 'setdate') { | ||||
1635 | my $err = $self->_config_var_setdate($val,0); | ||||
1636 | return if ($err); | ||||
1637 | $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0; | ||||
1638 | $val = 1; | ||||
1639 | |||||
1640 | } elsif ($var eq 'forcedate') { | ||||
1641 | my $err = $self->_config_var_setdate($val,1); | ||||
1642 | return if ($err); | ||||
1643 | $$self{'data'}{'sections'}{'conf'}{'setdate'} = 0; | ||||
1644 | $val = 1; | ||||
1645 | |||||
1646 | } elsif ($var eq 'configfile') { | ||||
1647 | $self->_config_file($val); | ||||
1648 | return; | ||||
1649 | } | ||||
1650 | |||||
1651 | my $base = $$self{'base'}; | ||||
1652 | $$base{'data'}{'sections'}{'conf'}{$var} = $val; | ||||
1653 | return; | ||||
1654 | } | ||||
1655 | |||||
1656 | sub _config_var_setdate { | ||||
1657 | my($self,$val,$force) = @_; | ||||
1658 | my $base = $$self{'base'}; | ||||
1659 | |||||
1660 | my $dstrx = qr/(?:,\s*(stdonly|dstonly|std|dst))?/i; | ||||
1661 | my $zonrx = qr/,\s*(.+)/; | ||||
1662 | my $da1rx = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d):(\d\d):(\d\d)/; | ||||
1663 | my $da2rx = qr/(\d\d\d\d)\-(\d\d)\-(\d\d)\-(\d\d):(\d\d):(\d\d)/; | ||||
1664 | my $time = time; | ||||
1665 | |||||
1666 | my($op,$date,$dstflag,$zone,@date,$offset,$abb); | ||||
1667 | |||||
1668 | # | ||||
1669 | # Parse the argument | ||||
1670 | # | ||||
1671 | |||||
1672 | if ($val =~ /^now${dstrx}${zonrx}$/oi) { | ||||
1673 | # now,ZONE | ||||
1674 | # now,DSTFLAG,ZONE | ||||
1675 | # Sets now to the system date/time but sets the timezone to be ZONE | ||||
1676 | |||||
1677 | $op = 'nowzone'; | ||||
1678 | ($dstflag,$zone) = ($1,$2); | ||||
1679 | |||||
1680 | } elsif ($val =~ /^zone${dstrx}${zonrx}$/oi) { | ||||
1681 | # zone,ZONE | ||||
1682 | # zone,DSTFLAG,ZONE | ||||
1683 | # Converts 'now' to the alternate zone | ||||
1684 | |||||
1685 | $op = 'zone'; | ||||
1686 | ($dstflag,$zone) = ($1,$2); | ||||
1687 | |||||
1688 | } elsif ($val =~ /^${da1rx}${dstrx}${zonrx}$/o || | ||||
1689 | $val =~ /^${da2rx}${dstrx}${zonrx}$/o) { | ||||
1690 | # DATE,ZONE | ||||
1691 | # DATE,DSTFLAG,ZONE | ||||
1692 | # Sets the date and zone | ||||
1693 | |||||
1694 | $op = 'datezone'; | ||||
1695 | my($y,$m,$d,$h,$mn,$s); | ||||
1696 | ($y,$m,$d,$h,$mn,$s,$dstflag,$zone) = ($1,$2,$3,$4,$5,$6,$7,$8); | ||||
1697 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1698 | |||||
1699 | } elsif ($val =~ /^${da1rx}$/o || | ||||
1700 | $val =~ /^${da2rx}$/o) { | ||||
1701 | # DATE | ||||
1702 | # Sets the date in the system timezone | ||||
1703 | |||||
1704 | $op = 'date'; | ||||
1705 | my($y,$m,$d,$h,$mn,$s) = ($1,$2,$3,$4,$5,$6); | ||||
1706 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1707 | $zone = $self->_now('systz',1); | ||||
1708 | |||||
1709 | } elsif (lc($val) eq 'now') { | ||||
1710 | # now | ||||
1711 | # Resets everything | ||||
1712 | |||||
1713 | my $systz = $$base{'data'}{'now'}{'systz'}; | ||||
1714 | $base->_init_now(); | ||||
1715 | $$base{'data'}{'now'}{'systz'} = $systz; | ||||
1716 | return 0; | ||||
1717 | |||||
1718 | } else { | ||||
1719 | warn "ERROR: [config_var] invalid SetDate/ForceDate value: $val\n"; | ||||
1720 | return 1; | ||||
1721 | } | ||||
1722 | |||||
1723 | $dstflag = 'std' if (! $dstflag); | ||||
1724 | |||||
1725 | # | ||||
1726 | # Get the date we're setting 'now' to | ||||
1727 | # | ||||
1728 | |||||
1729 | if ($op eq 'nowzone') { | ||||
1730 | # Use the system localtime | ||||
1731 | |||||
1732 | my($s,$mn,$h,$d,$m,$y) = localtime($time); | ||||
1733 | $y += 1900; | ||||
1734 | $m++; | ||||
1735 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1736 | |||||
1737 | } elsif ($op eq 'zone') { | ||||
1738 | # Use the system GMT time | ||||
1739 | |||||
1740 | my($s,$mn,$h,$d,$m,$y) = gmtime($time); | ||||
1741 | $y += 1900; | ||||
1742 | $m++; | ||||
1743 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
1744 | } | ||||
1745 | |||||
1746 | # | ||||
1747 | # Find out what zone was passed in. It can be an alias or an offset. | ||||
1748 | # | ||||
1749 | |||||
1750 | if ($zone) { | ||||
1751 | my ($err,@args); | ||||
1752 | my $dmb = $$self{'base'}; | ||||
1753 | $date = [] if (! defined $date); | ||||
1754 | $zone = $self->__zone($date,'',lc($zone),'',lc($dstflag)); | ||||
1755 | if (! $zone) { | ||||
1756 | warn "ERROR: [config_var] invalid zone in SetDate: @args\n"; | ||||
1757 | return 1; | ||||
1758 | } | ||||
1759 | |||||
1760 | } else { | ||||
1761 | $zone = $$base{'data'}{'now'}{'systz'}; | ||||
1762 | } | ||||
1763 | |||||
1764 | # | ||||
1765 | # Handle the zone | ||||
1766 | # | ||||
1767 | |||||
1768 | my($isdst,@isdst); | ||||
1769 | if ($dstflag eq 'std') { | ||||
1770 | @isdst = (0,1); | ||||
1771 | } elsif ($dstflag eq 'stdonly') { | ||||
1772 | @isdst = (0); | ||||
1773 | } elsif ($dstflag eq 'dst') { | ||||
1774 | @isdst = (1,0); | ||||
1775 | } else { | ||||
1776 | @isdst = (1); | ||||
1777 | } | ||||
1778 | |||||
1779 | if ($op eq 'nowzone' || | ||||
1780 | $op eq 'datezone' || | ||||
1781 | $op eq 'date') { | ||||
1782 | |||||
1783 | # Check to make sure that the date can exist in this zone. | ||||
1784 | my $per; | ||||
1785 | foreach my $dst (@isdst) { | ||||
1786 | next if ($per); | ||||
1787 | $per = $self->date_period($date,$zone,1,$dst); | ||||
1788 | } | ||||
1789 | |||||
1790 | if (! $per) { | ||||
1791 | warn "ERROR: [config_var] invalid date: SetDate: $date, $zone\n"; | ||||
1792 | return 1; | ||||
1793 | } | ||||
1794 | $isdst = $$per[5]; | ||||
1795 | $abb = $$per[4]; | ||||
1796 | $offset = $$per[3]; | ||||
1797 | |||||
1798 | } elsif ($op eq 'zone') { | ||||
1799 | |||||
1800 | # Convert to that zone | ||||
1801 | my($err); | ||||
1802 | ($err,$date,$offset,$isdst,$abb) = $self->convert_from_gmt($date,$zone); | ||||
1803 | if ($err) { | ||||
1804 | warn "ERROR: [config_var] invalid SetDate date/offset values: $date, $zone\n"; | ||||
1805 | return 1; | ||||
1806 | } | ||||
1807 | } | ||||
1808 | |||||
1809 | # | ||||
1810 | # Set NOW | ||||
1811 | # | ||||
1812 | |||||
1813 | $$base{'data'}{'now'}{'date'} = $date; | ||||
1814 | $$base{'data'}{'now'}{'tz'} = $self->_zone($zone); | ||||
1815 | $$base{'data'}{'now'}{'isdst'} = $isdst; | ||||
1816 | $$base{'data'}{'now'}{'abb'} = $abb; | ||||
1817 | $$base{'data'}{'now'}{'offset'} = $offset; | ||||
1818 | |||||
1819 | # | ||||
1820 | # Treate SetDate/ForceDate | ||||
1821 | # | ||||
1822 | |||||
1823 | if ($force) { | ||||
1824 | $$base{'data'}{'now'}{'force'} = 1; | ||||
1825 | $$base{'data'}{'now'}{'set'} = 0; | ||||
1826 | } else { | ||||
1827 | $$base{'data'}{'now'}{'force'} = 0; | ||||
1828 | $$base{'data'}{'now'}{'set'} = 1; | ||||
1829 | $$base{'data'}{'now'}{'setsecs'} = $time; | ||||
1830 | my($err,$setdate) = $self->convert_to_gmt($date,$zone); | ||||
1831 | $$base{'data'}{'now'}{'setdate'} = $setdate; | ||||
1832 | } | ||||
1833 | |||||
1834 | return 0; | ||||
1835 | } | ||||
1836 | |||||
1837 | 1 | 2µs | 1; | ||
1838 | # Local Variables: | ||||
1839 | # mode: cperl | ||||
1840 | # indent-tabs-mode: nil | ||||
1841 | # cperl-indent-level: 3 | ||||
1842 | # cperl-continued-statement-offset: 2 | ||||
1843 | # cperl-continued-brace-offset: 0 | ||||
1844 | # cperl-brace-offset: 0 | ||||
1845 | # cperl-brace-imaginary-offset: 0 | ||||
1846 | # cperl-label-offset: 0 | ||||
1847 | # End: | ||||
# spent 500ns within Date::Manip::TZ::CORE:close which was called:
# once (500ns+0s) by Date::Manip::TZ::_get_curr_zone at line 535 | |||||
# spent 3µs within Date::Manip::TZ::CORE:ftfile which was called 3 times, avg 1µs/call:
# 3 times (3µs+0s) by Date::Manip::TZ::_get_curr_zone at line 468, avg 1µs/call | |||||
# spent 24µs within Date::Manip::TZ::CORE:match which was called 91 times, avg 263ns/call:
# 83 times (19µs+0s) by Date::Manip::TZ::_get_curr_zone at line 477, avg 234ns/call
# 7 times (3µs+0s) by Date::Manip::TZ::_get_curr_zone at line 503, avg 443ns/call
# once (1µs+0s) by Date::Manip::TZ::_get_curr_zone at line 508 | |||||
# spent 11µs within Date::Manip::TZ::CORE:qr which was called 13 times, avg 831ns/call:
# once (2µs+0s) by Date::Manip::TZ::_zrx at line 1600
# once (1µs+0s) by Date::Manip::TZ::_zrx at line 1555
# once (1µs+0s) by Date::Manip::TZ::_zrx at line 1603
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1604
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1601
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1573
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1605
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1599
# once (700ns+0s) by Date::Manip::TZ::_zrx at line 1577
# once (600ns+0s) by Date::Manip::TZ::_zrx at line 1602
# once (500ns+0s) by Date::Manip::TZ::_zrx at line 1579
# once (400ns+0s) by Date::Manip::TZ::_zrx at line 1581
# once (400ns+0s) by Date::Manip::TZ::_zrx at line 1578 | |||||
# spent 9µs within Date::Manip::TZ::CORE:readline which was called 74 times, avg 126ns/call:
# 74 times (9µs+0s) by Date::Manip::TZ::_get_curr_zone at line 476, avg 126ns/call | |||||
# spent 9.38ms within Date::Manip::TZ::CORE:regcomp which was called 10 times, avg 938µs/call:
# once (2.79ms+0s) by Date::Manip::TZ::_zrx at line 1605
# once (1.90ms+0s) by Date::Manip::TZ::_zrx at line 1601
# once (1.48ms+0s) by Date::Manip::TZ::_zrx at line 1555
# once (1.39ms+0s) by Date::Manip::TZ::_zrx at line 1599
# once (474µs+0s) by Date::Manip::TZ::_zrx at line 1600
# once (458µs+0s) by Date::Manip::TZ::_zrx at line 1573
# once (411µs+0s) by Date::Manip::TZ::_zrx at line 1603
# once (388µs+0s) by Date::Manip::TZ::_zrx at line 1604
# once (56µs+0s) by Date::Manip::TZ::_zrx at line 1602
# once (35µs+0s) by Date::Manip::TZ::_zrx at line 1581 | |||||
# spent 17.4ms within Date::Manip::TZ::CORE:sort which was called 1984 times, avg 9µs/call:
# 1680 times (13.3ms+0s) by Date::Manip::TZ::_all_periods at line 1110, avg 8µs/call
# 302 times (2.83ms+0s) by Date::Manip::TZ::_check_abbrev_isdst at line 994, avg 9µs/call
# once (926µs+0s) by Date::Manip::TZ::_zrx at line 1544
# once (348µs+0s) by Date::Manip::TZ::_zrx at line 1566 | |||||
# spent 297µs within Date::Manip::TZ::CORE:subst which was called 5762 times, avg 52ns/call:
# 825 times (176µs+0s) by Date::Manip::TZ::_zrx at line 1546, avg 213ns/call
# 825 times (49µs+0s) by Date::Manip::TZ::_zrx at line 1547, avg 60ns/call
# 825 times (18µs+0s) by Date::Manip::TZ::_zrx at line 1550, avg 22ns/call
# 825 times (15µs+0s) by Date::Manip::TZ::_zrx at line 1548, avg 19ns/call
# 825 times (13µs+0s) by Date::Manip::TZ::_zrx at line 1549, avg 16ns/call
# 825 times (11µs+0s) by Date::Manip::TZ::_zrx at line 1551, avg 13ns/call
# 403 times (5µs+0s) by Date::Manip::TZ::_zrx at line 1568, avg 13ns/call
# 403 times (5µs+0s) by Date::Manip::TZ::_zrx at line 1569, avg 12ns/call
# once (1µs+0s) by Date::Manip::TZ::_get_curr_zone at line 529
# once (900ns+0s) by Date::Manip::TZ::_get_curr_zone at line 528
# once (900ns+0s) by Date::Manip::TZ::_get_curr_zone at line 530
# once (400ns+0s) by Date::Manip::TZ::_get_curr_zone at line 632
# once (300ns+0s) by Date::Manip::TZ::_get_curr_zone at line 531
# once (300ns+0s) by Date::Manip::TZ::_get_curr_zone at line 511 |