TimeZone.pm

filter: Statementstmt 43.2% 131 / 303 Branchbran 34.3% 46 / 134 Conditioncond 21.5% 11 / 51 MC/DCmcdc 9.6% 3 / 31 Subroutinesub 61.0% 36 / 59 Podpod 86.9% 20 / 23 totaltotal 41.1% 247 / 601 CC 88 SCAR 44.5
CC
88
Cov
39%
_spans_binary_search
342.0
new
235.6
_generate_spans_until_match
110.0
CRAP 85.9
« TimeZone/OlsonDB/Observance.pm ↑ Summary TimeZone/OlsonDB/Change.pm »
1 package DateTime::TimeZone;
2  
3 3 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '2.72';
10  
11 # Note that while we make use of DateTime::Duration in this module if we
12 # actually try to load it here all hell breaks loose with circular
13 # dependencies.
14 3 ▶use DateTime::TimeZone::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use DateTime::TimeZone::Floating;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use DateTime::TimeZone::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use DateTime::TimeZone::OffsetOnly;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use DateTime::TimeZone::OlsonDB::Change;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use DateTime::TimeZone::UTC;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Module::Runtime qw( require_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Params::ValidationCompiler 0.13 qw( validation_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Specio::Library::Builtins;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Specio::Library::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 ## no critic (ValuesAndExpressions::ProhibitConstantPragma)
27 3 ▶use constant INFINITY => 100**1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use constant NEG_INFINITY => -1 * ( 100**1000 );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # the offsets for each span element
31 3 ▶use constant UTC_START => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶use constant UTC_END => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use constant LOCAL_START => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use constant LOCAL_END => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use constant OFFSET => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use constant IS_DST => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use constant SHORT_NAME => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 3 my %SpecialName = map { $_ => 1 }
40 qw( EST MST HST CET EET MET WET EST5EDT CST6CDT MST7MDT PST8PDT );
41  
42 {
43 3 my $validator = validation_for(
44 name => '_check_new_params',
45 name_is_optional => 1,
46 params => {
47 name => {
48 type => t('NonEmptyStr'),
49 },
50 },
51 );
52  
53 1 ▶ sub new {
Subroutine new: called CC=19 SCAR=54.6
Pod documented
54 1 shift;
55 1 my %p = $validator->(@_);
56  
57 1 ▶ if ( exists $DateTime::TimeZone::Catalog::LINKS{ $p{name} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $DateTime::TimeZone::Catalog::LINKS{$p{'name'}}) { } 0 1 1
elsif (exists $DateTime::TimeZone::Catalog::LINKS{uc $p{'name'}}) { } 0 1 1
58 0 $p{name} = $DateTime::TimeZone::Catalog::LINKS{ $p{name} };
59 }
60 elsif ( exists $DateTime::TimeZone::Catalog::LINKS{ uc $p{name} } ) {
61 0 $p{name} = $DateTime::TimeZone::Catalog::LINKS{ uc $p{name} };
62 }
63  
64 1 ▶ unless ( $p{name} =~ m{/}
Branch: 1 branch
BranchTrueFalseTotal
unless ($p{"name"} =~ m[/] or $SpecialName{$p{"name"}}) 1 0 1
Condition33%1/3
$p{"name"} =~ m[/] or $SpecialName{$p{"name"}}
l!l&&r!l&&!r
001
MC/DC0%0/2
$p{"name"} =~ m[/] or $SpecialName{$p{"name"}}
$p{"name"} =~ m[/] $SpecialName{$p{"name"}}
Truth table33%1/3
A or B
A= $p{"name"} =~ m[/]B= $SpecialName{$p{"name"}}
ABresult
1X1
011
000
65 || $SpecialName{ $p{name} } ) {
66 1 ▶ if ( $p{name} eq 'floating' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"name"} eq "floating") 0 1 1
67 0 return DateTime::TimeZone::Floating->instance;
68 }
69  
70 1 ▶ if ( $p{name} eq 'local' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"name"} eq "local") 1 0 1
71 1 return DateTime::TimeZone::Local->TimeZone();
72 }
73  
74 0 ▶ if ( $p{name} eq 'UTC' || $p{name} eq 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"name"} eq "UTC" or $p{"name"} eq "Z") 0 0 0
Condition0%0/3
$p{"name"} eq "UTC" or $p{"name"} eq "Z"
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"name"} eq "UTC" or $p{"name"} eq "Z"
$p{"name"} eq "UTC" $p{"name"} eq "Z"
Truth table0%0/3
A or B
A= $p{"name"} eq "UTC"B= $p{"name"} eq "Z"
ABresult
1X1
011
000
75 0 return DateTime::TimeZone::UTC->instance;
76 }
77  
78 0 return DateTime::TimeZone::OffsetOnly->new( offset => $p{name} );
79 }
80  
81 0 ▶ if ( $p{name} =~ m{Etc/(?:GMT|UTC)(\+|-)(\d{1,2})}i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"name"} =~ m[Etc/(?:GMT|UTC)(\+|-)(\d{1,2})]i) 0 0 0
82  
83 # Etc/GMT+4 is actually UTC-4. For more info, see
84 # https://data.iana.org/time-zones/tzdb/etcetera
85 0 ▶ my $sign = $1 eq '-' ? '+' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' ? : 0 0 0
86 0 my $hours = $2;
87 0 ▶ die "The timezone '$p{name}' is an invalid name.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $hours <= 14 0 0 0
88 unless $hours <= 14;
89 0 return DateTime::TimeZone::OffsetOnly->new(
90 offset => "${sign}${hours}:00" );
91 }
92  
93 0 my $subclass = $p{name};
94 0 $subclass =~ s{/}{::}g;
95 0 $subclass =~ s/-(\d)/_Minus$1/;
96 0 $subclass =~ s/\+/_Plus/;
97 0 $subclass =~ s/-/_/g;
98  
99 0 my $real_class = "DateTime::TimeZone::$subclass";
100  
101 0 ▶ die "The timezone '$p{name}' is an invalid name.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $real_class =~ /^\w+(::\w+)*$/ 0 0 0
102 unless $real_class =~ /^\w+(::\w+)*$/;
103  
104 0 ▶ unless ( $real_class->can('instance') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($real_class->can("instance")) 0 0 0
105 0 ($real_class)
106 = $real_class =~ m{\A([a-zA-Z0-9_]+(?:::[a-zA-Z0-9_]+)*)\z};
107  
108 0 my $e;
109 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 ## no critic (Variables::RequireInitializationForLocalVars)
111 0 local $SIG{__DIE__};
112 0 require_module($real_class);
113 }
114 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
115 0 $e = $_;
116 0 };
117  
118 0 ▶ if ($e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 0 0 0
119 0 my $regex = join '.', split /::/, $real_class;
120 0 $regex .= '\\.pm';
121  
122 0 ▶ if ( $e =~ /^Can't locate $regex/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /^Can't locate $regex/i) { } 0 0 0
123 0 die
124 "The timezone '$p{name}' could not be loaded, or is an invalid name.\n";
125 }
126 else {
127 0 die $e;
128 }
129 }
130 }
131  
132 0 my $zone = $real_class->instance( name => $p{name}, is_olson => 1 );
133  
134 0 ▶ if ( $zone->is_olson() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone->is_olson) 0 0 0
135 0 ▶ my $object_version
Branch: 1 branch
BranchTrueFalseTotal
$zone->can('olson_version') ? : 0 0 0
136 = $zone->can('olson_version')
137 ? $zone->olson_version()
138 : 'unknown';
139 0 my $catalog_version = DateTime::TimeZone::Catalog->OlsonVersion();
140  
141 0 ▶ if ( $object_version ne $catalog_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_version ne $catalog_version) 0 0 0
142 0 warn
143 "Loaded $real_class, which is from a different version ($object_version) of the Olson database than this installation of DateTime::TimeZone ($catalog_version).\n";
144 }
145 }
146  
147 0 return $zone;
148 }
149 }
150  
151 {
152 3 my $validator = validation_for(
153 name => '_check_init_params',
154 name_is_optional => 1,
155 params => {
156 name => {
157 type => t('NonEmptyStr'),
158 },
159 spans => {
160 type => t('ArrayRef'),
161 },
162 is_olson => {
163 type => t('Bool'),
164 default => 0,
165 },
166 },
167 );
168  
169 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
170 0 ▶ sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
171 0 my $class = shift;
172 0 my %p = $validator->(@_);
173  
174 my $self = bless {
175 name => $p{name},
176 spans => $p{spans},
177 is_olson => $p{is_olson},
178 0 }, $class;
179  
180 0 foreach my $k (qw( last_offset last_observance rules max_year )) {
181 0 my $m = "_$k";
182 0 ▶ $self->{$k} = $self->$m() if $self->can($m);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($m) 0 0 0
183 }
184  
185 0 return $self;
186 }
187 ## use critic
188 }
189  
190 0 ▶sub is_olson { $_[0]->{is_olson} }
Subroutine is_olson: not called CC=1 SCAR=1.2
Pod documented
191  
192 0 ▶sub is_dst_for_datetime {
Subroutine is_dst_for_datetime: not called CC=1 SCAR=6.9
Pod documented
193 0 my $self = shift;
194  
195 0 my $span = $self->_span_for_datetime( 'utc', $_[0] );
196  
197 0 return $span->[IS_DST];
198 }
199  
200 0 ▶sub offset_for_datetime {
Subroutine offset_for_datetime: not called CC=1 SCAR=6.9
Pod documented
201 0 my $self = shift;
202  
203 0 my $span = $self->_span_for_datetime( 'utc', $_[0] );
204  
205 0 return $span->[OFFSET];
206 }
207  
208 0 ▶sub offset_for_local_datetime {
Subroutine offset_for_local_datetime: not called CC=1 SCAR=6.9
Pod documented
209 0 my $self = shift;
210  
211 0 my $span = $self->_span_for_datetime( 'local', $_[0] );
212  
213 0 return $span->[OFFSET];
214 }
215  
216 0 ▶sub short_name_for_datetime {
Subroutine short_name_for_datetime: not called CC=1 SCAR=6.9
Pod documented
217 0 my $self = shift;
218  
219 0 my $span = $self->_span_for_datetime( 'utc', $_[0] );
220  
221 0 return $span->[SHORT_NAME];
222 }
223  
224 0 ▶sub _span_for_datetime {
Subroutine _span_for_datetime: not called CC=5 SCAR=34.0
225 0 my $self = shift;
226 0 my $type = shift;
227 0 my $dt = shift;
228  
229 0 my $method = $type . '_rd_as_seconds';
230  
231 0 ▶ my $end = $type eq 'utc' ? UTC_END : LOCAL_END;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'utc' ? : 0 0 0
232  
233 0 my $span;
234 0 my $seconds = $dt->$method();
235 0 ▶ if ( $seconds < $self->max_span->[$end] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seconds < $self->max_span->[$end]) { } 0 0 0
236 0 $span = $self->_spans_binary_search( $type, $seconds );
237 }
238 else {
239 0 my $until_year = $dt->utc_year + 1;
240 0 $span = $self->_generate_spans_until_match(
241 $until_year, $seconds,
242 $type
243 );
244 }
245  
246 # This means someone gave a local time that doesn't exist
247 # (like during a transition into savings time)
248 0 ▶ unless ( defined $span ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $span) 0 0 0
249 0 my $err = 'Invalid local time for date';
250 0 ▶ $err .= q{ } . $dt->iso8601 if $type eq 'utc';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "utc" 0 0 0
251 0 $err .= ' in time zone: ' . $self->name;
252 0 $err .= "\n";
253  
254 0 die $err;
255 }
256  
257 0 return $span;
258 }
259  
260 0 ▶sub _spans_binary_search {
Subroutine _spans_binary_search: not called CC=18 SCAR=58.3
261 0 my $self = shift;
262 0 my ( $type, $seconds ) = @_;
263  
264 0 my ( $start, $end ) = _keys_for_type($type);
265  
266 0 my $min = 0;
267 0 my $max = scalar @{ $self->{spans} } + 1;
268 0 my $i = int( $max / 2 );
269  
270 # special case for when there are only 2 spans
271 0 ▶ $i++ if $max % 2 && $max != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $max % 2 and $max != 3 0 0 0
Condition0%0/3
$max % 2 and $max != 3
!ll&&!rl&&r
000
MC/DC0%0/2
$max % 2 and $max != 3
$max % 2 $max != 3
Truth table0%0/3
A and B
A= $max % 2B= $max != 3
ABresult
0X0
100
111
272  
273 0 ▶ $i = 0 if @{ $self->{spans} } == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"spans"};} == 1 0 0 0
274  
275 0 while (1) {
276 0 my $current = $self->{spans}[$i];
277  
278 0 ▶ if ( $seconds < $current->[$start] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($seconds < $current->[$start]) { } 0 0 0
elsif ($seconds >= $current->[$end]) { } 0 0 0
279 0 $max = $i;
280 0 my $c = int( ( $i - $min ) / 2 );
281 0 ▶ $c ||= 1;
Condition0%0/2
$c ||= 1
l!l
00
MC/DC0%0/1
$c ||= 1
$c
Truth table0%0/2
A
A= $c
Aresult
11
00
282  
283 0 $i -= $c;
284  
285 0 ▶ return if $i < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $i < $min 0 0 0
286 }
287 elsif ( $seconds >= $current->[$end] ) {
288 0 $min = $i;
289 0 my $c = int( ( $max - $i ) / 2 );
290 0 ▶ $c ||= 1;
Condition0%0/2
$c ||= 1
l!l
00
MC/DC0%0/1
$c ||= 1
$c
Truth table0%0/2
A
A= $c
Aresult
11
00
291  
292 0 $i += $c;
293  
294 0 ▶ return if $i >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $max 0 0 0
295 }
296 else {
297  
298 # Special case for overlapping ranges because of DST and
299 # other weirdness (like Alaska's change when bought from
300 # Russia by the US). Always prefer latest span.
301 0 ▶ if ( $current->[IS_DST] && $type eq 'local' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current->[5] and $type eq "local") 0 0 0
Condition0%0/3
$current->[5] and $type eq "local"
!ll&&!rl&&r
000
MC/DC0%0/2
$current->[5] and $type eq "local"
$current->[5] $type eq "local"
Truth table0%0/3
A and B
A= $current->[5]B= $type eq "local"
ABresult
0X0
100
111
302  
303 # Asia/Dhaka in 2009j goes into DST without any known
304 # end-of-DST date (wtf, Bangladesh).
305 0 ▶ return $current if $current->[UTC_END] == INFINITY;
Branch: 1 branch
BranchTrueFalseTotal
if $current->[1] == "Inf" 0 0 0
306  
307 0 my $next = $self->{spans}[ $i + 1 ];
308  
309 # Sometimes we will get here and the span we're
310 # looking at is the last that's been generated so far.
311 # We need to try to generate one more or else we run
312 # out.
313 0 ▶ $next ||= $self->_generate_next_span;
Condition0%0/3
$next ||= $self->_generate_next_span
l!l&&r!l&&!r
000
MC/DC0%0/2
$next ||= $self->_generate_next_span
$next $self->_generate_next_span
Truth table0%0/3
A ||= B
A= $nextB= $self->_generate_next_span
ABresult
1X1
011
000
314  
315 0 ▶ die "No next span in $self->{max_year}" unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 0 0
316  
317 0 ▶ if ( ( !$next->[IS_DST] )
Branch: 1 branch
BranchTrueFalseTotal
if (not $next->[5] and $next->[$start] <= $seconds and $seconds <= $next->[$end]) 0 0 0
Condition0%0/6
not $next->[5] and $next->[$start] <= $seconds and $seconds <= $next->[$end]
!ll&&!rl&&r
000
not $next->[5] and $next->[$start] <= $seconds
!ll&&!rl&&r
000
MC/DC0%0/3
not $next->[5] and $next->[$start] <= $seconds and $seconds <= $next->[$end]
not $next->[5] $next->[$start] <= $seconds $seconds <= $next->[$end]
Truth table0%0/4
not(A) and B and C
A= not $next->[5]B= $next->[$start] <= $secondsC= $seconds <= $next->[$end]
ABCresult
0XX0
10X0
1100
1111
318 && $next->[$start] <= $seconds
319 && $seconds <= $next->[$end] ) {
320 0 return $next;
321 }
322 }
323  
324 0 return $current;
325 }
326 }
327 }
328  
329 0 ▶sub _generate_next_span {
Subroutine _generate_next_span: not called CC=1 SCAR=6.9
330 0 my $self = shift;
331  
332 0 my $last_idx = $#{ $self->{spans} };
333  
334 0 my $max_span = $self->max_span;
335  
336 # Kind of a hack, but AFAIK there are no zones where it takes
337 # _more_ than a year for a _future_ time zone change to occur, so
338 # by looking two years out we can ensure that we will find at
339 # least one more span. Of course, I will no doubt be proved wrong
340 # and this will cause errors.
341 $self->_generate_spans_until_match(
342 0 $self->{max_year} + 2,
343 $max_span->[UTC_END] + ( 366 * 86400 ), 'utc'
344 );
345  
346 0 return $self->{spans}[ $last_idx + 1 ];
347 }
348  
349 0 ▶sub _generate_spans_until_match {
Subroutine _generate_spans_until_match: not called CC=10 SCAR=47.0
350 0 my $self = shift;
351 0 my $generate_until_year = shift;
352 0 my $seconds = shift;
353 0 my $type = shift;
354  
355 0 my @changes;
356 0 my @rules = @{ $self->_rules };
357 0 foreach my $year ( $self->{max_year} .. $generate_until_year ) {
358 ## no critic (ControlStructures::ProhibitCStyleForLoops)
359 0 ▶ for ( my $x = 0; $x < @rules; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @rules) 0 0 0
360 0 my $last_offset_from_std;
361  
362 0 ▶ if ( @rules == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@rules == 2) { } 0 0 0
elsif (@rules == 1) { } 0 0 0
363 0 ▶ $last_offset_from_std
Branch: 1 branch
BranchTrueFalseTotal
$x ? : 0 0 0
364 = $x
365 ? $rules[0]->offset_from_std
366 : $rules[1]->offset_from_std;
367 }
368 elsif ( @rules == 1 ) {
369 0 $last_offset_from_std = $rules[0]->offset_from_std;
370 }
371 else {
372 0 my $count = scalar @rules;
373 0 die
374 "Cannot generate future changes for zone with $count infinite rules\n";
375 }
376  
377 0 my $rule = $rules[$x];
378  
379 my $next = $rule->utc_start_datetime_for_year(
380 $year,
381 0 $self->{last_offset}, $last_offset_from_std
382 );
383  
384 # don't bother with changes we've seen already
385 0 ▶ next if $next->utc_rd_as_seconds < $self->max_span->[UTC_END];
Branch: 1 branch
BranchTrueFalseTotal
if $next->utc_rd_as_seconds < $self->max_span->[1] 0 0 0
386  
387 push @changes,
388 DateTime::TimeZone::OlsonDB::Change->new(
389 type => 'rule',
390 utc_start_datetime => $next,
391 local_start_datetime => $next + DateTime::Duration->new(
392 seconds => $self->{last_observance}->total_offset
393 + $rule->offset_from_std
394 ),
395 short_name => $self->{last_observance}
396 ->formatted_short_name( $rule->letter, $rule ),
397 observance => $self->{last_observance},
398 0 rule => $rule,
399 );
400 }
401 }
402  
403 0 $self->{max_year} = $generate_until_year;
404  
405 my @sorted
406 0 = sort { $a->utc_start_datetime <=> $b->utc_start_datetime } @changes;
407  
408 0 my ( $start, $end ) = _keys_for_type($type);
409  
410 0 my $match;
411 ## no critic (ControlStructures::ProhibitCStyleForLoops)
412 0 ▶ for ( my $x = 1; $x < @sorted; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @sorted) 0 0 0
413 0 my $span = DateTime::TimeZone::OlsonDB::Change::two_changes_as_span(
414 @sorted[ $x - 1, $x ] );
415  
416 0 $span = _span_as_array($span);
417  
418 0 push @{ $self->{spans} }, $span;
419  
420 0 ▶ $match = $span
Branch: 1 branch
BranchTrueFalseTotal
if $seconds >= $span->[$start] and $seconds < $span->[$end] 0 0 0
Condition0%0/3
$seconds >= $span->[$start] and $seconds < $span->[$end]
!ll&&!rl&&r
000
MC/DC0%0/2
$seconds >= $span->[$start] and $seconds < $span->[$end]
$seconds >= $span->[$start] $seconds < $span->[$end]
Truth table0%0/3
A and B
A= $seconds >= $span->[$start]B= $seconds < $span->[$end]
ABresult
0X0
100
111
421 if $seconds >= $span->[$start] && $seconds < $span->[$end];
422 }
423  
424 0 return $match;
425 }
426  
427 0 ▶sub max_span { $_[0]->{spans}[-1] }
Subroutine max_span: not called CC=1 SCAR=6.9
Pod undocumented
428  
429 0 ▶sub _keys_for_type {
Subroutine _keys_for_type: not called CC=2 SCAR=17.9
430 0 ▶ $_[0] eq 'utc' ? ( UTC_START, UTC_END ) : ( LOCAL_START, LOCAL_END );
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq 'utc' ? : 0 0 0
431 }
432  
433 0 ▶sub _span_as_array {
Subroutine _span_as_array: not called CC=1 SCAR=6.9
434 [
435 0 @{ $_[0] }{
436 0 qw( utc_start utc_end local_start local_end offset is_dst short_name )
437 }
438 ];
439 }
440  
441 0 ▶sub is_floating {0}
Subroutine is_floating: not called CC=1 SCAR=6.9
Pod documented
442  
443 0 ▶sub is_utc {0}
Subroutine is_utc: not called CC=1 SCAR=6.9
Pod documented
444  
445 0 ▶sub has_dst_changes {0}
Subroutine has_dst_changes: not called CC=1 SCAR=6.9
Pod documented
446  
447 1 ▶sub name { $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
448 0 ▶sub category { ( split /\//, $_[0]->{name}, 2 )[0] }
Subroutine category: not called CC=1 SCAR=6.9
Pod documented
449  
450 0 ▶sub is_valid_name {
Subroutine is_valid_name: not called CC=3 SCAR=24.8
Pod documented
451 0 my $class = shift;
452 0 my $name = shift;
453  
454 0 ▶ my $tz = try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
455 ## no critic (Variables::RequireInitializationForLocalVars)
456 0 local $SIG{__DIE__};
457 0 $class->new( name => $name );
458 0 };
459  
460 0 ▶ return $tz && $tz->isa('DateTime::TimeZone') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$tz && $tz->isa('DateTime::TimeZone') ? : 0 0 0
Condition0%0/3
$tz and $tz->isa("DateTime::TimeZone")
!ll&&!rl&&r
000
MC/DC0%0/2
$tz and $tz->isa("DateTime::TimeZone")
$tz $tz->isa("DateTime::TimeZone")
Truth table0%0/3
A and B
A= $tzB= $tz->isa("DateTime::TimeZone")
ABresult
0X0
100
111
461 }
462  
463 0 ▶sub STORABLE_freeze {
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
464 0 my $self = shift;
465  
466 0 return $self->name;
467 }
468  
469 0 ▶sub STORABLE_thaw {
Subroutine STORABLE_thaw: not called CC=3 SCAR=24.8
Pod undocumented
470 0 my $self = shift;
471 0 shift;
472 0 my $serialized = shift;
473  
474 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
475  
476 0 my $obj;
477 0 ▶ if ( $class->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isa(__PACKAGE__)) { } 0 0 0
478 0 $obj = __PACKAGE__->new( name => $serialized );
479 }
480 else {
481 0 $obj = $class->new( name => $serialized );
482 }
483  
484 0 %$self = %$obj;
485  
486 0 return $self;
487 }
488  
489 #
490 # Functions
491 #
492 20 ▶sub offset_as_seconds {
Subroutine offset_as_seconds: called CC=16 SCAR=31.4
Pod documented
493 20 my $offset = shift;
494 20 ▶ $offset = shift if try {
Subroutine __ANON__: called CC=1 SCAR=0.0
495 ## no critic (Variables::RequireInitializationForLocalVars)
496 20 local $SIG{__DIE__};
497 20 $offset->isa('DateTime::TimeZone');
498 20 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
if &try(sub { local $SIG{"__DIE__"}; $offset->isa("DateTime::TimeZone"); } ) 1 19 20
499  
500 20 ▶ return undef unless defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 20 20
501  
502 20 ▶ return 0 if $offset eq '0';
Branch: 1 branch
BranchTrueFalseTotal
if $offset eq 0 0 20 20
503  
504 20 my ( $sign, $hours, $minutes, $seconds );
505 20 ▶ if ( $offset =~ /^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($offset =~ /^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/) { } 0 20 20
elsif ($offset =~ /^([\+\-])?(\d\d)(\d\d)(\d\d)?$/) { } 20 0 20
506 0 ( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 );
507 }
508 elsif ( $offset =~ /^([\+\-])?(\d\d)(\d\d)(\d\d)?$/ ) {
509 20 ( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 );
510 }
511 else {
512 0 return undef;
513 }
514  
515 20 ▶ $sign = '+' unless defined $sign;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sign 1 19 20
516 20 ▶ return undef unless $hours >= 0 && $hours <= 99;
Branch: 1 branch
BranchTrueFalseTotal
unless $hours >= 0 and $hours <= 99 0 20 20
Condition33%1/3
$hours >= 0 and $hours <= 99
!ll&&!rl&&r
0020
MC/DC0%0/2
$hours >= 0 and $hours <= 99
$hours >= 0 $hours <= 99
Truth table33%1/3
A and B
A= $hours >= 0B= $hours <= 99
ABresult
0X0
100
111
517 20 ▶ return undef unless $minutes >= 0 && $minutes <= 59;
Branch: 1 branch
BranchTrueFalseTotal
unless $minutes >= 0 and $minutes <= 59 0 20 20
Condition33%1/3
$minutes >= 0 and $minutes <= 59
!ll&&!rl&&r
0020
MC/DC0%0/2
$minutes >= 0 and $minutes <= 59
$minutes >= 0 $minutes <= 59
Truth table33%1/3
A and B
A= $minutes >= 0B= $minutes <= 59
ABresult
0X0
100
111
518 return undef
519 20 ▶ unless !defined($seconds) || ( $seconds >= 0 && $seconds <= 59 );
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $seconds or $seconds >= 0 and $seconds <= 59 0 20 20
Condition50%3/6
not defined $seconds or $seconds >= 0 and $seconds <= 59
l!l&&r!l&&!r
1640
$seconds >= 0 and $seconds <= 59
!ll&&!rl&&r
004
MC/DC0%0/3
not defined $seconds or $seconds >= 0 and $seconds <= 59
not defined $seconds $seconds >= 0 $seconds <= 59
Truth table50%2/4
not(A) or B and C
A= not defined $secondsB= $seconds >= 0C= $seconds <= 59
ABCresult
1XX1
0111
00X0
0100
520  
521 20 my $total = $hours * 3600 + $minutes * 60;
522 20 ▶ $total += $seconds if $seconds;
Branch: 1 branch
BranchTrueFalseTotal
if $seconds 4 16 20
523 20 ▶ $total *= -1 if $sign eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "-" 8 12 20
524  
525 20 return $total;
526 }
527  
528 40 ▶sub offset_as_string {
Subroutine offset_as_string: called CC=8 SCAR=20.8
Pod documented
529 40 my $offset = shift;
530 40 ▶ $offset = shift if try {
Subroutine __ANON__: called CC=1 SCAR=0.0
531 ## no critic (Variables::RequireInitializationForLocalVars)
532 40 local $SIG{__DIE__};
533 40 $offset->isa('DateTime::TimeZone');
534 40 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
if &try(sub { local $SIG{"__DIE__"}; $offset->isa("DateTime::TimeZone"); } ) 1 39 40
535 40 ▶ my $sep = shift || q{};
Condition100%2/2
shift() || ''
l!l
931
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
536  
537 40 ▶ return undef unless defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 40 40
538 40 ▶ return undef unless $offset >= -359999 && $offset <= 359999;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset >= -359999 and $offset <= 359999 2 38 40
Condition100%3/3
$offset >= -359999 and $offset <= 359999
!ll&&!rl&&r
1138
MC/DC100%2/2
$offset >= -359999 and $offset <= 359999
$offset >= -359999 $offset <= 359999
Truth table100%3/3
A and B
A= $offset >= -359999B= $offset <= 359999
ABresult
0X0
100
111
539  
540 38 ▶ my $sign = $offset < 0 ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 ? : 16 22 38
541  
542 38 $offset = abs($offset);
543  
544 38 my $hours = int( $offset / 3600 );
545 38 $offset %= 3600;
546 38 my $mins = int( $offset / 60 );
547 38 $offset %= 60;
548 38 my $secs = int($offset);
549  
550 return (
551 38 ▶ $secs
Branch: 1 branch
BranchTrueFalseTotal
$secs ? : 8 30 38
552 ? sprintf(
553 '%s%02d%s%02d%s%02d', $sign, $hours, $sep, $mins, $sep, $secs
554 )
555 : sprintf( '%s%02d%s%02d', $sign, $hours, $sep, $mins )
556 );
557 }
558  
559 # These methods all operate on data contained in the DateTime/TimeZone/Catalog.pm file.
560  
561 2 ▶sub all_names {
Subroutine all_names: called CC=2 SCAR=6.9
Pod documented
562 return wantarray
563 ? @DateTime::TimeZone::Catalog::ALL
564 2 ▶ : [@DateTime::TimeZone::Catalog::ALL];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
565 }
566  
567 2 ▶sub categories {
Subroutine categories: called CC=2 SCAR=6.9
Pod documented
568 return wantarray
569 ? @DateTime::TimeZone::Catalog::CATEGORY_NAMES
570 2 ▶ : [@DateTime::TimeZone::Catalog::CATEGORY_NAMES];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
571 }
572  
573 2 ▶sub links {
Subroutine links: called CC=2 SCAR=6.9
Pod documented
574 return wantarray
575 2 ▶ ? %DateTime::TimeZone::Catalog::LINKS
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
576 : {%DateTime::TimeZone::Catalog::LINKS};
577 }
578  
579 3 ▶sub names_in_category {
Subroutine names_in_category: called CC=4 SCAR=13.9
Pod documented
580 3 ▶ shift if $_[0]->isa('DateTime::TimeZone');
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->isa("DateTime::TimeZone") 1 2 3
581 3 ▶ return unless exists $DateTime::TimeZone::Catalog::CATEGORIES{ $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $DateTime::TimeZone::Catalog::CATEGORIES{$_[0]} 0 3 3
582  
583 return wantarray
584 2 ? @{ $DateTime::TimeZone::Catalog::CATEGORIES{ $_[0] } }
585 3 ▶ : $DateTime::TimeZone::Catalog::CATEGORIES{ $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
586 }
587  
588 1 ▶sub countries {
Subroutine countries: called CC=2 SCAR=7.6
Pod documented
589 wantarray
590 1 ▶ ? ( sort keys %DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY )
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
591 : [ sort keys %DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY ];
592 }
593  
594 5 ▶sub names_in_country {
Subroutine names_in_country: called CC=4 SCAR=13.9
Pod documented
595 5 ▶ shift if $_[0]->isa('DateTime::TimeZone');
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->isa("DateTime::TimeZone") 1 4 5
596  
597 return
598 unless
599 5 ▶ exists $DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY{ lc $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY{lc $_[0]} 0 5 5
600  
601 return
602 wantarray
603 4 ? @{ $DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY{ lc $_[0] } }
604 5 ▶ : $DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY{ lc $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 1 5
605 }
606  
607 3 1;
608  
609 # ABSTRACT: Time zone object base class and factory
610  
611 __END__
« TimeZone/OlsonDB/Observance.pm ↑ Summary TimeZone/OlsonDB/Change.pm »