| Filename | /home/sulbeck/local/lib/perl5/5.20.1/Date/Manip/TZ.pm |
| Statements | Executed 119371 statements in 84.4ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2431 | 2 | 2 | 31.7ms | 73.3ms | Date::Manip::TZ::date_period |
| 2431 | 1 | 1 | 21.9ms | 22.2ms | Date::Manip::TZ::_all_periods |
| 10 | 10 | 1 | 9.50ms | 9.50ms | Date::Manip::TZ::CORE:regcomp (opcode) |
| 4863 | 4 | 2 | 6.84ms | 6.84ms | Date::Manip::TZ::_zone |
| 2431 | 1 | 1 | 6.31ms | 6.34ms | Date::Manip::TZ::_module |
| 10 | 5 | 1 | 4.68ms | 15.7ms | Date::Manip::TZ::_zrx |
| 9 | 3 | 1 | 1.40ms | 1.40ms | Date::Manip::TZ::CORE:sort (opcode) |
| 1 | 1 | 1 | 287µs | 453µs | Date::Manip::TZ::_get_curr_zone |
| 5762 | 14 | 1 | 233µs | 233µs | Date::Manip::TZ::CORE:subst (opcode) |
| 14 | 2 | 1 | 125µs | 125µs | Date::Manip::TZ::_periods |
| 1 | 1 | 1 | 24µs | 31µs | Date::Manip::TZ::_init |
| 91 | 3 | 1 | 23µs | 23µs | Date::Manip::TZ::CORE:match (opcode) |
| 13 | 13 | 1 | 10µs | 10µs | Date::Manip::TZ::CORE:qr (opcode) |
| 74 | 1 | 1 | 10µs | 10µs | Date::Manip::TZ::CORE:readline (opcode) |
| 1 | 1 | 1 | 8µs | 15µs | Date::Manip::TZ::BEGIN@721 |
| 1 | 1 | 1 | 7µs | 14µs | Date::Manip::TZ::BEGIN@1582 |
| 1 | 1 | 1 | 7µs | 461µs | Date::Manip::TZ::_set_curr_zone |
| 2 | 1 | 1 | 6µs | 6µs | Date::Manip::TZ::END |
| 1 | 1 | 1 | 5µs | 5µs | Date::Manip::TZ::BEGIN@14 |
| 1 | 1 | 1 | 5µs | 8µs | Date::Manip::TZ::BEGIN@731 |
| 1 | 1 | 1 | 4µs | 88µs | Date::Manip::TZ::BEGIN@22 |
| 1 | 1 | 1 | 4µs | 11µs | Date::Manip::TZ::BEGIN@158 |
| 1 | 1 | 1 | 4µs | 9µs | Date::Manip::TZ::BEGIN@1586 |
| 1 | 1 | 1 | 4µs | 10µs | Date::Manip::TZ::BEGIN@189 |
| 1 | 1 | 1 | 4µs | 7µs | Date::Manip::TZ::BEGIN@19 |
| 3 | 1 | 1 | 3µs | 3µs | Date::Manip::TZ::CORE:ftfile (opcode) |
| 1 | 1 | 1 | 3µs | 9µs | Date::Manip::TZ::BEGIN@20 |
| 1 | 1 | 1 | 3µs | 464µs | Date::Manip::TZ::_init_final |
| 1 | 1 | 1 | 2µs | 2µs | Date::Manip::TZ::BEGIN@24 |
| 1 | 1 | 1 | 2µs | 2µs | Date::Manip::TZ::BEGIN@15 |
| 1 | 1 | 1 | 500ns | 500ns | Date::Manip::TZ::CORE:close (opcode) |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_check_abbrev_isdst |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_check_offset_abbrev_isdst |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_cmd |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_config_var_setdate |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_config_var_tz |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_convert |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_convert_args |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_lastrule |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_list_add |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_list_union |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_offmod |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_sortByLength |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::_windows_registry_val |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::all_periods |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::convert |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::convert_from_gmt |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::convert_from_local |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::convert_to_gmt |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::convert_to_local |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::curr_zone |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::curr_zone_methods |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::define_abbrev |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::define_alias |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::define_offset |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::periods |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::tzcode |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::tzdata |
| 0 | 0 | 0 | 0s | 0s | Date::Manip::TZ::zone |
| 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 | 4µs | @ISA = qw(Date::Manip::Obj Date::Manip::TZ_Base); | ||
| 17 | |||||
| 18 | 1 | 5µ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 | 9µs | 2 | 15µs | # spent 9µs (3+6) within Date::Manip::TZ::BEGIN@20 which was called:
# once (3µs+6µs) by Date::Manip::Date::BEGIN@27 at line 20 # spent 9µs making 1 call to Date::Manip::TZ::BEGIN@20
# spent 6µs making 1 call to strict::import |
| 21 | |||||
| 22 | 2 | 17µs | 2 | 172µs | # spent 88µs (4+84) within Date::Manip::TZ::BEGIN@22 which was called:
# once (4µs+84µs) by Date::Manip::Date::BEGIN@27 at line 22 # spent 88µs making 1 call to Date::Manip::TZ::BEGIN@22
# spent 84µs making 1 call to Exporter::import |
| 23 | 1 | 47µs | require Date::Manip::Zones; | ||
| 24 | 2 | 206µs | 1 | 2µs | # spent 2µs within Date::Manip::TZ::BEGIN@24 which was called:
# once (2µs+0s) by Date::Manip::Date::BEGIN@27 at line 24 # spent 2µs making 1 call to Date::Manip::TZ::BEGIN@24 |
| 25 | |||||
| 26 | 1 | 100ns | our $VERSION; | ||
| 27 | 1 | 200ns | $VERSION='6.49'; | ||
| 28 | 1 | 1µs | END { undef $VERSION; } | ||
| 29 | |||||
| 30 | # To get rid of a 'used only once' warnings. | ||||
| 31 | # spent 6µs within Date::Manip::TZ::END which was called 2 times, avg 3µs/call:
# 2 times (6µs+0s) by main::RUNTIME at line 0 of ../dm5dm6_ex3, avg 3µs/call | ||||
| 32 | 1 | 800ns | my $tmp = \%Date::Manip::Zones::Module; | ||
| 33 | 1 | 500ns | $tmp = \%Date::Manip::Zones::ZoneNames; | ||
| 34 | 1 | 500ns | $tmp = \%Date::Manip::Zones::Alias; | ||
| 35 | 1 | 300ns | $tmp = \%Date::Manip::Zones::Abbrev; | ||
| 36 | 1 | 300ns | $tmp = \%Date::Manip::Zones::Offmod; | ||
| 37 | 1 | 300ns | $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 31µs (24+7) within Date::Manip::TZ::_init which was called:
# once (24µ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 | 800ns | 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 | 500ns | $$self{'data'}{'path'} = '/bin:/usr/bin'; | ||
| 100 | 1 | 5µ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 464µs (3+461) within Date::Manip::TZ::_init_final which was called:
# once (3µs+461µs) by Date::Manip::Obj::new at line 165 of Date/Manip/Obj.pm | ||||
| 153 | 1 | 200ns | my($self) = @_; | ||
| 154 | |||||
| 155 | 1 | 3µs | 1 | 461µs | $self->_set_curr_zone(); # spent 461µs making 1 call to Date::Manip::TZ::_set_curr_zone |
| 156 | } | ||||
| 157 | |||||
| 158 | 2 | 100µs | 2 | 17µs | # spent 11µs (4+6) within Date::Manip::TZ::BEGIN@158 which was called:
# once (4µs+6µs) by Date::Manip::Date::BEGIN@27 at line 158 # spent 11µs making 1 call to Date::Manip::TZ::BEGIN@158
# spent 6µ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 | # spent 6.34ms (6.31+36µs) within Date::Manip::TZ::_module which was called 2431 times, avg 3µs/call:
# 2431 times (6.31ms+36µs) by Date::Manip::TZ::date_period at line 1194, avg 3µs/call | ||||
| 175 | 2431 | 286µs | my($self,$zone) = @_; | ||
| 176 | 2431 | 3.15ms | return if (exists $$self{'data'}{'Zones'}{$zone}{'Loaded'}); | ||
| 177 | |||||
| 178 | 1 | 1µs | my $mod = $$self{'data'}{'Module'}{$zone}; | ||
| 179 | 1 | 29µs | eval "require Date::Manip::TZ::${mod}"; # spent 60µs executing statements in string eval | ||
| 180 | 1 | 24µs | my %dates = %{ "Date::Manip::TZ::${mod}::Dates" }; | ||
| 181 | 1 | 2µs | my %last = %{ "Date::Manip::TZ::${mod}::LastRule" }; | ||
| 182 | 1 | 26µs | $$self{'data'}{'Zones'}{$zone} = | ||
| 183 | { | ||||
| 184 | 'Dates' => { %dates }, | ||||
| 185 | 'LastRule' => { %last }, | ||||
| 186 | 'Loaded' => 1 | ||||
| 187 | }; | ||||
| 188 | } | ||||
| 189 | 2 | 1.23ms | 2 | 15µ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 6.84ms within Date::Manip::TZ::_zone which was called 4863 times, avg 1µs/call:
# 2431 times (2.71ms+0s) by Date::Manip::TZ::date_period at line 1188, avg 1µs/call
# 2430 times (4.13ms+0s) by Date::Manip::Date::set at line 2616 of Date/Manip/Date.pm, avg 2µs/call
# once (5µs+0s) by Date::Manip::TZ::_get_curr_zone at line 635
# once (1µs+0s) by Date::Manip::TZ::_set_curr_zone at line 388 | ||||
| 196 | 4863 | 605µs | my($self,$zone) = @_; | ||
| 197 | 4863 | 978µs | $zone = lc($zone); | ||
| 198 | |||||
| 199 | 4863 | 7.99ms | 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 461µs (7+454) within Date::Manip::TZ::_set_curr_zone which was called:
# once (7µs+454µs) by Date::Manip::TZ::_init_final at line 155 | ||||
| 384 | 1 | 200ns | my($self) = @_; | ||
| 385 | 1 | 500ns | my $dmb = $$self{'base'}; | ||
| 386 | 1 | 2µs | 1 | 453µs | my $currzone = $self->_get_curr_zone(); # spent 453µs making 1 call to Date::Manip::TZ::_get_curr_zone |
| 387 | |||||
| 388 | 1 | 3µs | 1 | 1µs | $$dmb{'data'}{'now'}{'systz'} = $self->_zone($currzone); # spent 1µ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 453µs (287+166) within Date::Manip::TZ::_get_curr_zone which was called:
# once (287µs+166µs) by Date::Manip::TZ::_set_curr_zone at line 386 | ||||
| 395 | 1 | 200ns | my($self) = @_; | ||
| 396 | 1 | 500ns | my $dmb = $$self{'base'}; | ||
| 397 | |||||
| 398 | 1 | 400ns | 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 | 1µs | my $dstflag = ($isdst ? 'dstonly' : 'stdonly'); | ||
| 402 | |||||
| 403 | 1 | 3µ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 | 600ns | while (@methods) { | ||
| 411 | 5 | 1µs | my $method = shift(@methods); | ||
| 412 | 5 | 900ns | my @zone = (); | ||
| 413 | |||||
| 414 | 5 | 3µ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 | 200ns | my $var = shift(@methods); | ||
| 421 | 1 | 4µs | push(@zone,$$::var) if (defined $$::var); | ||
| 422 | |||||
| 423 | 1 | 300ns | 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 | 700ns | my $type = lc( shift(@methods) ); | ||
| 434 | 1 | 400ns | 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 | 500ns | my $var = shift(@methods); | ||
| 440 | 1 | 700ns | 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 | 200ns | 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 | 200ns | my $firstline = 1; | ||
| 473 | |||||
| 474 | 1 | 200ns | my @z; | ||
| 475 | 1 | 28µs | 68 | 71µs | while (! $in->eof) { # spent 71µs making 68 calls to IO::Handle::eof, avg 1µs/call |
| 476 | 74 | 63µs | 74 | 10µs | my $line = <$in>; # spent 10µs making 74 calls to Date::Manip::TZ::CORE:readline, avg 138ns/call |
| 477 | 74 | 89µs | 83 | 19µs | next if ($line =~ /^\s*\043/ || # spent 19µs making 83 calls to Date::Manip::TZ::CORE:match, avg 225ns/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 | 9µ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 400ns/call |
| 504 | 1 | 800ns | my $val = $1; | ||
| 505 | 1 | 600ns | @z = (); | ||
| 506 | 1 | 200ns | last if (! $val); | ||
| 507 | |||||
| 508 | 1 | 6µ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 | 100ns | 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 | 500ns | last; | ||
| 525 | } | ||||
| 526 | 6 | 3µs | 6 | 6µs | if ($firstline) { # spent 6µs making 6 calls to IO::Handle::eof, avg 967ns/call |
| 527 | 1 | 500ns | $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 | 2µs | $line =~ s/\s*$//; # spent 2µ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 | 1µs | 1 | 400ns | $line =~ s/\s+/_/g; # spent 400ns making 1 call to Date::Manip::TZ::CORE:subst |
| 532 | 1 | 400ns | push(@z,$line); | ||
| 533 | } | ||||
| 534 | } | ||||
| 535 | 1 | 4µs | 1 | 500ns | close(IN); # spent 500ns making 1 call to Date::Manip::TZ::CORE:close |
| 536 | |||||
| 537 | 1 | 200ns | push(@zone,@z) if (@z); | ||
| 538 | |||||
| 539 | 1 | 5µ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 | 500ns | $zone = lc($zone); | ||
| 631 | # OpenUNIX puts a colon at the start | ||||
| 632 | 1 | 2µs | 1 | 300ns | $zone =~ s/^://; # spent 300ns making 1 call to Date::Manip::TZ::CORE:subst |
| 633 | |||||
| 634 | # If we got a zone name/alias | ||||
| 635 | 1 | 2µs | 1 | 5µs | $currzone = $self->_zone($zone); # spent 5µs making 1 call to Date::Manip::TZ::_zone |
| 636 | 1 | 1µ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 | 300ns | 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 | 22µs | # spent 15µs (8+7) within Date::Manip::TZ::BEGIN@721 which was called:
# once (8µs+7µs) by Date::Manip::Date::BEGIN@27 at line 721 # spent 15µs making 1 call to Date::Manip::TZ::BEGIN@721
# spent 7µ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 | 1.96ms | 2 | 10µ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(@abbrev,$date,$tmp); | ||||
| 749 | foreach my $arg (@args) { | ||||
| 750 | |||||
| 751 | if (ref($arg) eq 'ARRAY') { | ||||
| 752 | if ($#$arg == 5) { | ||||
| 753 | # [Y,M,D,H,Mn,S] | ||||
| 754 | return undef if ($date); | ||||
| 755 | $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 | $arg = lc($arg); | ||||
| 772 | |||||
| 773 | if ($arg =~ /^(std|dst|stdonly|dstonly)$/) { | ||||
| 774 | return undef if ($dstflag); | ||||
| 775 | $dstflag = $arg; | ||||
| 776 | |||||
| 777 | } elsif ($tmp = $self->_zone($arg)) { | ||||
| 778 | return undef if ($zone); | ||||
| 779 | $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 | my @zone; | ||||
| 809 | |||||
| 810 | while (1) { | ||||
| 811 | |||||
| 812 | # No information | ||||
| 813 | |||||
| 814 | 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 | $dstflag = "dst" if ($offset && $date && ! $dstflag); | ||||
| 828 | |||||
| 829 | my(@isdst); | ||||
| 830 | 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 | @isdst = (0,1); | ||||
| 838 | } | ||||
| 839 | |||||
| 840 | # $zone | ||||
| 841 | |||||
| 842 | if ($zone) { | ||||
| 843 | @zone = ($zone); | ||||
| 844 | } | ||||
| 845 | |||||
| 846 | # $abbrev | ||||
| 847 | |||||
| 848 | 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 | 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 | 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 | my @tmp; | ||||
| 913 | my $isdst = ''; | ||||
| 914 | $isdst = 0 if ($dstflag eq 'stdonly'); | ||||
| 915 | $isdst = 1 if ($dstflag eq 'dstonly'); | ||||
| 916 | |||||
| 917 | ZONE: | ||||
| 918 | foreach my $z (@zone) { | ||||
| 919 | $self->_module($z); | ||||
| 920 | my $y = $$date[0]; | ||||
| 921 | my @periods = $self->_all_periods($z,$y); | ||||
| 922 | |||||
| 923 | foreach my $period (@periods) { | ||||
| 924 | my($begUT,$begLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period; | ||||
| 925 | next if ($dmb->cmp($date,$begLT) == -1 || | ||||
| 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 | push(@tmp,$z); | ||||
| 932 | next ZONE; | ||||
| 933 | } | ||||
| 934 | } | ||||
| 935 | @zone = @tmp; | ||||
| 936 | last if (! @zone); | ||||
| 937 | } | ||||
| 938 | |||||
| 939 | last; | ||||
| 940 | } | ||||
| 941 | |||||
| 942 | # Return the value/list | ||||
| 943 | |||||
| 944 | if (wantarray) { | ||||
| 945 | my @ret; | ||||
| 946 | foreach my $z (@zone) { | ||||
| 947 | push(@ret,$$self{'data'}{'ZoneNames'}{$z}); | ||||
| 948 | } | ||||
| 949 | return @ret; | ||||
| 950 | } | ||||
| 951 | |||||
| 952 | return '' if (! @zone); | ||||
| 953 | 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 | # spent 22.2ms (21.9+285µs) within Date::Manip::TZ::_all_periods which was called 2431 times, avg 9µs/call:
# 2431 times (21.9ms+285µs) by Date::Manip::TZ::date_period at line 1204, avg 9µs/call | ||||
| 1055 | 2431 | 507µs | my($self,$zone,$year) = @_; | ||
| 1056 | 2431 | 534µs | $year += 0; | ||
| 1057 | |||||
| 1058 | 2431 | 1.10ms | 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 | 7 | 1µs | my($ym1,$ym0); | ||
| 1067 | 7 | 19µ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 | 7 | 289µs | 7 | 160µs | foreach my $y (sort { $a <=> $b } # spent 160µs making 7 calls to Date::Manip::TZ::CORE:sort, avg 23µs/call |
| 1074 | keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) { | ||||
| 1075 | 665 | 54µs | if ($y < $year) { | ||
| 1076 | 658 | 46µs | $ym1 = $y; | ||
| 1077 | 658 | 42µs | next; | ||
| 1078 | } | ||||
| 1079 | 7 | 3µs | $ym0 = $year if ($year == $y); | ||
| 1080 | 7 | 2µs | last; | ||
| 1081 | } | ||||
| 1082 | } | ||||
| 1083 | 7 | 1µs | $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 | 7 | 2µs | my(@periods); | ||
| 1091 | |||||
| 1092 | # $ym1 will be 0 in 0001 | ||||
| 1093 | 7 | 2µs | if ($ym1) { | ||
| 1094 | 7 | 11µs | 7 | 75µs | my @tmp = $self->_periods($zone,$ym1); # spent 75µs making 7 calls to Date::Manip::TZ::_periods, avg 11µs/call |
| 1095 | 7 | 10µs | push(@periods,pop(@tmp)) if (@tmp); | ||
| 1096 | } | ||||
| 1097 | |||||
| 1098 | # | ||||
| 1099 | # Add on any periods from the current year. | ||||
| 1100 | # | ||||
| 1101 | |||||
| 1102 | 7 | 7µs | 7 | 50µs | if ($ym0) { # spent 50µs making 7 calls to Date::Manip::TZ::_periods, avg 7µs/call |
| 1103 | push(@periods,$self->_periods($zone,$year)); | ||||
| 1104 | } | ||||
| 1105 | |||||
| 1106 | 7 | 7µs | $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} = [ @periods ]; | ||
| 1107 | } | ||||
| 1108 | |||||
| 1109 | # A faster 'dclone' so we don't return the actual data | ||||
| 1110 | 2431 | 247µs | my @ret; | ||
| 1111 | 2431 | 1.70ms | 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 | 7293 | 15.8ms | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
| 1115 | } | ||||
| 1116 | 2431 | 3.15ms | 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 | sub _periods { | ||||
| 1159 | 14 | 4µs | my($self,$zone,$year) = @_; | ||
| 1160 | 14 | 3µs | $year += 0; | ||
| 1161 | |||||
| 1162 | 14 | 11µ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 | 14 | 1µs | my @ret; | ||
| 1175 | 14 | 13µ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 | 28 | 82µs | [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]); | ||
| 1179 | } | ||||
| 1180 | 14 | 25µs | return @ret; | ||
| 1181 | } | ||||
| 1182 | |||||
| 1183 | # spent 73.3ms (31.7+41.6) within Date::Manip::TZ::date_period which was called 2431 times, avg 30µs/call:
# 2430 times (31.7ms+37.3ms) by Date::Manip::Date::set at line 2664 of Date/Manip/Date.pm, avg 28µs/call
# once (31µs+4.25ms) by Date::Manip::TZ_Base::_update_now at line 387 of Date/Manip/TZ_Base.pm | ||||
| 1184 | 2431 | 615µs | my($self,$date,$zone,$wallclock,$isdst) = @_; | ||
| 1185 | 2431 | 236µs | $wallclock = 0 if (! $wallclock); | ||
| 1186 | 2431 | 317µs | $isdst = 0 if (! $isdst); | ||
| 1187 | |||||
| 1188 | 2431 | 1.30ms | 2431 | 2.71ms | my $z = $self->_zone($zone); # spent 2.71ms making 2431 calls to Date::Manip::TZ::_zone, avg 1µs/call |
| 1189 | 2431 | 221µs | if (! $z) { | ||
| 1190 | warn "ERROR: [date_period] Invalid zone: $zone\n"; | ||||
| 1191 | return; | ||||
| 1192 | } | ||||
| 1193 | 2431 | 272µs | $zone = $z; | ||
| 1194 | 2431 | 1.24ms | 2431 | 6.34ms | $self->_module($zone); # spent 6.34ms making 2431 calls to Date::Manip::TZ::_module, avg 3µs/call |
| 1195 | |||||
| 1196 | 2431 | 369µs | my $dmb = $$self{'base'}; | ||
| 1197 | 2431 | 1.73ms | my @date = @$date; | ||
| 1198 | 2431 | 452µs | my $year = $date[0]; | ||
| 1199 | 2431 | 1.92ms | 2431 | 10.4ms | my $dates= $dmb->_date_fields(@$date); # spent 10.4ms making 2431 calls to Date::Manip::Base::_date_fields, avg 4µs/call |
| 1200 | |||||
| 1201 | 2431 | 374µs | if ($wallclock) { | ||
| 1202 | # A wallclock date | ||||
| 1203 | |||||
| 1204 | 2431 | 2.11ms | 2431 | 22.2ms | my @period = $self->_all_periods($zone,$year); # spent 22.2ms making 2431 calls to Date::Manip::TZ::_all_periods, avg 9µs/call |
| 1205 | 2431 | 550µs | my $beg = $period[0]->[9]; | ||
| 1206 | 2431 | 406µs | my $end = $period[-1]->[11]; | ||
| 1207 | 2431 | 936µ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 | 2431 | 165µs | my(@per); | ||
| 1214 | 2431 | 634µs | foreach my $period (@period) { | ||
| 1215 | 7293 | 2.57ms | my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT, | ||
| 1216 | $begUTs,$begLTs,$endUTs,$endLTs) = @$period; | ||||
| 1217 | 7293 | 3.58ms | if (($dates cmp $begLTs) != -1 && ($dates cmp $endLTs) != 1) { | ||
| 1218 | push(@per,$period); | ||||
| 1219 | } | ||||
| 1220 | } | ||||
| 1221 | |||||
| 1222 | 2431 | 7.43ms | 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 | sub convert_to_gmt { | ||||
| 1347 | my($self,$date,@arg) = @_; | ||||
| 1348 | my($err,$from,$isdst) = _convert_args('convert_to_gmt',@arg); | ||||
| 1349 | return (1) if ($err); | ||||
| 1350 | |||||
| 1351 | my $dmb = $$self{'base'}; | ||||
| 1352 | |||||
| 1353 | if (! $from) { | ||||
| 1354 | $from = $self->_now('tz',1); | ||||
| 1355 | } | ||||
| 1356 | $self->_convert('convert_to_gmt',$date,$from,'GMT',$isdst); | ||||
| 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 | sub _convert_args { | ||||
| 1399 | my($caller,@args) = @_; | ||||
| 1400 | |||||
| 1401 | 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 | return (0,$args[0],0); | ||||
| 1409 | } | ||||
| 1410 | } elsif ($#args == 1) { | ||||
| 1411 | return (0,@args); | ||||
| 1412 | } else { | ||||
| 1413 | return (1,'',0); | ||||
| 1414 | } | ||||
| 1415 | } | ||||
| 1416 | |||||
| 1417 | sub _convert { | ||||
| 1418 | my($self,$caller,$date,$from,$to,$isdst) = @_; | ||||
| 1419 | my $dmb = $$self{'base'}; | ||||
| 1420 | |||||
| 1421 | # Handle $date as a reference and a string | ||||
| 1422 | my (@date); | ||||
| 1423 | if (ref($date)) { | ||||
| 1424 | @date = @$date; | ||||
| 1425 | } else { | ||||
| 1426 | @date = @{ $dmb->split('date',$date) }; | ||||
| 1427 | $date = [@date]; | ||||
| 1428 | } | ||||
| 1429 | |||||
| 1430 | if ($from ne $to) { | ||||
| 1431 | my $tmp = $self->_zone($from); | ||||
| 1432 | if (! $tmp) { | ||||
| 1433 | return (2); | ||||
| 1434 | } | ||||
| 1435 | $from = $tmp; | ||||
| 1436 | |||||
| 1437 | $tmp = $self->_zone($to); | ||||
| 1438 | if (! $tmp) { | ||||
| 1439 | return (3); | ||||
| 1440 | } | ||||
| 1441 | $to = $tmp; | ||||
| 1442 | } | ||||
| 1443 | |||||
| 1444 | if ($from eq $to) { | ||||
| 1445 | my $per = $self->date_period($date,$from,1,$isdst); | ||||
| 1446 | my $offset = $$per[3]; | ||||
| 1447 | my $abb = $$per[4]; | ||||
| 1448 | 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 regular expressions capable of matching timezones. | ||||
| 1484 | # | ||||
| 1485 | # The timezone regular expressions are: | ||||
| 1486 | # namerx : this will match a zone name or alias (America/New_York) | ||||
| 1487 | # abbrx : this will match a zone abbreviation (EDT) | ||||
| 1488 | # zonerx : this will match a zone name or an abbreviation | ||||
| 1489 | # offrx : this will match a pure offset (+0400) | ||||
| 1490 | # offabbrx : this will match an offset with an abbreviation (+0400 WET) | ||||
| 1491 | # offparrx : this will match an offset and abbreviation if parentheses | ||||
| 1492 | # ("+0400 (WET)") | ||||
| 1493 | # zrx : this will match all forms | ||||
| 1494 | # | ||||
| 1495 | # The regular expression will have the following named matches: | ||||
| 1496 | # tzstring : the full string matched | ||||
| 1497 | # zone : the name/alias | ||||
| 1498 | # abb : the zone abbrevation | ||||
| 1499 | # off : the offset | ||||
| 1500 | # | ||||
| 1501 | # spent 15.7ms (4.68+11.0) within Date::Manip::TZ::_zrx which was called 10 times, avg 1.57ms/call:
# 6 times (9µs+0s) by Date::Manip::Date::_parse_tz at line 1718 of Date/Manip/Date.pm, avg 2µs/call
# once (4.67ms+11.0ms) by Date::Manip::Date::_iso8601_rx at line 1126 of Date/Manip/Date.pm
# once (2µs+0s) by Date::Manip::Date::_other_rx at line 1493 of Date/Manip/Date.pm
# once (1µs+0s) by Date::Manip::Date::_other_rx at line 1388 of Date/Manip/Date.pm
# once (700ns+0s) by Date::Manip::Date::_other_rx at line 1494 of Date/Manip/Date.pm | ||||
| 1502 | 10 | 2µs | my($self,$re) = @_; | ||
| 1503 | 10 | 19µs | return $$self{'data'}{$re} if (defined $$self{'data'}{$re}); | ||
| 1504 | |||||
| 1505 | # Zone name | ||||
| 1506 | |||||
| 1507 | 1 | 300ns | my @zone; | ||
| 1508 | 1 | 12µs | if (exists $ENV{'DATE_MANIP_DEBUG_ZONES'}) { | ||
| 1509 | @zone = split(/\s+/,$ENV{'DATE_MANIP_DEBUG_ZONES'}); | ||||
| 1510 | } else { | ||||
| 1511 | @zone = (keys %{ $$self{'data'}{'Alias'} }, | ||||
| 1512 | 1 | 102µs | keys %{ $$self{'data'}{'MyAlias'} }); | ||
| 1513 | } | ||||
| 1514 | 1 | 4µs | 1 | 909µs | @zone = sort _sortByLength(@zone); # spent 909µs making 1 call to Date::Manip::TZ::CORE:sort |
| 1515 | 1 | 800ns | foreach my $zone (@zone) { | ||
| 1516 | 825 | 719µs | 825 | 144µs | $zone =~ s/\057/\\057/g; # / # spent 144µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 174ns/call |
| 1517 | 825 | 599µs | 825 | 41µs | $zone =~ s/\055/\\055/g; # - # spent 41µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 50ns/call |
| 1518 | 825 | 568µs | 825 | 11µs | $zone =~ s/\056/\\056/g; # . # spent 11µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 13ns/call |
| 1519 | 825 | 555µs | 825 | 8µs | $zone =~ s/\050/\\050/g; # ( # spent 8µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 9ns/call |
| 1520 | 825 | 560µs | 825 | 8µs | $zone =~ s/\051/\\051/g; # ) # spent 8µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 9ns/call |
| 1521 | 825 | 711µs | 825 | 8µs | $zone =~ s/\053/\\053/g; # + # spent 8µs making 825 calls to Date::Manip::TZ::CORE:subst, avg 9ns/call |
| 1522 | } | ||||
| 1523 | |||||
| 1524 | 1 | 24µs | my $zone = join('|',@zone); | ||
| 1525 | 1 | 1.62ms | 2 | 1.56ms | $zone = qr/(?<zone>$zone)/i; # spent 1.56ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 1µs making 1 call to Date::Manip::TZ::CORE:qr |
| 1526 | |||||
| 1527 | # Abbreviation | ||||
| 1528 | |||||
| 1529 | 1 | 200ns | my @abb; | ||
| 1530 | 1 | 6µs | if (exists $ENV{'DATE_MANIP_DEBUG_ABBREVS'}) { | ||
| 1531 | @abb = split(/\s+/,$ENV{'DATE_MANIP_DEBUG_ABBREVS'}); | ||||
| 1532 | } else { | ||||
| 1533 | @abb = (keys %{ $$self{'data'}{'Abbrev'} }, | ||||
| 1534 | 1 | 71µs | keys %{ $$self{'data'}{'MyAbbrev'} }); | ||
| 1535 | } | ||||
| 1536 | 1 | 2µs | 1 | 328µs | @abb = sort _sortByLength(@abb); # spent 328µs making 1 call to Date::Manip::TZ::CORE:sort |
| 1537 | 1 | 800ns | foreach my $abb (@abb) { | ||
| 1538 | 403 | 277µs | 403 | 5µs | $abb =~ s/\055/\\055/g; # - # spent 5µs making 403 calls to Date::Manip::TZ::CORE:subst, avg 13ns/call |
| 1539 | 403 | 315µs | 403 | 5µs | $abb =~ s/\053/\\053/g; # + # spent 5µs making 403 calls to Date::Manip::TZ::CORE:subst, avg 12ns/call |
| 1540 | } | ||||
| 1541 | |||||
| 1542 | 1 | 10µs | my $abb = join('|',@abb); | ||
| 1543 | 1 | 472µs | 2 | 446µs | $abb = qr/(?<abb>$abb)/i; # spent 445µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 1µs making 1 call to Date::Manip::TZ::CORE:qr |
| 1544 | |||||
| 1545 | # Offset (+HH, +HHMM, +HH:MM, +HH:MM:SS, +HHMMSS) | ||||
| 1546 | |||||
| 1547 | 1 | 2µs | 1 | 500ns | my($hr) = qr/(?:[0-1][0-9]|2[0-3])/; # 00 - 23 # spent 500ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1548 | 1 | 2µs | 1 | 300ns | my($mn) = qr/(?:[0-5][0-9])/; # 00 - 59 # spent 300ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1549 | 1 | 2µs | 1 | 300ns | my($ss) = qr/(?:[0-5][0-9])/; # 00 - 59 # spent 300ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1550 | |||||
| 1551 | 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 500ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1552 | $hr$mn$ss | | ||||
| 1553 | $hr:?$mn | | ||||
| 1554 | $hr | ||||
| 1555 | ) | ||||
| 1556 | ) /ix; | ||||
| 1557 | |||||
| 1558 | # Assemble everything | ||||
| 1559 | # | ||||
| 1560 | # A timezone can be any of the following in this order: | ||||
| 1561 | # Offset (ABB) | ||||
| 1562 | # Offset ABB | ||||
| 1563 | # ABB | ||||
| 1564 | # Zone | ||||
| 1565 | # Offset | ||||
| 1566 | # We put ABB before Zone so CET gets parse as the more common abbreviation | ||||
| 1567 | # than the less common zone name. | ||||
| 1568 | |||||
| 1569 | 1 | 1.64ms | 2 | 1.59ms | $$self{'data'}{'namerx'} = qr/(?<tzstring>$zone)/; # spent 1.58ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1570 | 1 | 490µs | 2 | 462µs | $$self{'data'}{'abbrx'} = qr/(?<tzstring>$abb)/; # spent 460µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 2µs making 1 call to Date::Manip::TZ::CORE:qr |
| 1571 | 1 | 2.03ms | 2 | 1.96ms | $$self{'data'}{'zonerx'} = qr/(?<tzstring>(?:$abb|$zone))/; # spent 1.95ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 800ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1572 | 1 | 61µs | 2 | 57µs | $$self{'data'}{'offrx'} = qr/(?<tzstring>$off)/; # spent 56µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 500ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1573 | 1 | 377µs | 2 | 372µs | $$self{'data'}{'offabbrx'} = qr/(?<tzstring>$off\s+$abb)/; # spent 371µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 800ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1574 | 1 | 381µs | 2 | 376µs | $$self{'data'}{'offparrx'} = qr/(?<tzstring>$off\s*\($abb\))/; # spent 375µs making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 800ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1575 | 1 | 2.74ms | 2 | 2.66ms | $$self{'data'}{'zrx'} = qr/(?<tzstring>(?:$off\s*\($abb\)|$off\s+$abb|$abb|$zone|$off))/; # spent 2.66ms making 1 call to Date::Manip::TZ::CORE:regcomp
# spent 900ns making 1 call to Date::Manip::TZ::CORE:qr |
| 1576 | |||||
| 1577 | 1 | 28µs | return $$self{'data'}{$re}; | ||
| 1578 | } | ||||
| 1579 | |||||
| 1580 | # This sorts from longest to shortest element | ||||
| 1581 | # | ||||
| 1582 | 2 | 29µs | 2 | 21µs | # spent 14µs (7+7) within Date::Manip::TZ::BEGIN@1582 which was called:
# once (7µs+7µs) by Date::Manip::Date::BEGIN@27 at line 1582 # spent 14µs making 1 call to Date::Manip::TZ::BEGIN@1582
# spent 7µs making 1 call to strict::unimport |
| 1583 | sub _sortByLength { | ||||
| 1584 | 8991 | 1.24ms | return (length $b <=> length $a); | ||
| 1585 | } | ||||
| 1586 | 2 | 491µs | 2 | 13µs | # spent 9µs (4+5) within Date::Manip::TZ::BEGIN@1586 which was called:
# once (4µs+5µs) by Date::Manip::Date::BEGIN@27 at line 1586 # spent 9µs making 1 call to Date::Manip::TZ::BEGIN@1586
# spent 5µs making 1 call to strict::import |
| 1587 | |||||
| 1588 | ######################################################################## | ||||
| 1589 | # CONFIG VARS | ||||
| 1590 | ######################################################################## | ||||
| 1591 | |||||
| 1592 | # This sets a config variable. It also performs all side effects from | ||||
| 1593 | # setting that variable. | ||||
| 1594 | # | ||||
| 1595 | sub _config_var_tz { | ||||
| 1596 | my($self,$var,$val) = @_; | ||||
| 1597 | |||||
| 1598 | if ($var eq 'tz') { | ||||
| 1599 | my $err = $self->_config_var_setdate("now,$val",0); | ||||
| 1600 | return if ($err); | ||||
| 1601 | $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0; | ||||
| 1602 | $val = 1; | ||||
| 1603 | |||||
| 1604 | } elsif ($var eq 'setdate') { | ||||
| 1605 | my $err = $self->_config_var_setdate($val,0); | ||||
| 1606 | return if ($err); | ||||
| 1607 | $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0; | ||||
| 1608 | $val = 1; | ||||
| 1609 | |||||
| 1610 | } elsif ($var eq 'forcedate') { | ||||
| 1611 | my $err = $self->_config_var_setdate($val,1); | ||||
| 1612 | return if ($err); | ||||
| 1613 | $$self{'data'}{'sections'}{'conf'}{'setdate'} = 0; | ||||
| 1614 | $val = 1; | ||||
| 1615 | |||||
| 1616 | } elsif ($var eq 'configfile') { | ||||
| 1617 | $self->_config_file($val); | ||||
| 1618 | return; | ||||
| 1619 | } | ||||
| 1620 | |||||
| 1621 | my $base = $$self{'base'}; | ||||
| 1622 | $$base{'data'}{'sections'}{'conf'}{$var} = $val; | ||||
| 1623 | return; | ||||
| 1624 | } | ||||
| 1625 | |||||
| 1626 | sub _config_var_setdate { | ||||
| 1627 | my($self,$val,$force) = @_; | ||||
| 1628 | my $base = $$self{'base'}; | ||||
| 1629 | |||||
| 1630 | my $dstrx = qr/(?:,\s*(stdonly|dstonly|std|dst))?/i; | ||||
| 1631 | my $zonrx = qr/,\s*(.+)/; | ||||
| 1632 | my $da1rx = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d):(\d\d):(\d\d)/; | ||||
| 1633 | my $da2rx = qr/(\d\d\d\d)\-(\d\d)\-(\d\d)\-(\d\d):(\d\d):(\d\d)/; | ||||
| 1634 | my $time = time; | ||||
| 1635 | |||||
| 1636 | my($op,$date,$dstflag,$zone,@date,$offset,$abb); | ||||
| 1637 | |||||
| 1638 | # | ||||
| 1639 | # Parse the argument | ||||
| 1640 | # | ||||
| 1641 | |||||
| 1642 | if ($val =~ /^now${dstrx}${zonrx}$/oi) { | ||||
| 1643 | # now,ZONE | ||||
| 1644 | # now,DSTFLAG,ZONE | ||||
| 1645 | # Sets now to the system date/time but sets the timezone to be ZONE | ||||
| 1646 | |||||
| 1647 | $op = 'nowzone'; | ||||
| 1648 | ($dstflag,$zone) = ($1,$2); | ||||
| 1649 | |||||
| 1650 | } elsif ($val =~ /^zone${dstrx}${zonrx}$/oi) { | ||||
| 1651 | # zone,ZONE | ||||
| 1652 | # zone,DSTFLAG,ZONE | ||||
| 1653 | # Converts 'now' to the alternate zone | ||||
| 1654 | |||||
| 1655 | $op = 'zone'; | ||||
| 1656 | ($dstflag,$zone) = ($1,$2); | ||||
| 1657 | |||||
| 1658 | } elsif ($val =~ /^${da1rx}${dstrx}${zonrx}$/o || | ||||
| 1659 | $val =~ /^${da2rx}${dstrx}${zonrx}$/o) { | ||||
| 1660 | # DATE,ZONE | ||||
| 1661 | # DATE,DSTFLAG,ZONE | ||||
| 1662 | # Sets the date and zone | ||||
| 1663 | |||||
| 1664 | $op = 'datezone'; | ||||
| 1665 | my($y,$m,$d,$h,$mn,$s); | ||||
| 1666 | ($y,$m,$d,$h,$mn,$s,$dstflag,$zone) = ($1,$2,$3,$4,$5,$6,$7,$8); | ||||
| 1667 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
| 1668 | |||||
| 1669 | } elsif ($val =~ /^${da1rx}$/o || | ||||
| 1670 | $val =~ /^${da2rx}$/o) { | ||||
| 1671 | # DATE | ||||
| 1672 | # Sets the date in the system timezone | ||||
| 1673 | |||||
| 1674 | $op = 'date'; | ||||
| 1675 | my($y,$m,$d,$h,$mn,$s) = ($1,$2,$3,$4,$5,$6); | ||||
| 1676 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
| 1677 | $zone = $self->_now('systz',1); | ||||
| 1678 | |||||
| 1679 | } elsif (lc($val) eq 'now') { | ||||
| 1680 | # now | ||||
| 1681 | # Resets everything | ||||
| 1682 | |||||
| 1683 | my $systz = $$base{'data'}{'now'}{'systz'}; | ||||
| 1684 | $base->_init_now(); | ||||
| 1685 | $$base{'data'}{'now'}{'systz'} = $systz; | ||||
| 1686 | return 0; | ||||
| 1687 | |||||
| 1688 | } else { | ||||
| 1689 | warn "ERROR: [config_var] invalid SetDate/ForceDate value: $val\n"; | ||||
| 1690 | return 1; | ||||
| 1691 | } | ||||
| 1692 | |||||
| 1693 | $dstflag = 'std' if (! $dstflag); | ||||
| 1694 | |||||
| 1695 | # | ||||
| 1696 | # Get the date we're setting 'now' to | ||||
| 1697 | # | ||||
| 1698 | |||||
| 1699 | if ($op eq 'nowzone') { | ||||
| 1700 | # Use the system localtime | ||||
| 1701 | |||||
| 1702 | my($s,$mn,$h,$d,$m,$y) = localtime($time); | ||||
| 1703 | $y += 1900; | ||||
| 1704 | $m++; | ||||
| 1705 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
| 1706 | |||||
| 1707 | } elsif ($op eq 'zone') { | ||||
| 1708 | # Use the system GMT time | ||||
| 1709 | |||||
| 1710 | my($s,$mn,$h,$d,$m,$y) = gmtime($time); | ||||
| 1711 | $y += 1900; | ||||
| 1712 | $m++; | ||||
| 1713 | $date = [$y,$m,$d,$h,$mn,$s]; | ||||
| 1714 | } | ||||
| 1715 | |||||
| 1716 | # | ||||
| 1717 | # Find out what zone was passed in. It can be an alias or an offset. | ||||
| 1718 | # | ||||
| 1719 | |||||
| 1720 | if ($zone) { | ||||
| 1721 | my ($err,@args); | ||||
| 1722 | push(@args,$date) if ($date); | ||||
| 1723 | push(@args,$zone); | ||||
| 1724 | push(@args,$dstflag); | ||||
| 1725 | |||||
| 1726 | $zone = $self->zone(@args); | ||||
| 1727 | if (! $zone) { | ||||
| 1728 | warn "ERROR: [config_var] invalid zone in SetDate: @args\n"; | ||||
| 1729 | return 1; | ||||
| 1730 | } | ||||
| 1731 | |||||
| 1732 | } else { | ||||
| 1733 | $zone = $$base{'data'}{'now'}{'systz'}; | ||||
| 1734 | } | ||||
| 1735 | |||||
| 1736 | # | ||||
| 1737 | # Handle the zone | ||||
| 1738 | # | ||||
| 1739 | |||||
| 1740 | my($isdst,@isdst); | ||||
| 1741 | if ($dstflag eq 'std') { | ||||
| 1742 | @isdst = (0,1); | ||||
| 1743 | } elsif ($dstflag eq 'stdonly') { | ||||
| 1744 | @isdst = (0); | ||||
| 1745 | } elsif ($dstflag eq 'dst') { | ||||
| 1746 | @isdst = (1,0); | ||||
| 1747 | } else { | ||||
| 1748 | @isdst = (1); | ||||
| 1749 | } | ||||
| 1750 | |||||
| 1751 | if ($op eq 'nowzone' || | ||||
| 1752 | $op eq 'datezone' || | ||||
| 1753 | $op eq 'date') { | ||||
| 1754 | |||||
| 1755 | # Check to make sure that the date can exist in this zone. | ||||
| 1756 | my $per; | ||||
| 1757 | foreach my $dst (@isdst) { | ||||
| 1758 | next if ($per); | ||||
| 1759 | $per = $self->date_period($date,$zone,1,$dst); | ||||
| 1760 | } | ||||
| 1761 | |||||
| 1762 | if (! $per) { | ||||
| 1763 | warn "ERROR: [config_var] invalid date: SetDate: $date, $zone\n"; | ||||
| 1764 | return 1; | ||||
| 1765 | } | ||||
| 1766 | $isdst = $$per[5]; | ||||
| 1767 | $abb = $$per[4]; | ||||
| 1768 | $offset = $$per[3]; | ||||
| 1769 | |||||
| 1770 | } elsif ($op eq 'zone') { | ||||
| 1771 | |||||
| 1772 | # Convert to that zone | ||||
| 1773 | my($err); | ||||
| 1774 | ($err,$date,$offset,$isdst,$abb) = $self->convert_from_gmt($date,$zone); | ||||
| 1775 | if ($err) { | ||||
| 1776 | warn "ERROR: [config_var] invalid SetDate date/offset values: $date, $zone\n"; | ||||
| 1777 | return 1; | ||||
| 1778 | } | ||||
| 1779 | } | ||||
| 1780 | |||||
| 1781 | # | ||||
| 1782 | # Set NOW | ||||
| 1783 | # | ||||
| 1784 | |||||
| 1785 | $$base{'data'}{'now'}{'date'} = $date; | ||||
| 1786 | $$base{'data'}{'now'}{'tz'} = $self->_zone($zone); | ||||
| 1787 | $$base{'data'}{'now'}{'isdst'} = $isdst; | ||||
| 1788 | $$base{'data'}{'now'}{'abb'} = $abb; | ||||
| 1789 | $$base{'data'}{'now'}{'offset'} = $offset; | ||||
| 1790 | |||||
| 1791 | # | ||||
| 1792 | # Treate SetDate/ForceDate | ||||
| 1793 | # | ||||
| 1794 | |||||
| 1795 | if ($force) { | ||||
| 1796 | $$base{'data'}{'now'}{'force'} = 1; | ||||
| 1797 | $$base{'data'}{'now'}{'set'} = 0; | ||||
| 1798 | } else { | ||||
| 1799 | $$base{'data'}{'now'}{'force'} = 0; | ||||
| 1800 | $$base{'data'}{'now'}{'set'} = 1; | ||||
| 1801 | $$base{'data'}{'now'}{'setsecs'} = $time; | ||||
| 1802 | my($err,$setdate) = $self->convert_to_gmt($date,$zone); | ||||
| 1803 | $$base{'data'}{'now'}{'setdate'} = $setdate; | ||||
| 1804 | } | ||||
| 1805 | |||||
| 1806 | return 0; | ||||
| 1807 | } | ||||
| 1808 | |||||
| 1809 | 1 | 2µs | 1; | ||
| 1810 | # Local Variables: | ||||
| 1811 | # mode: cperl | ||||
| 1812 | # indent-tabs-mode: nil | ||||
| 1813 | # cperl-indent-level: 3 | ||||
| 1814 | # cperl-continued-statement-offset: 2 | ||||
| 1815 | # cperl-continued-brace-offset: 0 | ||||
| 1816 | # cperl-brace-offset: 0 | ||||
| 1817 | # cperl-brace-imaginary-offset: 0 | ||||
| 1818 | # cperl-label-offset: 0 | ||||
| 1819 | # 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 23µs within Date::Manip::TZ::CORE:match which was called 91 times, avg 252ns/call:
# 83 times (19µs+0s) by Date::Manip::TZ::_get_curr_zone at line 477, avg 225ns/call
# 7 times (3µs+0s) by Date::Manip::TZ::_get_curr_zone at line 503, avg 400ns/call
# once (1µs+0s) by Date::Manip::TZ::_get_curr_zone at line 508 | |||||
# spent 10µs within Date::Manip::TZ::CORE:qr which was called 13 times, avg 792ns/call:
# once (2µs+0s) by Date::Manip::TZ::_zrx at line 1570
# once (1µs+0s) by Date::Manip::TZ::_zrx at line 1543
# once (1µs+0s) by Date::Manip::TZ::_zrx at line 1525
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1575
# once (900ns+0s) by Date::Manip::TZ::_zrx at line 1569
# once (800ns+0s) by Date::Manip::TZ::_zrx at line 1574
# once (800ns+0s) by Date::Manip::TZ::_zrx at line 1573
# once (800ns+0s) by Date::Manip::TZ::_zrx at line 1571
# once (500ns+0s) by Date::Manip::TZ::_zrx at line 1547
# once (500ns+0s) by Date::Manip::TZ::_zrx at line 1572
# once (500ns+0s) by Date::Manip::TZ::_zrx at line 1551
# once (300ns+0s) by Date::Manip::TZ::_zrx at line 1548
# once (300ns+0s) by Date::Manip::TZ::_zrx at line 1549 | |||||
# spent 10µs within Date::Manip::TZ::CORE:readline which was called 74 times, avg 138ns/call:
# 74 times (10µs+0s) by Date::Manip::TZ::_get_curr_zone at line 476, avg 138ns/call | |||||
# spent 9.50ms within Date::Manip::TZ::CORE:regcomp which was called 10 times, avg 950µs/call:
# once (2.66ms+0s) by Date::Manip::TZ::_zrx at line 1575
# once (1.95ms+0s) by Date::Manip::TZ::_zrx at line 1571
# once (1.58ms+0s) by Date::Manip::TZ::_zrx at line 1569
# once (1.56ms+0s) by Date::Manip::TZ::_zrx at line 1525
# once (460µs+0s) by Date::Manip::TZ::_zrx at line 1570
# once (445µs+0s) by Date::Manip::TZ::_zrx at line 1543
# once (375µs+0s) by Date::Manip::TZ::_zrx at line 1574
# once (371µs+0s) by Date::Manip::TZ::_zrx at line 1573
# once (56µs+0s) by Date::Manip::TZ::_zrx at line 1572
# once (35µs+0s) by Date::Manip::TZ::_zrx at line 1551 | |||||
sub Date::Manip::TZ::CORE:sort; # opcode | |||||
# spent 233µs within Date::Manip::TZ::CORE:subst which was called 5762 times, avg 40ns/call:
# 825 times (144µs+0s) by Date::Manip::TZ::_zrx at line 1516, avg 174ns/call
# 825 times (41µs+0s) by Date::Manip::TZ::_zrx at line 1517, avg 50ns/call
# 825 times (11µs+0s) by Date::Manip::TZ::_zrx at line 1518, avg 13ns/call
# 825 times (8µs+0s) by Date::Manip::TZ::_zrx at line 1520, avg 9ns/call
# 825 times (8µs+0s) by Date::Manip::TZ::_zrx at line 1519, avg 9ns/call
# 825 times (8µs+0s) by Date::Manip::TZ::_zrx at line 1521, avg 9ns/call
# 403 times (5µs+0s) by Date::Manip::TZ::_zrx at line 1538, avg 13ns/call
# 403 times (5µs+0s) by Date::Manip::TZ::_zrx at line 1539, avg 12ns/call
# once (2µ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 531
# once (300ns+0s) by Date::Manip::TZ::_get_curr_zone at line 511
# once (300ns+0s) by Date::Manip::TZ::_get_curr_zone at line 632 |