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 171 ▶use Date::Manip::Obj;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 171 ▶use Date::Manip::TZ_Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 171 @ISA = qw(Date::Manip::Obj Date::Manip::TZ_Base);
17  
18 171 require 5.010000;
19 171 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 171 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 171 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 171 require Date::Manip::Zones;
24 171 ▶use Date::Manip::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 171 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 171 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 171 our $VERSION;
29 171 $VERSION='7.01';
30 171 ▶END { undef $VERSION; }
Subroutine END: called CC=1 SCAR=0.0
31  
32 # To get rid of a 'used only once' warnings.
33 171 ▶END {
Subroutine END: called CC=1 SCAR=0.0
34 171 my $tmp = \%Date::Manip::Zones::Module;
35 171 $tmp = \%Date::Manip::Zones::ZoneNames;
36 171 $tmp = \%Date::Manip::Zones::Alias;
37 171 $tmp = \%Date::Manip::Zones::Abbrev;
38 171 $tmp = \%Date::Manip::Zones::Offmod;
39 171 $tmp = $Date::Manip::Zones::FirstDate;
40 171 $tmp = $Date::Manip::Zones::LastDate;
41 171 $tmp = $Date::Manip::Zones::LastYear;
42 171 $tmp = $Date::Manip::Zones::TzcodeVersion;
43 171 $tmp = $Date::Manip::Zones::TzdataVersion;
44 }
45  
46 ########################################################################
47 # BASE METHODS
48 ########################################################################
49  
50 518 ▶sub _init {
Subroutine _init: called CC=4 SCAR=17.9
51 518 my($self) = @_;
52  
53 518 $$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 518 my $dmb = $$self{'base'};
98 518 my $os = $dmb->_os();
99  
100 518 ▶ if ($os eq 'Unix') {
Branch: 3 branches
BranchTrueFalseTotal
if ($os eq 'Unix') { } 518 0 518
elsif ($os eq 'Windows') { } 0 0 0
elsif ($os eq 'VMS') { } 0 0 0
101 518 $$self{'data'}{'path'} = '/bin:/usr/bin';
102 518 $$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 521 ▶sub _init_final {
Subroutine _init_final: called CC=1 SCAR=0.0
157 521 my($self) = @_;
158  
159 521 $self->_set_curr_zone();
160 }
161  
162 171 ▶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 1638 ▶sub _module {
Subroutine _module: called CC=2 SCAR=6.9
179 1638 my($self,$zone) = @_;
180 1638 ▶ return if (exists $$self{'data'}{'Zones'}{$zone}{'Loaded'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"data"}{"Zones"}{$zone}{"Loaded"} 0 1638 1638
181  
182 1638 my $mod = $$self{'data'}{'Module'}{$zone};
183 1638 eval "require Date::Manip::TZ::${mod}";
184 1638 my %dates = %{ "Date::Manip::TZ::${mod}::Dates" };
185 1638 my %last = %{ "Date::Manip::TZ::${mod}::LastRule" };
186 1638 $$self{'data'}{'Zones'}{$zone} =
187 {
188 'Dates' => { %dates },
189 'LastRule' => { %last },
190 'Loaded' => 1
191 };
192 }
193 171 ▶use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
194  
195 ########################################################################
196 # CHECKING/MODIFYING ZONEINFO DATA
197 ########################################################################
198  
199 48117 ▶sub _zone {
Subroutine _zone: called CC=3 SCAR=11.0
200 48117 my($self,$zone) = @_;
201 48117 $zone = lc($zone);
202  
203 48117 ▶ if (exists $$self{'data'}{'MyAlias'}{$zone}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'MyAlias'}{$zone}) { } 1 48116 48117
elsif (exists $self->{'data'}{'Alias'}{$zone}) { } 48066 50 48116
204 1 return $$self{'data'}{'MyAlias'}{$zone};
205 } elsif (exists $$self{'data'}{'Alias'}{$zone}) {
206 48066 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 521 ▶sub _set_curr_zone {
Subroutine _set_curr_zone: called CC=1 SCAR=0.0
391 521 my($self) = @_;
392 521 my $dmb = $$self{'base'};
393 521 my $currzone = $self->_get_curr_zone();
394  
395 521 $$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 521 ▶sub _get_curr_zone {
Subroutine _get_curr_zone: called CC=86 SCAR=79.8
402 521 my($self) = @_;
403 521 my $dmb = $$self{'base'};
404  
405 521 my $t = time;
406 521 my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t);
407 521 my $currzone = '';
408 521 ▶ my $dstflag = ($isdst ? 'dstonly' : 'stdonly');
Branch: 1 branch
BranchTrueFalseTotal
$isdst ? : 0 521 521
409  
410 521 my (@methods) = @{ $$self{'data'}{'methods'} };
411 521 ▶ my $debug = ($ENV{DATE_MANIP_DEBUG} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'DATE_MANIP_DEBUG'} ? : 0 521 521
412  
413 defined $$self{'data'}{'path'}
414 521 ▶ and local $ENV{PATH} = $$self{'data'}{'path'};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"data"}{"path"} and local $ENV{"PATH"} = $self->{"data"}{"path"} 521 0 521
415  
416 METHOD:
417 521 ▶ while (@methods) {
Branch: 1 branch
BranchTrueFalseTotal
if (@methods) 3527 0 3527
418 3527 my $method = shift(@methods);
419 3527 my @zone = ();
420  
421 3527 ▶ print "*** DEBUG *** METHOD: $method [" if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 3527 3527
422  
423 3527 ▶ if ($method eq 'main') {
Branch: 8 branches
BranchTrueFalseTotal
if ($method eq 'main') { } 521 3006 3527
elsif ($method eq 'env') { } 521 2485 3006
elsif ($method eq 'file') { } 1988 497 2485
elsif ($method eq 'tzdata') { } 0 497 497
elsif ($method eq 'command') { } 497 0 497
elsif ($method eq 'cmdfield') { } 0 0 0
elsif ($method eq 'gmtoff') { } 0 0 0
elsif ($method eq 'registry') { } 0 0 0
424  
425 521 ▶ if (! @methods) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@methods) 0 521 521
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 521 my $var = shift(@methods);
431 521 ▶ print "$var] " if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 521 521
432 171 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
433 521 my $val = ${ "::$var" };
434 171 ▶ use strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
435 521 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 521 521
436 0 push(@zone,$val);
437 0 ▶ print "$val\n" if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
438 } else {
439 521 ▶ print "undef\n" if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 521 521
440 }
441  
442 } elsif ($method eq 'env') {
443 521 ▶ if (@methods < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@methods < 2) 0 521 521
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 521 my $type = lc( shift(@methods) );
449 521 ▶ print "$type," if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 521 521
450  
451 521 ▶ if ($type ne 'zone' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "zone" and $type ne "offset") 0 521 521
Condition33%1/3
$type ne "zone" and $type ne "offset"
!ll&&!rl&&r
52100
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 521 my $var = shift(@methods);
459 521 ▶ print "$var] " if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 521 521
460 521 ▶ if (exists $ENV{$var}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{$var}) { } 24 497 521
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 497 ▶ print "undef\n" if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 497 497
474 }
475  
476 } elsif ($method eq 'file') {
477 1988 ▶ if (! @methods) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@methods) 0 1988 1988
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 1988 my $file = shift(@methods);
483 1988 ▶ print "$file] " if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1988 1988
484 1988 ▶ if (! -f $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 1988 0 1988
485 1988 ▶ print "not found\n" if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1988 1988
486 1988 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 497 ▶ if (! @methods) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@methods) 0 497 497
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 497 my $command = shift(@methods);
598 497 ▶ print "$command] " if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 497 497
599 497 my ($out) = _cmd($command);
600 497 ▶ push(@zone,$out) if ($out);
Branch: 1 branch
BranchTrueFalseTotal
if $out 497 0 497
601  
602 497 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 497 497
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 1539 ▶ while (@zone) {
Branch: 1 branch
BranchTrueFalseTotal
if (@zone) 521 1018 1539
675 521 my $zone = lc(shift(@zone));
676  
677 # OpenUNIX puts a colon at the start
678 521 $zone =~ s/^://;
679  
680 # If we got a zone name/alias
681 521 $currzone = $self->_zone($zone);
682 521 ▶ last METHOD if ($currzone);
Branch: 1 branch
BranchTrueFalseTotal
if $currzone 521 0 521
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 521 ▶ if (! $currzone) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($currzone) 0 521 521
698 0 carp "ERROR: Date::Manip unable to determine Time Zone. GMT will be used.";
699 0 $currzone = 'Etc/GMT';
700 }
701  
702 521 return $currzone;
703 }
704  
705 #######################
706 # The following section comes from the DateTime-TimeZone module
707  
708 {
709 171 my $want_content;
710 my $want_size;
711 171 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 171 ▶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 171 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
846 497 ▶sub _cmd {
Subroutine _cmd: called CC=2 SCAR=7.0
847 497 my($cmd) = @_;
848 497 local(*IN);
849 497 ▶ open(IN,"$cmd |") || return ();
Branch: 1 branch
BranchTrueFalseTotal
open IN, "$cmd |" or return () 497 0 497
850 497 my @out = <IN>;
851 497 close(IN);
852 497 chomp(@out);
853 497 return @out;
854 }
855 171 ▶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 565 ▶sub __zone {
Subroutine __zone: called CC=53 SCAR=40.2
935 565 my($self,$date,$offset,$zone,$abbrev,$dstflag) = @_;
936 565 my $dmb = $$self{'base'};
937  
938 #
939 # Determine the zones that match all data.
940 #
941  
942 565 my @zone;
943  
944 565 while (1) {
945  
946 # No information
947  
948 565 ▶ if (! $zone &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($zone or $abbrev or $offset) 3 562 565
Condition100%6/6
$zone or $abbrev or $offset
l!l&&r!l&&!r
494683
$zone or $abbrev
l!l&&r!l&&!r
37711771
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 565 ▶ $dstflag = "dst" if ($offset && @$date && ! $dstflag);
Branch: 1 branch
BranchTrueFalseTotal
if $offset and @$date and not $dstflag 70 495 565
Condition100%6/6
$offset and @$date and not $dstflag
!ll&&!rl&&r
494170
$offset and @$date
!ll&&!rl&&r
4831171
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 565 my(@isdst);
964 565 ▶ if ($dstflag eq 'stdonly') {
Branch: 3 branches
BranchTrueFalseTotal
if ($dstflag eq 'stdonly') { } 4 561 565
elsif ($dstflag eq 'dstonly') { } 4 557 561
elsif ($dstflag eq 'dst') { } 71 486 557
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 486 @isdst = (0,1);
972 }
973  
974 # We may pass in $zone and not $abbrev when it really should be
975 # $abbrev.
976  
977 565 ▶ if ($zone && ! $abbrev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone and not $abbrev) 377 188 565
Condition66%2/3
$zone and not $abbrev
!ll&&!rl&&r
1880377
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 377 ▶ if (exists $$self{'data'}{'Alias'}{$zone}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'Alias'}{$zone}) { } 377 0 377
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 565 ▶ if ($zone) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone) 377 188 565
990 my $z = (exists $$self{'data'}{'Alias'}{$zone} ?
991 377 ▶ $$self{'data'}{'Alias'}{$zone} : $zone);
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'data'}{'Alias'}{$zone} ? : 377 0 377
992 377 @zone = ($z);
993 }
994  
995 # $abbrev
996  
997 565 ▶ if ($abbrev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($abbrev) 117 448 565
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 565 ▶ if ($offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset) 82 483 565
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 562 ▶ if (@$date) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$date) 537 25 562
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 537 my @tmp;
1071 537 my $isdst = '';
1072 537 ▶ $isdst = 0 if ($dstflag eq 'stdonly');
Branch: 1 branch
BranchTrueFalseTotal
if $dstflag eq "stdonly" 0 537 537
1073 537 ▶ $isdst = 1 if ($dstflag eq 'dstonly');
Branch: 1 branch
BranchTrueFalseTotal
if $dstflag eq "dstonly" 0 537 537
1074  
1075 ZONE:
1076 537 foreach my $z (@zone) {
1077 4134 ▶ $self->_module($z) if (! exists $$self{'data'}{'Zones'}{$z}{'Loaded'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"data"}{"Zones"}{$z}{"Loaded"} 855 3279 4134
1078 4134 my $y = $$date[0];
1079 4134 my @periods = $self->_all_periods($z,$y);
1080  
1081 4134 foreach my $period (@periods) {
1082 7291 ▶ 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 5076 2215 7291
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
46284482215
$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
42543742663
$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
425403037
$abbrev ne "" and lc $abbrev ne lc $period->[4] or $offset ne "" and $offset ne $period->[2]
l!l&&r!l&&!r
197322813037
$abbrev ne "" and lc $abbrev ne lc $period->[4]
!ll&&!rl&&r
423010881973
$offset ne "" and $offset ne $period->[2]
!ll&&!rl&&r
156214752281
$isdst ne "" and $isdst ne $period->[5]
!ll&&!rl&&r
303700
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 2215 push(@tmp,$z);
1089 2215 next ZONE;
1090 }
1091 }
1092 537 @zone = @tmp;
1093 537 ▶ last if (! @zone);
Branch: 1 branch
BranchTrueFalseTotal
unless @zone 9 528 537
1094 }
1095  
1096 553 last;
1097 }
1098  
1099 # Return the value/list
1100  
1101 564 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 27 537 564
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 537 ▶ return '' if (! @zone);
Branch: 1 branch
BranchTrueFalseTotal
unless @zone 9 528 537
1110 528 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 3652 ▶ $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"data"}{"Zones"}{$zone}{"Loaded"} 594 3058 3652
1123  
1124 3652 foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) {
1125 173164 my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} };
1126 173164 foreach my $period (@periods) {
1127 333773 my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period;
1128 333773 ▶ next if (lc($abbrev) ne lc($abb) ||
Branch: 1 branch
BranchTrueFalseTotal
if lc $abbrev ne lc $abb or $isdst != $dst 331910 1863 333773
Condition100%3/3
lc $abbrev ne lc $abb or $isdst != $dst
l!l&&r!l&&!r
245674862361863
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 1863 push(@ret,$zone);
1131 1863 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 808 ▶ $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"data"}{"Zones"}{$zone}{"Loaded"} 126 682 808
1148  
1149 808 foreach my $y (sort keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) {
1150 52451 my @periods = @{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$y} };
1151 52451 foreach my $period (@periods) {
1152 102367 my($dateUT,$dateLT,$off,$offref,$abb,$dst,$endUT,$endLT) = @$period;
1153 102367 ▶ next if (lc($abbrev) ne lc($abb) ||
Branch: 1 branch
BranchTrueFalseTotal
if lc $abbrev ne lc $abb or $offset ne $off or $isdst != $dst 102181 186 102367
Condition100%6/6
lc $abbrev ne lc $abb or $offset ne $off or $isdst != $dst
l!l&&r!l&&!r
977624419186
lc $abbrev ne lc $abb or $offset ne $off
l!l&&r!l&&!r
9483829244605
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 186 push(@ret,$zone);
1157 186 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 222 ▶ push(@ret,$ele) if (exists $list2{$ele});
Branch: 1 branch
BranchTrueFalseTotal
if exists $list2{$ele} 183 39 222
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 1780 ▶ next if (exists $list1{$ele});
Branch: 1 branch
BranchTrueFalseTotal
if exists $list1{$ele} 492 1288 1780
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 34384 ▶sub _all_periods {
Subroutine _all_periods: called CC=11 SCAR=24.0
1222 34384 my($self,$zone,$year) = @_;
1223 34384 $year += 0;
1224  
1225 34384 ▶ if (! exists $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}{"Zones"}{$zone}{"AllDates"}{$year}) 3163 31221 34384
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 3163 my($ym1,$ym0);
1234 3163 ▶ if ($year > $$self{'data'}{'LastYear'} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($year > $self->{'data'}{'LastYear'} and exists $self->{'data'}{'Zones'}{$zone}{'LastRule'}{'zone'}) { } 5 3158 3163
Condition100%3/3
$year > $self->{"data"}{"LastYear"} and exists $self->{"data"}{"Zones"}{$zone}{"LastRule"}{"zone"}
!ll&&!rl&&r
315445
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 3158 foreach my $y (sort { $a <=> $b }
1241 3158 keys %{ $$self{'data'}{'Zones'}{$zone}{'Dates'} }) {
1242 116972 ▶ if ($y < $year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $year) 114736 2236 116972
1243 114736 $ym1 = $y;
1244 114736 next;
1245 }
1246 2236 ▶ $ym0 = $year if ($year == $y);
Branch: 1 branch
BranchTrueFalseTotal
if $year == $y 1907 329 2236
1247 2236 last;
1248 }
1249 }
1250 3163 ▶ $ym1 = 0 if (! $ym1);
Branch: 1 branch
BranchTrueFalseTotal
unless $ym1 3 3160 3163
1251  
1252 #
1253 # Get the periods from the prior year. The last one is used (any others
1254 # are discarded).
1255 #
1256  
1257 3163 my(@periods);
1258  
1259 # $ym1 will be 0 in 0001
1260 3163 ▶ if ($ym1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ym1) 3160 3 3163
1261 3160 my @tmp = $self->_periods($zone,$ym1);
1262 3160 ▶ push(@periods,pop(@tmp)) if (@tmp);
Branch: 1 branch
BranchTrueFalseTotal
if @tmp 3160 0 3160
1263 }
1264  
1265 #
1266 # Add on any periods from the current year.
1267 #
1268  
1269 3163 ▶ if ($ym0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ym0) 1912 1251 3163
1270 1912 push(@periods,$self->_periods($zone,$year));
1271 }
1272  
1273 3163 $$self{'data'}{'Zones'}{$zone}{'AllDates'}{$year} = [ @periods ];
1274 }
1275  
1276 34384 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 5082 ▶sub _periods {
Subroutine _periods: called CC=4 SCAR=13.9
1319 5082 my($self,$zone,$year) = @_;
1320 5082 $year += 0;
1321  
1322 5082 ▶ if (! exists $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}{"Zones"}{$zone}{"Dates"}{$year}) 12 5070 5082
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 5082 my @ret;
1335 5082 foreach my $ele (@{ $$self{'data'}{'Zones'}{$zone}{'Dates'}{$year} }) {
1336 push(@ret,
1337 9195 [ [ @{$$ele[0]} ],[ @{$$ele[1]} ],$$ele[2],[ @{$$ele[3]} ],$$ele[4],$$ele[5],
1338 9195 [ @{$$ele[6]} ],[ @{$$ele[7]} ],$$ele[8],$$ele[9],$$ele[10],$$ele[11] ]);
1339 }
1340 5082 return @ret;
1341 }
1342  
1343 30243 ▶sub date_period {
Subroutine date_period: called CC=20 SCAR=31.5
Pod documented
1344 30243 my($self,$date,$zone,$wallclock,$isdst) = @_;
1345 30243 ▶ $wallclock = 0 if (! $wallclock);
Branch: 1 branch
BranchTrueFalseTotal
unless $wallclock 5549 24694 30243
1346 30243 ▶ $isdst = 0 if (! $isdst);
Branch: 1 branch
BranchTrueFalseTotal
unless $isdst 29961 282 30243
1347  
1348 30243 my $z = $self->_zone($zone);
1349 30243 ▶ if (! $z) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($z) 0 30243 30243
1350 0 carp "ERROR: [date_period] Invalid zone: $zone";
1351 0 return;
1352 }
1353 30243 $zone = $z;
1354 30243 ▶ $self->_module($zone) if (! exists $$self{'data'}{'Zones'}{$zone}{'Loaded'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"data"}{"Zones"}{$zone}{"Loaded"} 62 30181 30243
1355  
1356 30243 my $dmb = $$self{'base'};
1357 30243 my @date = @$date;
1358 30243 my $year = $date[0];
1359 30243 my $dates= $dmb->_date_fields(@$date);
1360 30243 ▶ return () if ($year < 0 || $year > 9999);
Branch: 1 branch
BranchTrueFalseTotal
if $year < 0 or $year > 9999 0 30243 30243
Condition33%1/3
$year < 0 or $year > 9999
l!l&&r!l&&!r
0030243
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 30243 ▶ if ($wallclock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wallclock) { } 24694 5549 30243
1363 # A wallclock date
1364  
1365 24694 my @period = $self->_all_periods($zone,$year);
1366 24694 my $beg = $period[0]->[9];
1367 24694 my $end = $period[-1]->[11];
1368 24694 ▶ if (($dates cmp $beg) == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if (($dates cmp $beg) == -1) { } 0 24694 24694
elsif (($dates cmp $end) == 1) { } 0 24694 24694
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 24694 my(@per);
1375 24694 foreach my $period (@period) {
1376 70061 my($begUT,$begLT,$offsetstr,$offset,$abbrev,$dst,$endUT,$endLT,
1377 $begUTs,$begLTs,$endUTs,$endLTs) = @$period;
1378 70061 ▶ if (($dates cmp $begLTs) != -1 && ($dates cmp $endLTs) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (($dates cmp $begLTs) != -1 and ($dates cmp $endLTs) != 1) 24726 45335 70061
Condition100%3/3
($dates cmp $begLTs) != -1 and ($dates cmp $endLTs) != 1
!ll&&!rl&&r
323661296924726
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 24726 push(@per,$period);
1380 }
1381 }
1382  
1383 24694 ▶ if ($#per == -1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($#per == -1) { } 8 24686 24694
elsif ($#per == 0) { } 24646 40 24686
elsif ($#per == 1) { } 40 0 40
1384 8 return ();
1385 } elsif ($#per == 0) {
1386 24646 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 2862 ▶sub convert_to_gmt {
Subroutine convert_to_gmt: called CC=3 SCAR=11.6
Pod documented
1508 2862 my($self,$date,@arg) = @_;
1509 2862 my($err,$from,$isdst) = _convert_args('convert_to_gmt',@arg);
1510 2862 ▶ return (1) if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 2862 2862
1511  
1512 2862 my $dmb = $$self{'base'};
1513  
1514 2862 ▶ if (! $from) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from) 0 2862 2862
1515 0 $from = $self->_now('tz',1);
1516 }
1517 2862 $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 2901 ▶sub _convert_args {
Subroutine _convert_args: called CC=6 SCAR=19.6
1560 2901 my($caller,@args) = @_;
1561  
1562 2901 ▶ if ($#args == -1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($#args == -1) { } 7 2894 2901
elsif ($#args == 0) { } 179 2715 2894
elsif ($#args == 1) { } 2715 0 2715
1563 7 return (0,'',0);
1564 } elsif ($#args == 0) {
1565 179 ▶ if ($args[0] eq '0' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] eq '0' or $args[0] eq '1') { } 0 179 179
Condition33%1/3
$args[0] eq 0 or $args[0] eq 1
l!l&&r!l&&!r
00179
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 179 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 5738 ▶sub _convert {
Subroutine _convert: called CC=10 SCAR=23.3
1579 5738 my($self,$caller,$date,$from,$to,$isdst) = @_;
1580 5738 my $dmb = $$self{'base'};
1581  
1582 # Handle $date as a reference and a string
1583 5738 my (@date);
1584 5738 ▶ if (ref($date)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $date) { } 5737 1 5738
1585 5737 @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 5738 ▶ if ($from ne $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from ne $to) 5738 0 5738
1594 5738 my $tmp = $self->_zone($from);
1595 5738 ▶ if (! $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp) 0 5738 5738
1596 0 return (2);
1597 }
1598 5738 $from = $tmp;
1599  
1600 5738 $tmp = $self->_zone($to);
1601 5738 ▶ if (! $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp) 0 5738 5738
1602 0 return (3);
1603 }
1604 5738 $to = $tmp;
1605 }
1606  
1607 5738 ▶ if ($from eq $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from eq $to) 190 5548 5738
1608 190 my $per = $self->date_period($date,$from,1,$isdst);
1609 190 my $offset = $$per[3];
1610 190 my $abb = $$per[4];
1611 190 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 556 ▶sub _zrx {
Subroutine _zrx: called CC=6 SCAR=18.0
1665 556 my($self,$re) = @_;
1666 556 ▶ return $$self{'data'}{$re} if (defined $$self{'data'}{$re});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"data"}{$re} 474 82 556
1667  
1668 # Zone name
1669  
1670 82 my @zone;
1671 82 ▶ if (exists $ENV{'DATE_MANIP_DEBUG_ZONES'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{'DATE_MANIP_DEBUG_ZONES'}) { } 0 82 82
1672 0 @zone = split(/\s+/,$ENV{'DATE_MANIP_DEBUG_ZONES'});
1673 } else {
1674 82 @zone = (keys %{ $$self{'data'}{'Alias'} },
1675 82 keys %{ $$self{'data'}{'MyAlias'} });
1676 }
1677 82 @zone = sort _sortByLength(@zone);
1678 82 foreach my $zone (@zone) {
1679 69617 $zone =~ s/\057/\\057/g; # /
1680 69617 $zone =~ s/\055/\\055/g; # -
1681 69617 $zone =~ s/\056/\\056/g; # .
1682 69617 $zone =~ s/\050/\\050/g; # (
1683 69617 $zone =~ s/\051/\\051/g; # )
1684 69617 $zone =~ s/\053/\\053/g; # +
1685 }
1686  
1687 82 my $zone = join('|',@zone);
1688 82 $zone = qr/(?<zone>$zone)/i;
1689  
1690 # Abbreviation
1691  
1692 82 my @abb;
1693 82 ▶ if (exists $ENV{'DATE_MANIP_DEBUG_ABBREVS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{'DATE_MANIP_DEBUG_ABBREVS'}) { } 0 82 82
1694 0 @abb = split(/\s+/,$ENV{'DATE_MANIP_DEBUG_ABBREVS'});
1695 } else {
1696 82 @abb = (keys %{ $$self{'data'}{'Abbrev'} },
1697 82 keys %{ $$self{'data'}{'MyAbbrev'} });
1698 }
1699 82 @abb = sort _sortByLength(@abb);
1700 82 foreach my $abb (@abb) {
1701 13614 $abb =~ s/\055/\\055/g; # -
1702 13614 $abb =~ s/\053/\\053/g; # +
1703 }
1704  
1705 82 my $abb = join('|',@abb);
1706 82 $abb = qr/(?<abb>$abb)/i;
1707  
1708 # Offset (+HH, +HHMM, +HH:MM, +HH:MM:SS, +HHMMSS)
1709  
1710 82 my($hr) = qr/(?:[0-1][0-9]|2[0-3])/; # 00 - 23
1711 82 my($mn) = qr/(?:[0-5][0-9])/; # 00 - 59
1712 82 my($ss) = qr/(?:[0-5][0-9])/; # 00 - 59
1713  
1714 82 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 82 $$self{'data'}{'namerx'} = qr/(?<tzstring>$zone)/;
1733 82 $$self{'data'}{'abbrx'} = qr/(?<tzstring>$abb)/;
1734 82 $$self{'data'}{'zonerx'} = qr/(?<tzstring>(?:$abb|$zone))/;
1735 82 $$self{'data'}{'offrx'} = qr/(?<tzstring>$off)/;
1736 82 $$self{'data'}{'offabbrx'} = qr/(?<tzstring>$off\s+$abb)/;
1737 82 $$self{'data'}{'offparrx'} = qr/(?<tzstring>$off\s*\($abb\))/;
1738 82 $$self{'data'}{'zrx'} = qr/(?<tzstring>(?:$off\s*\($abb\)|$off\s+$abb|$abb|$zone|$off))/;
1739  
1740 82 return $$self{'data'}{$re};
1741 }
1742  
1743 # This sorts from longest to shortest element
1744 #
1745 171 ▶no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
1746 637538 ▶sub _sortByLength {
Subroutine _sortByLength: called CC=1 SCAR=0.0
1747 637538 return (length $b <=> length $a);
1748 }
1749 171 ▶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 389 ▶sub _config_var_tz {
Subroutine _config_var_tz: called CC=8 SCAR=22.8
1759 389 my($self,$var,$val) = @_;
1760  
1761 389 ▶ if ($var eq 'tz') {
Branch: 4 branches
BranchTrueFalseTotal
if ($var eq 'tz') { } 0 389 389
elsif ($var eq 'setdate') { } 172 217 389
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 172 my $err = $self->_config_var_setdate($val,0);
1769 172 ▶ return if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 172 172
1770 172 $$self{'data'}{'sections'}{'conf'}{'forcedate'} = 0;
1771 172 $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 362 my $base = $$self{'base'};
1785 362 $$base{'data'}{'sections'}{'conf'}{$var} = $val;
1786 362 return;
1787 }
1788  
1789 362 ▶sub _config_var_setdate {
Subroutine _config_var_setdate: called CC=26 SCAR=44.3
1790 362 my($self,$val,$force) = @_;
1791 362 my $base = $$self{'base'};
1792  
1793 362 my $dstrx = qr/(?:,\s*(stdonly|dstonly|std|dst))?/i;
1794 362 my $zonrx = qr/,\s*(.+)/;
1795 362 my $da1rx = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d):(\d\d):(\d\d)/;
1796 362 my $da2rx = qr/(\d\d\d\d)\-(\d\d)\-(\d\d)\-(\d\d):(\d\d):(\d\d)/;
1797 362 my $time = time;
1798  
1799 362 my($op,$date,$dstflag,$zone,@date,$offset,$abb);
1800  
1801 #
1802 # Parse the argument
1803 #
1804  
1805 362 ▶ if ($val =~ /^now${dstrx}${zonrx}$/oi) {
Branch: 5 branches
BranchTrueFalseTotal
if ($val =~ /^now$dstrx$zonrx$/io) { } 272 90 362
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 272 $op = 'nowzone';
1811 272 ($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 362 ▶ $dstflag = 'std' if (! $dstflag);
Branch: 1 branch
BranchTrueFalseTotal
unless $dstflag 362 0 362
1857  
1858 #
1859 # Get the date we're setting 'now' to
1860 #
1861  
1862 362 ▶ if ($op eq 'nowzone') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq 'nowzone') { } 272 90 362
elsif ($op eq 'zone') { } 0 90 90
1863 # Use the system localtime
1864  
1865 272 my($s,$mn,$h,$d,$m,$y) = localtime($time);
1866 272 $y += 1900;
1867 272 $m++;
1868 272 $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 362 ▶ if ($zone) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone) { } 362 0 362
1884 362 my ($err,@args);
1885 362 my $dmb = $$self{'base'};
1886 362 ▶ $date = [] if (! defined $date);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 362 362
1887 362 $zone = $self->__zone($date,'',lc($zone),'',lc($dstflag));
1888 362 ▶ if (! $zone) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zone) 0 362 362
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 362 my($isdst,@isdst);
1902 362 ▶ if ($dstflag eq 'std') {
Branch: 3 branches
BranchTrueFalseTotal
if ($dstflag eq 'std') { } 362 0 362
elsif ($dstflag eq 'stdonly') { } 0 0 0
elsif ($dstflag eq 'dst') { } 0 0 0
1903 362 @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 362 ▶ if ($op eq 'nowzone' ||
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq 'nowzone' or $op eq 'datezone' or $op eq 'date') { } 362 0 362
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
36200
$op eq "nowzone" or $op eq "datezone"
l!l&&r!l&&!r
272900
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 362 my $per;
1918 362 foreach my $dst (@isdst) {
1919 724 ▶ next if ($per);
Branch: 1 branch
BranchTrueFalseTotal
if $per 362 362 724
1920 362 $per = $self->date_period($date,$zone,1,$dst);
1921 }
1922  
1923 362 ▶ if (! $per) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($per) 0 362 362
1924 0 carp "ERROR: [config_var] invalid date: SetDate: $date, $zone";
1925 0 return 1;
1926 }
1927 362 $isdst = $$per[5];
1928 362 $abb = $$per[4];
1929 362 $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 362 $$base{'data'}{'now'}{'date'} = $date;
1947 362 $$base{'data'}{'now'}{'tz'} = $self->_zone($zone);
1948 362 $$base{'data'}{'now'}{'isdst'} = $isdst;
1949 362 $$base{'data'}{'now'}{'abb'} = $abb;
1950 362 $$base{'data'}{'now'}{'offset'} = $offset;
1951  
1952 #
1953 # Treate SetDate/ForceDate
1954 #
1955  
1956 362 ▶ if ($force) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force) { } 190 172 362
1957 190 $$base{'data'}{'now'}{'force'} = 1;
1958 190 $$base{'data'}{'now'}{'set'} = 0;
1959 } else {
1960 172 $$base{'data'}{'now'}{'force'} = 0;
1961 172 $$base{'data'}{'now'}{'set'} = 1;
1962 172 $$base{'data'}{'now'}{'setsecs'} = $time;
1963 172 my($err,$setdate) = $self->convert_to_gmt($date,$zone);
1964 172 $$base{'data'}{'now'}{'setdate'} = $setdate;
1965 }
1966  
1967 362 return 0;
1968 }
1969  
1970 171 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 »