lib/Date/Manip/TZ.pm

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