lib/DateTime/Lite/TimeZone.pm

filter: Statementstmt 51.3% 682 / 1328 Branchbran 40.9% 308 / 752 Conditioncond 31.6% 226 / 715 MC/DCmcdc 9.2% 37 / 399 Subroutinesub 63.3% 64 / 101 Podpod 97.7% 43 / 44 totaltotal 40.7% 1360 / 3339 CC 656 SCAR 49.6
CC
656
Cov
44%
_local_tz_unix
1084.2
pass_error
457.3
_posix_tz_lookup
294.3
CRAP 142.0
« lib/DateTime/Lite/PP.pm ↑ Summary lib/DateTime/Lite.pm »
1 ##----------------------------------------------------------------------------
2 ## Lightweight DateTime Alternative - ~/lib/DateTime/Lite/TimeZone.pm
3 ## Version v0.5.9
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/04/03
7 ## Modified 2026/05/21
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package DateTime::Lite::TimeZone;
15 BEGIN
16 20 ▶{
Subroutine BEGIN: called CC=21 SCAR=42.3
17 20 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 20 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 20 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 20 ▶ if( $] < 5.013 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.013") 0 20 20
21 {
22 20 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 0 ▶ unless( defined( &warnings::register_categories ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &warnings::register_categories) 0 0 0
24 {
25 *warnings::_mkMask = sub
26 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 my $bit = shift( @_ );
28 0 my $mask = "";
29 0 vec( $mask, $bit, 1 ) = 1;
30 0 return( $mask );
31 0 };
32  
33 *warnings::register_categories = sub
34 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
35 0 my @names = @_;
36 0 foreach my $name ( @names )
37 {
38 0 ▶ if( !defined( $warnings::Bits{ $name } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $warnings::Bits{$name}) 0 0 0
39 {
40 0 $warnings::Offsets{ $name } = $warnings::LAST_BIT;
41 0 $warnings::Bits{ $name } = warnings::_mkMask( $warnings::LAST_BIT++ );
42 0 $warnings::DeadBits{ $name } = warnings::_mkMask( $warnings::LAST_BIT++ );
43 0 ▶ if( length( $warnings::Bits{ $name } ) > length( $warnings::Bits{all} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $warnings::Bits{$name} > length $warnings::Bits{"all"}) 0 0 0
44 {
45 0 $warnings::Bits{all} .= "\x55";
46 0 $warnings::DeadBits{all} .= "\xaa";
47 }
48 }
49 }
50 0 };
51 }
52 }
53 20 warnings::register_categories( 'DateTime::Lite' );
54 20 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
55 $VERSION $ERROR $DEBUG $FATAL_EXCEPTIONS
56 $DB_FILE $DBH $STHS
57 $FALLBACK_TO_DT_TZ
58 $HAS_CONSTANTS
59 $JSON_CLASS
60 $MISSING_AUTO_UTF8_DECODING
61 $SQLITE_HAS_MATH_FUNCTIONS
62 $USE_MEM_CACHE $_CACHE
63 20 );
64 20 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
65 '""' => \&name,
66 208 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
67 20 fallback => 1,
68 20 );
69 20 ▶ use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
70 20 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 20 ▶ use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
72 20 ▶ use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
73 20 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
74 20 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 # Seconds between the Unix epoch (1970-01-01T00:00:00 UTC) and the Rata Die
77 # epoch (0001-01-01T00:00:00) used internally by DateTime::Lite.
78 #
79 # The tz.sqlite3 database stores transition times as raw Unix seconds
80 # (as they come from the TZif binary files). All lookups subtract this
81 # constant from $dt->utc_rd_as_seconds before querying the database.
82 #
83 # Verified:
84 # DateTime::Lite->new(
85 # year => 1970,
86 # month => 1,
87 # day => 1,
88 # time_zone => 'UTC',
89 # )->utc_rd_as_seconds == 62_135_683_200
90 20 ▶ use constant UNIX_TO_RD => 62_135_683_200;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 20 our $VERSION = 'v0.5.9';
92 20 our $DEBUG = 0;
93 20 our $DBH = {};
94 # Cached prepared statements, keyed by db file path then by statement ID:
95 # $STHS->{ $db_file }->{ $statement_id } = $sth
96 20 our $STHS = {};
97 # Package-level memory cache: canonical_name -> blessed object.
98 # Populated when use_cache_mem => 1 is passed to new(), or when
99 # enable_mem_cache() has been called at the class level.
100 # Keys are canonical zone names after alias resolution.
101 20 our $_CACHE = {};
102 # $SQLITE_HAS_MATH_FUNCTIONS is not defined on purpose
103 # Its definedness is checked in _dbh_add_user_defined_functions()
104  
105 # The bundled database lives next to this file
106 {
107 20 my( $vol, $parent, $file ) = File::Spec->splitpath( __FILE__ );
108 20 $DB_FILE = File::Spec->catpath( $vol, $parent, 'tz.sqlite3' );
109 20 ▶ $DB_FILE = File::Spec->rel2abs( $DB_FILE )
Branch: 1 branch
BranchTrueFalseTotal
unless "File::Spec"->file_name_is_absolute($DateTime::Lite::TimeZone::DB_FILE) 20 0 20
110 unless( File::Spec->file_name_is_absolute( $DB_FILE ) );
111 }
112  
113 # Detect whether DBD::SQLite is available. If not, we fall back to
114 # DateTime::TimeZone transparently.
115 20 $FALLBACK_TO_DT_TZ = 0;
116 20 local $@;
117 eval
118 20 {
119 20 require DBI;
120 20 require DBD::SQLite;
121 };
122 20 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 20 20
elsif (not -e $DateTime::Lite::TimeZone::DB_FILE) { } 0 20 20
123 {
124 0 ▶ warn( "DateTime::Lite::TimeZone: DBD::SQLite not available, falling back to DateTime::TimeZone. Install DBD::SQLite for a lighter footprint." ) if( warnings::enabled( 'DateTime::Lite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Lite") 0 0 0
125 0 $FALLBACK_TO_DT_TZ = 1;
126 }
127 elsif( !-e( $DB_FILE ) )
128 {
129 0 ▶ warn( "DateTime::Lite::TimeZone: bundled database $DB_FILE not found, falling back to DateTime::TimeZone." ) if( warnings::enabled( 'DateTime::Lite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Lite") 0 0 0
130 0 $FALLBACK_TO_DT_TZ = 1;
131 }
132  
133 20 ▶ if( !$FALLBACK_TO_DT_TZ && -l( $DB_FILE ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ and -l $DateTime::Lite::TimeZone::DB_FILE) 0 20 20
Condition33%1/3
not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ and -l $DateTime::Lite::TimeZone::DB_FILE
!ll&&!rl&&r
0200
MC/DC0%0/2
not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ and -l $DateTime::Lite::TimeZone::DB_FILE
not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ -l $DateTime::Lite::TimeZone::DB_FILE
Truth table33%1/3
not(A) and B
A= not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZB= -l $DateTime::Lite::TimeZone::DB_FILE
ABresult
0X0
100
111
134 {
135 0 my $real_path = Cwd::realpath( $DB_FILE );
136 0 ▶ if( !-e( $real_path ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $real_path) { } 0 0 0
137 {
138 0 ▶ warn( "DateTime::Lite::TimeZone: bundled database $DB_FILE is a symbolic link pointing to $real_path, but it could not be found, falling back to DateTime::TimeZone." ) if( warnings::enabled( 'DateTime::Lite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Lite") 0 0 0
139 0 $FALLBACK_TO_DT_TZ = 1;
140 }
141 else
142 {
143 0 $DB_FILE = $real_path;
144 }
145 }
146  
147 20 ▶ if( !$FALLBACK_TO_DT_TZ && -z( $DB_FILE ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ and -z $DateTime::Lite::TimeZone::DB_FILE) 0 20 20
Condition33%1/3
not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ and -z $DateTime::Lite::TimeZone::DB_FILE
!ll&&!rl&&r
0200
MC/DC0%0/2
not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ and -z $DateTime::Lite::TimeZone::DB_FILE
not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ -z $DateTime::Lite::TimeZone::DB_FILE
Truth table33%1/3
not(A) and B
A= not $DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZB= -z $DateTime::Lite::TimeZone::DB_FILE
ABresult
0X0
100
111
148 {
149 0 ▶ warn( "DateTime::Lite::TimeZone: bundled database $DB_FILE is an empty file (zero byte)." ) if( warnings::enabled( 'DateTime::Lite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Lite") 0 0 0
150 0 $FALLBACK_TO_DT_TZ = 1;
151 }
152  
153 20 ▶ if( $FALLBACK_TO_DT_TZ )
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ) { } 0 20 20
154 {
155 0 local $@;
156 # Lazy loading of DateTime::TimeZone
157 # We do not want to make it a dependency of our module.
158 eval
159 0 {
160 0 require DateTime::TimeZone;
161 };
162 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
163 {
164 0 die( "Neither SQLite nor DateTime::TimeZone are installed on your system. You need at least one of them to use this module." );
165 }
166 }
167 else
168 {
169 # DBD::SQLite::Constants available since 1.48
170 # Foreign key constraints since SQLite v3.6.19 (2009-10-14)
171 # DBD::SQLite 1.27 (2009-11-23)
172 # utf8 auto decoding from version 1.68 (2021-07-22)
173 20 ▶ $HAS_CONSTANTS = ( version->parse( $DBD::SQLite::VERSION ) >= version->parse( '1.48' ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
'version'->parse($DBD::SQLite::VERSION) >= 'version'->parse('1.48') ? : 20 0 20
174 # Native UTF-8 string mode available since 1.68
175 20 ▶ $MISSING_AUTO_UTF8_DECODING = ( version->parse( $DBD::SQLite::VERSION ) < version->parse( '1.68' ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
'version'->parse($DBD::SQLite::VERSION) < 'version'->parse('1.68') ? : 0 20 20
176 }
177  
178 # JSON backend detection: prefer Cpanel::JSON::XS (fastest, most rigorous), fall back
179 # to JSON::XS, then JSON::PP (core since Perl 5.14).
180 20 our $JSON_CLASS;
181 20 ▶ if( eval{ require Cpanel::JSON::XS; 1 } )
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Cpanel::JSON::XS; 1 } }) { } 20 0 20
elsif (eval { do { require JSON::XS; 1 } }) { } 0 0 0
182 {
183 20 $JSON_CLASS = 'Cpanel::JSON::XS';
184 }
185 0 elsif( eval{ require JSON::XS; 1 } )
186 {
187 0 $JSON_CLASS = 'JSON::XS';
188 }
189 else
190 {
191 0 require JSON::PP;
192 0 $JSON_CLASS = 'JSON::PP';
193 }
194 };
195  
196 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
197 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
198  
199 # NOTE: Constructor
200 sub new
201 222 ▶{
Subroutine new: called CC=47 SCAR=44.1
Pod documented
202 222 my $this = shift( @_ );
203 222 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
02220
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
204 222 my %args;
205  
206 222 ▶ if( @_ == 1 && !ref( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 0 222 222
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
22200
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
207 {
208 0 $args{name} = shift( @_ );
209 }
210 else
211 {
212 222 %args = @_;
213 }
214  
215 222 my $name = delete( $args{name} );
216 222 ▶ my $use_cache = delete( $args{use_cache_mem} ) // $USE_MEM_CACHE // 0;
Condition100%5/5
(delete $args{"use_cache_mem"} // $DateTime::Lite::TimeZone::USE_MEM_CACHE) // 0
l!l
14208
delete $args{"use_cache_mem"} // $DateTime::Lite::TimeZone::USE_MEM_CACHE
l!l&&r!l&&!r
77208
MC/DC100%2/2
(delete $args{"use_cache_mem"} // $DateTime::Lite::TimeZone::USE_MEM_CACHE) // 0
delete $args{"use_cache_mem"} $DateTime::Lite::TimeZone::USE_MEM_CACHE
Truth table100%3/3
A // B
A= delete $args{"use_cache_mem"}B= $DateTime::Lite::TimeZone::USE_MEM_CACHE
ABresult
1X1
011
000
217 222 ▶ my $extended = delete( $args{extended} ) // 0;
Condition100%2/2
delete $args{"extended"} // 0
l!l
2220
MC/DC100%1/1
delete $args{"extended"} // 0
delete $args{"extended"}
Truth table100%2/2
A
A= delete $args{"extended"}
Aresult
11
00
218 222 ▶ my $latitude = delete( $args{latitude} ) // delete( $args{lat} );
Condition66%2/3
delete $args{"latitude"} // delete $args{"lat"}
l!l&&r!l&&!r
110211
MC/DC50%1/2
delete $args{"latitude"} // delete $args{"lat"}
delete $args{"latitude"} delete $args{"lat"}
Truth table66%2/3
A // B
A= delete $args{"latitude"}B= delete $args{"lat"}
ABresult
1X1
011
000
219 222 ▶ my $longitude = delete( $args{longitude} ) // delete( $args{lon} );
Condition66%2/3
delete $args{"longitude"} // delete $args{"lon"}
l!l&&r!l&&!r
100212
MC/DC50%1/2
delete $args{"longitude"} // delete $args{"lon"}
delete $args{"longitude"} delete $args{"lon"}
Truth table66%2/3
A // B
A= delete $args{"longitude"}B= delete $args{"lon"}
ABresult
1X1
011
000
220 222 ▶ my $fatal = delete( $args{fatal} ) // ( $FATAL_EXCEPTIONS // 0 );
Condition75%3/4
delete $args{"fatal"} // ($DateTime::Lite::TimeZone::FATAL_EXCEPTIONS // 0)
l!l
2220
$DateTime::Lite::TimeZone::FATAL_EXCEPTIONS // 0
l!l
0220
MC/DC100%1/1
delete $args{"fatal"} // ($DateTime::Lite::TimeZone::FATAL_EXCEPTIONS // 0)
delete $args{"fatal"}
Truth table100%2/2
A
A= delete $args{"fatal"}
Aresult
11
00
221  
222 # After extracting all known keys, %args must be empty
223 222 ▶ if( scalar( keys( %args ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %args) 1 221 222
224 {
225 1 my @unknown = sort( keys( %args ) );
226 return( $class->error( sprintf(
227 "Unknown argument%s passed to %s->new: %s",
228 scalar( @unknown ) > 1 ? 's' : '',
229 $class,
230 1 ▶ join( ', ', map{ qq{'$_'} } @unknown ),
Branch: 1 branch
BranchTrueFalseTotal
scalar @unknown > 1 ? : 0 1 1
231 ) ) );
232 }
233  
234 # If latitude and longitude are provided instead of a name, resolve the
235 # nearest IANA timezone using the coordinates stored in the zones table.
236 221 ▶ if( !defined( $name ) || !length( $name ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and length $name) 11 210 221
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
110210
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
237 {
238 11 ▶ if( defined( $latitude ) && defined( $longitude ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $latitude and defined $longitude) { } 10 1 11
Condition66%2/3
defined $latitude and defined $longitude
!ll&&!rl&&r
0110
MC/DC50%1/2
defined $latitude and defined $longitude
defined $latitude defined $longitude
Truth table66%2/3
A and B
A= defined $latitudeB= defined $longitude
ABresult
0X0
100
111
239 {
240 10 ▶ $name = $class->_nearest_zone( $latitude, $longitude ) ||
Condition100%2/2
$class->_nearest_zone($latitude, $longitude) || (return $class->pass_error)
l!l
73
MC/DC100%1/1
$class->_nearest_zone($latitude, $longitude) || (return $class->pass_error)
$class->_nearest_zone($latitude, $longitude)
Truth table100%2/2
A
A= $class->_nearest_zone($latitude, $longitude)
Aresult
11
00
241 return( $class->pass_error );
242 }
243 else
244 {
245 1 return( $class->error( "Parameter 'name' is required (or provide 'latitude' and 'longitude')." ) );
246 }
247 }
248  
249 # Package-level memory cache: return immediately if the canonical name
250 # is already cached. The cache is keyed BEFORE alias resolution so
251 # that both the alias ("US/Eastern") and the canonical name
252 # ("America/New_York") are stored and looked up by their original form.
253 217 ▶ if( $use_cache && exists( $_CACHE->{ $name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($use_cache and exists $DateTime::Lite::TimeZone::_CACHE->{$name}) 4 213 217
Condition100%3/3
$use_cache and exists $DateTime::Lite::TimeZone::_CACHE->{$name}
!ll&&!rl&&r
20764
MC/DC100%2/2
$use_cache and exists $DateTime::Lite::TimeZone::_CACHE->{$name}
$use_cache exists $DateTime::Lite::TimeZone::_CACHE->{$name}
Truth table100%3/3
A and B
A= $use_cacheB= exists $DateTime::Lite::TimeZone::_CACHE->{$name}
ABresult
0X0
100
111
254 {
255 4 return( $_CACHE->{ $name } );
256 }
257  
258 # Delegate entirely to DateTime::TimeZone if fallback mode is active
259 213 ▶ if( $FALLBACK_TO_DT_TZ )
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::TimeZone::FALLBACK_TO_DT_TZ) 0 213 213
260 {
261 0 local $@;
262 0 my $tz = eval{ DateTime::TimeZone->new( name => $name ) };
263 0 ▶ return( $class->error( "Invalid time zone name '$name': $@" ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
264 0 return( $tz );
265 }
266  
267 # Special cases: floating, UTC, and local never need a DB lookup
268 213 ▶ if( $name eq 'local' )
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "local") 2 211 213
269 {
270 # Resolve the local timezone name from the environment or OS.
271 # We try the following methods in order, all using only core modules:
272 # 1. $ENV{TZ} if set, valid, and not 'local' (to avoid infinite loop)
273 # 2. /etc/localtime symlink target (most Linux and macOS systems)
274 # 3. /etc/timezone plain text file (Debian/Ubuntu)
275 # 4. /etc/TIMEZONE with TZ= line (Solaris)
276 # 5. /etc/sysconfig/clock with ZONE= or TIMEZONE= line (RedHat)
277 # 6. /etc/default/init with TZ= line (older Unix)
278 2 ▶ my $local_name = $class->_resolve_local_tz_name ||
Condition50%1/2
$class->_resolve_local_tz_name || (return $class->error('Cannot determine local time zone. Please set $ENV{TZ}.'))
l!l
20
MC/DC0%0/1
$class->_resolve_local_tz_name || (return $class->error('Cannot determine local time zone. Please set $ENV{TZ}.'))
$class->_resolve_local_tz_name
Truth table50%1/2
A
A= $class->_resolve_local_tz_name
Aresult
11
00
279 return( $class->error( "Cannot determine local time zone. Please set \$ENV{TZ}." ) );
280 # Recurse with the resolved name
281 2 return( $class->new( name => $local_name, fatal => $fatal, use_cache_mem => $use_cache, extended => $extended ) );
282 }
283  
284 211 ▶ if( $name eq 'floating' )
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "floating") 20 191 211
285 {
286 20 return( bless(
287 {
288 name => 'floating',
289 is_floating => 1,
290 is_utc => 0,
291 is_olson => 0,
292 has_dst => 0,
293 fatal => $fatal,
294 }, $class ) );
295 }
296  
297 191 ▶ if( $name eq 'UTC' || $name eq 'Z' || $name eq '+0000' || $name eq '-0000' )
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "UTC" or $name eq "Z" or $name eq "+0000" or $name eq "-0000") 127 64 191
Condition66%6/9
$name eq "UTC" or $name eq "Z" or $name eq "+0000" or $name eq "-0000"
l!l&&r!l&&!r
127064
$name eq "UTC" or $name eq "Z" or $name eq "+0000"
l!l&&r!l&&!r
127064
$name eq "UTC" or $name eq "Z"
l!l&&r!l&&!r
127064
MC/DC25%1/4
$name eq "UTC" or $name eq "Z" or $name eq "+0000" or $name eq "-0000"
$name eq "UTC" $name eq "Z" $name eq "+0000" $name eq "-0000"
Truth table40%2/5
A or B or C or D
A= $name eq "UTC"B= $name eq "Z"C= $name eq "+0000"D= $name eq "-0000"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
298 {
299 127 return( bless(
300 {
301 name => 'UTC',
302 is_floating => 0,
303 is_utc => 1,
304 is_olson => 0,
305 has_dst => 0,
306 fatal => $fatal,
307 }, $class ) );
308 }
309  
310 # Fixed-offset zones like "+09:00" or "-05:00" or "+0900"
311 64 ▶ if( $name =~ /\A([+-])(\d{2}):?(\d{2})\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A([+-])(\d{2}):?(\d{2})\z/) 1 63 64
312 {
313 1 ▶ my $sign = $1 eq '+' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '+' ? : 1 0 1
314 1 my $offset = $sign * ( $2 * 3600 + $3 * 60 );
315 1 ▶ return( bless(
Branch: 1 branch
BranchTrueFalseTotal
$offset == 0 ? : 0 1 1
316 {
317 name => $name,
318 is_floating => 0,
319 is_utc => ( $offset == 0 ? 1 : 0 ),
320 is_olson => 0,
321 has_dst => 0,
322 fixed_offset => $offset,
323 fatal => $fatal,
324 }, $class ) );
325 }
326  
327 63 my $self = bless(
328 {
329 name => $name,
330 is_floating => 0,
331 is_utc => 0,
332 is_olson => 1,
333 has_dst => 0,
334 _zone_id => undef,
335 fatal => $fatal,
336 }, $class );
337  
338 # Resolve aliases (such as "US/Eastern" -> "America/New_York")
339 63 ▶ my $canonical = $self->_resolve_alias( $name ) ||
Condition50%1/2
$self->_resolve_alias($name) || (return $self->pass_error)
l!l
630
MC/DC0%0/1
$self->_resolve_alias($name) || (return $self->pass_error)
$self->_resolve_alias($name)
Truth table50%1/2
A
A= $self->_resolve_alias($name)
Aresult
11
00
340 return( $self->pass_error );
341  
342 63 ▶ $self->{_is_canonical} = ( $canonical eq $name ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$canonical eq $name ? : 59 4 63
343 63 ▶ if( !$self->{_is_canonical} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_is_canonical"}) 4 59 63
344 {
345 4 $self->{name} = $canonical;
346 4 $self->{_alias_of} = $name;
347 }
348  
349 63 my $ref = $self->_get_zone_info( $self->{name} );
350 63 ▶ return( $self->pass_error ) if( !defined( $ref ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $self->error 0 63 63
Condition66%2/3
not defined $ref and $self->error
!ll&&!rl&&r
6210
MC/DC0%0/2
not defined $ref and $self->error
not defined $ref $self->error
Truth table66%2/3
not(A) and B
A= not defined $refB= $self->error
ABresult
0X0
100
111
351  
352 # If the name is not a known IANA timezone, and extended mode was requested,
353 # attempt to resolve it as a timezone abbreviation (such as JST or CET) via the
354 # extended_aliases table. Use the first unambiguous result.
355 63 ▶ if( !$ref && $extended )
Branch: 1 branch
BranchTrueFalseTotal
if (not $ref and $extended) 0 63 63
Condition66%2/3
not $ref and $extended
!ll&&!rl&&r
6210
MC/DC0%0/2
not $ref and $extended
not $ref $extended
Truth table66%2/3
not(A) and B
A= not $refB= $extended
ABresult
0X0
100
111
356 {
357 0 my $candidates = $self->resolve_abbreviation( $name, extended => 1 );
358 0 ▶ if( defined( $candidates ) && @$candidates )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $candidates and @$candidates) 0 0 0
Condition0%0/3
defined $candidates and @$candidates
!ll&&!rl&&r
000
MC/DC0%0/2
defined $candidates and @$candidates
defined $candidates @$candidates
Truth table0%0/3
A and B
A= defined $candidatesB= @$candidates
ABresult
0X0
100
111
359 {
360 0 ▶ if( $candidates->[0]->{ambiguous} )
Branch: 1 branch
BranchTrueFalseTotal
if ($candidates->[0]{"ambiguous"}) 0 0 0
361 {
362 0 return( $self->error( "Timezone abbreviation '$name' is ambiguous (maps to multiple UTC offsets). Use resolve_abbreviation() with a utc_offset filter to disambiguate." ) );
363 }
364 # Passing the 'extended' property here does not matter much since the candidate zone found is already a canonical IANA zone, but we pass it anyway to be consistent.
365 0 return( $class->new( name => $candidates->[0]->{zone_name}, fatal => $fatal, use_cache_mem => $use_cache, extended => $extended ) );
366 }
367 }
368 63 ▶ return( $self->error( "Unknown time zone '$name'." ) ) unless( $ref );
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 1 62 63
369  
370 62 $self->{_zone_id} = $ref->{zone_id};
371 62 ▶ $self->{has_dst} = $ref->{has_dst} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'has_dst'} ? : 59 3 62
372 62 ▶ $self->{is_olson} = $ref->{canonical} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'canonical'} ? : 62 0 62
373 62 my @keys = qw( countries coordinates comment latitude longitude tzif_version footer_tz_string transition_count type_count leap_count isstd_count designation_charcount );
374 62 @$self{ @keys } = @$ref{ @keys };
375  
376 # Store in process-level cache if requested.
377 # Cache under both the input name (which may be an alias) and the
378 # canonical name so that either form hits the cache on the next call.
379 # Also initialise the per-object span cache so that _lookup_span
380 # avoids SQLite queries for repeated timestamps in the same span.
381 62 ▶ if( $use_cache )
Branch: 1 branch
BranchTrueFalseTotal
if ($use_cache) 6 56 62
382 {
383 6 $self->{_span_cache} = {};
384 6 $self->{_span_cache_local} = {};
385 6 $self->{_footer_cache_key} = undef;
386 6 $self->{_footer_cache_val} = undef;
387 6 $self->{_footer_local_cache_key} = undef;
388 6 $self->{_footer_local_cache_val} = undef;
389 6 $_CACHE->{ $name } = $self;
390 6 ▶ $_CACHE->{ $self->{name} } = $self if( $self->{name} ne $name );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"name"} ne $name 1 5 6
391 }
392  
393 62 return( $self );
394 }
395  
396 sub aliases
397 0 ▶{
Subroutine aliases: not called CC=11 SCAR=48.8
Pod documented
398 # Can be called as class method, instance method, or plain function.
399 0 my $class_or_self = shift( @_ );
400 0 local $@;
401 0 my $sth;
402 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'all_aliases' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("all_aliases")) 0 0 0
403 {
404 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
405 0 my $query = q{SELECT alias_name, zone_name FROM v_zone_aliases ORDER BY alias_name};
406 $sth = eval
407 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all timezone aliases: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all timezone aliases: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
408 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
409 } || return( $class_or_self->error( "Error preparing the query to get all timezone aliases: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
410 0 $class_or_self->_set_cached_statement( all_aliases => $sth );
411 }
412  
413 0 my $rv = eval{ $sth->execute };
414 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
415 {
416 0 $sth->finish;
417 0 return( $class_or_self->error( "Error executing the query to get all timezone aliases: $@", "\nSQL query was ", $sth->{Statement} ) );
418 }
419 elsif( !defined( $rv ) )
420 {
421 0 $sth->finish;
422 0 return( $class_or_self->error( "Error executing the query to get all timezone aliases: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
423 }
424  
425 0 my $all = eval{ $sth->fetchall_arrayref([0,1]) };
426 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
427 {
428 0 $sth->finish;
429 0 return( $class_or_self->error( "Error retrieving all timezone aliases: $@", "\nSQL query was ", $sth->{Statement} ) );
430 }
431 # We check for definedness, which means an error in DBI
432 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
433 {
434 0 $sth->finish;
435 0 return( $class_or_self->error( "Error retrieving all timezone aliases: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
436 }
437 0 $sth->finish;
438 0 my $aliases = +{map{ $_->[0] => $_->[1] } @$all};
439 0 ▶ return( wantarray() ? %$aliases : $aliases );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
440 }
441  
442 {
443 20 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
444 20 *links = \&aliases;
445 }
446  
447 sub all_names
448 0 ▶{
Subroutine all_names: not called CC=11 SCAR=48.8
Pod documented
449 # Can be called as class method, instance method, or plain function.
450 0 my $class_or_self = shift( @_ );
451 0 local $@;
452 0 my $sth;
453 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'all_names' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("all_names")) 0 0 0
454 {
455 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
456 # We handle each step of building the query, so we can report on any error with better accuracy.
457 0 my $query = q{SELECT name FROM zones ORDER BY name};
458 $sth = eval
459 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all timezone names: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all timezone names: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
460 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
461 } || return( $class_or_self->error( "Error preparing the query to get all timezone names: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
462 0 $class_or_self->_set_cached_statement( all_names => $sth );
463 }
464  
465 0 my $rv = eval{ $sth->execute };
466 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
467 {
468 0 $sth->finish;
469 0 return( $class_or_self->error( "Error executing the query to get all timezone names: $@\nSQL query was ", $sth->{Statement} ) );
470 }
471 elsif( !defined( $rv ) )
472 {
473 0 $sth->finish;
474 0 return( $class_or_self->error( "Error executing the query to get all timezone names: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
475 }
476  
477 0 my $all = eval{ $sth->fetchall_arrayref([0]) };
478 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
479 {
480 0 $sth->finish;
481 0 return( $class_or_self->error( "Error retrieving all timezone names: $@", "\nSQL query was ", $sth->{Statement} ) );
482 }
483 # We check for definedness, which means an error in DBI
484 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
485 {
486 0 $sth->finish;
487 0 return( $class_or_self->error( "Error retrieving all timezone names: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
488 }
489 0 $sth->finish;
490 0 my $zones = [map{ $_->[0] } @$all];
491 0 ▶ return( wantarray() ? @$zones : $zones );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
492 }
493  
494 sub categories
495 0 ▶{
Subroutine categories: not called CC=11 SCAR=48.8
Pod documented
496 # Can be called as class method, instance method, or plain function.
497 0 my $class_or_self = shift( @_ );
498 0 local $@;
499 0 my $sth;
500 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'categories' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("categories")) 0 0 0
501 {
502 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
503 0 my $query = q{SELECT DISTINCT(category) FROM zones WHERE category IS NOT NULL ORDER BY category};
504 $sth = eval
505 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all timezone categories: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all timezone categories: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
506 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
507 } || return( $class_or_self->error( "Error preparing the query to get all timezone categories: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
508 0 $class_or_self->_set_cached_statement( categories => $sth );
509 }
510  
511 0 my $rv = eval{ $sth->execute };
512 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
513 {
514 0 $sth->finish;
515 0 return( $class_or_self->error( "Error executing the query to get all timezone categories: $@", "\nSQL query was ", $sth->{Statement} ) );
516 }
517 elsif( !defined( $rv ) )
518 {
519 0 $sth->finish;
520 0 return( $class_or_self->error( "Error executing the query to get all timezone categories: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
521 }
522  
523 0 my $all = eval{ $sth->fetchall_arrayref([0]) };
524 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
525 {
526 0 $sth->finish;
527 0 return( $class_or_self->error( "Error retrieving all timezone categories: $@", "\nSQL query was ", $sth->{Statement} ) );
528 }
529 # We check for definedness, which means an error in DBI
530 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
531 {
532 0 $sth->finish;
533 0 return( $class_or_self->error( "Error retrieving all timezone categories: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
534 }
535 0 $sth->finish;
536 0 my $categories = [map{ $_->[0] } @$all];
537 0 ▶ return( wantarray() ? @$categories : $categories );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
538 }
539  
540 # Returns the first part of the timezone, such as 'Asia' in 'Asia/Tokyo'
541 sub category
542 0 ▶{
Subroutine category: not called CC=4 SCAR=30.0
Pod documented
543 0 my $self = shift( @_ );
544 0 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
545 {
546 0 return( $self->error( "category() must be called on a class instance." ) );
547 }
548 0 ▶ return if( index( $self->{name}, '/' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($self->{"name"}, "/") == -1) 0 0 0
549 0 return( [split( /\//, $self->{name}, 2 )]->[0] );
550 }
551  
552 # clear_mem_cache()
553 # Class method. Removes all entries from the package-level cache without
554 # disabling it. Useful when zone data may have changed, such as after replacing
555 # tz.sqlite3 at runtime, which is an unusual operation.
556 sub clear_mem_cache
557 1 ▶{
Subroutine clear_mem_cache: called CC=1 SCAR=0.0
Pod documented
558 1 my $class = shift( @_ );
559 1 $_CACHE = {};
560 1 return( $class );
561 }
562  
563 # Returns the optional zone comment from zone1970.tab
564 4 ▶sub comment { return( $_[0]->{comment} ) }
Subroutine comment: called CC=1 SCAR=0.0
Pod documented
565  
566 # Returns the compact coordinate string from zone1970.tab, such as "+3518+13942"
567 2 ▶sub coordinates { return( $_[0]->{coordinates} ) }
Subroutine coordinates: called CC=1 SCAR=0.0
Pod documented
568  
569 # Returns an arrayref of ISO 3166-1 alpha-2 country codes associated with
570 # this timezone, such as ["JP"] or ["US","CA"].
571 # Returns an empty array for UTC, floating, and fixed-offset zones.
572 sub country_codes
573 3 ▶{
Subroutine country_codes: called CC=5 SCAR=18.4
Pod documented
574 3 my $self = shift( @_ );
575 3 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 3 3
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
003
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
576 {
577 0 return( $self->error( "country_codes() must be called on a class instance." ) );
578 }
579 3 ▶ return unless( defined( $self->{countries} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"countries"} 2 1 3
580 # We need to cache it
581 1 ▶ unless( ref( $self->{countries} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"countries"} eq "ARRAY") 0 1 1
582 {
583 0 $self->{countries} = $self->_decode_sql_array( $self->{countries} );
584 }
585 1 return( $self->{countries} );
586 }
587  
588 sub countries
589 0 ▶{
Subroutine countries: not called CC=11 SCAR=48.8
Pod documented
590 # Can be called as class method, instance method, or plain function.
591 0 my $class_or_self = shift( @_ );
592 0 local $@;
593 0 my $sth;
594 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'countries' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("countries")) 0 0 0
595 {
596 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
597 0 my $query = q{SELECT LOWER(code) FROM countries ORDER BY code};
598 $sth = eval
599 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all country codes: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all country codes: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
600 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
601 } || return( $class_or_self->error( "Error preparing the query to get all country codes: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
602 0 $class_or_self->_set_cached_statement( countries => $sth );
603 }
604  
605 0 my $rv = eval{ $sth->execute };
606 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
607 {
608 0 $sth->finish;
609 0 return( $class_or_self->error( "Error executing the query to get all country codes: $@", "\nSQL query was ", $sth->{Statement} ) );
610 }
611 elsif( !defined( $rv ) )
612 {
613 0 $sth->finish;
614 0 return( $class_or_self->error( "Error executing the query to get all country codes: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
615 }
616  
617 0 my $all = eval{ $sth->fetchall_arrayref([0]) };
618 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
619 {
620 0 $sth->finish;
621 0 return( $class_or_self->error( "Error retrieving all country codes: $@", "\nSQL query was ", $sth->{Statement} ) );
622 }
623 # We check for definedness, which means an error in DBI
624 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
625 {
626 0 $sth->finish;
627 0 return( $class_or_self->error( "Error retrieving all country codes: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
628 }
629 0 $sth->finish;
630 0 my $codes = [map{ $_->[0] } @$all];
631 0 ▶ return( wantarray() ? @$codes : $codes );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
632 }
633  
634 # Returns the path to the bundled tz.sqlite3 database
635 2 ▶sub datafile { return( $DB_FILE ) }
Subroutine datafile: called CC=1 SCAR=0.0
Pod documented
636  
637 0 ▶sub designation_charcount { return( $_[0]->{designation_charcount} ) }
Subroutine designation_charcount: not called CC=1 SCAR=6.9
Pod documented
638  
639 # disable_mem_cache()
640 # Class method. Disables the package-level cache and clears all cached entries.
641 sub disable_mem_cache
642 4 ▶{
Subroutine disable_mem_cache: called CC=1 SCAR=0.0
Pod documented
643 4 my $class = shift( @_ );
644 4 $USE_MEM_CACHE = 0;
645 4 $_CACHE = {};
646 4 return( $class );
647 }
648  
649 # enable_mem_cache( [$bool] )
650 # Class method. Enables or disables the package-level memory cache for all
651 # subsequent TimeZone->new() calls. When enabled, constructed objects are
652 # stored in a process-global hash keyed by canonical zone name; repeated
653 # calls for the same name return the cached object without a DB query.
654 #
655 # Equivalent to passing use_cache_mem => 1 on every new() call.
656 sub enable_mem_cache
657 2 ▶{
Subroutine enable_mem_cache: called CC=3 SCAR=11.4
Pod documented
658 2 my( $class, $bool ) = @_;
659 2 ▶ $bool //= 1;
Condition50%1/2
$bool //= 1
l!l
02
MC/DC0%0/1
$bool //= 1
$bool
Truth table50%1/2
A
A= $bool
Aresult
11
00
660 2 ▶ $USE_MEM_CACHE = $bool ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 2 0 2
661 2 return( $class );
662 }
663  
664 # NOTE: Error handling
665 sub error
666 27 ▶{
Subroutine error: called CC=8 SCAR=21.3
Pod documented
667 27 my $self = shift( @_ );
668 27 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 13 27
669 {
670 14 require DateTime::Lite::Exception;
671 14 ▶ my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 14 14
672 14 my $e = DateTime::Lite::Exception->new({
673 skip_frames => 1,
674 message => $msg,
675 });
676 14 $ERROR = $e;
677 14 ▶ $self->{error} = $e if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 2 12 14
678 14 ▶ if( $self->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 14 14
679 {
680 0 die( $self->{error} );
681 }
682 else
683 {
684 14 ▶ warn( $msg ) if( warnings::enabled( 'DateTime::Lite') );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Lite") 14 0 14
685 14 ▶ rreturn( DateTime::Lite::NullObject->new ) if( want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("OBJECT") 0 14 14
686 14 return;
687 }
688 }
689 13 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1 12 13
690 }
691  
692 sub extended_aliases
693 0 ▶{
Subroutine extended_aliases: not called CC=11 SCAR=48.8
Pod documented
694 # Can be called as class method, instance method, or plain function.
695 0 my $class_or_self = shift( @_ );
696 0 local $@;
697 0 my $sth;
698 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'all_extended_aliases' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("all_extended_aliases")) 0 0 0
699 {
700 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
701 0 my $query = q{SELECT abbreviation AS alias_name, zone_name FROM v_extended_alias ORDER BY alias_name};
702 $sth = eval
703 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all extended timezone aliases: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all extended timezone aliases: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
704 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
705 } || return( $class_or_self->error( "Error preparing the query to get all extended timezone aliases: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
706 0 $class_or_self->_set_cached_statement( all_extended_aliases => $sth );
707 }
708  
709 0 my $rv = eval{ $sth->execute };
710 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
711 {
712 0 $sth->finish;
713 0 return( $class_or_self->error( "Error executing the query to get all extended timezone aliases: $@", "\nSQL query was ", $sth->{Statement} ) );
714 }
715 elsif( !defined( $rv ) )
716 {
717 0 $sth->finish;
718 0 return( $class_or_self->error( "Error executing the query to get all extended timezone aliases: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
719 }
720  
721 0 my $all = eval{ $sth->fetchall_arrayref([0,1]) };
722 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
723 {
724 0 $sth->finish;
725 0 return( $class_or_self->error( "Error retrieving all timezone extended aliases: $@", "\nSQL query was ", $sth->{Statement} ) );
726 }
727 # We check for definedness, which means an error in DBI
728 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
729 {
730 0 $sth->finish;
731 0 return( $class_or_self->error( "Error retrieving all timezone extended aliases: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
732 }
733 0 $sth->finish;
734 0 my $aliases = +{map{ $_->[0] => $_->[1] } @$all};
735 0 ▶ return( wantarray() ? %$aliases : $aliases );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
736 }
737  
738 sub fatal
739 14 ▶{
Subroutine fatal: called CC=5 SCAR=22.7
Pod documented
740 14 my $this = shift( @_ );
741 14 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 14 14
742 {
743 0 ▶ if( ref( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this) { } 0 0 0
744 {
745 0 return( $this->_set_get_prop( 'fatal', @_ ) );
746 }
747 else
748 {
749 0 ▶ warn( "Cannot call fatal in mutator mode as a class method." ) if( warnings::enabled( 'DateTime::Lite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Lite") 0 0 0
750 }
751 }
752 14 ▶ return( ref( $this ) ? $this->_set_get_prop( 'fatal' ) : $FATAL_EXCEPTIONS );
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 2 12 14
753 }
754  
755 0 ▶sub footer_tz_string { return( $_[0]->{footer_tz_string} ); }
Subroutine footer_tz_string: not called CC=1 SCAR=6.9
Pod documented
756  
757 {
758 20 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
759 20 *has_dst = \&has_dst_changes;
760 }
761  
762 # Returns true if this timezone observes DST transitions
763 sub has_dst_changes
764 5 ▶{
Subroutine has_dst_changes: called CC=4 SCAR=15.6
Pod documented
765 5 my $self = shift( @_ );
766 5 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 5 5
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
005
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
767 {
768 0 return( $self->error( "has_dst_changes() must be called on a class instance." ) );
769 }
770 5 ▶ return( $self->{has_dst} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'has_dst'} ? : 1 4 5
771 }
772  
773 0 ▶sub is_canonical { return( $_[0]->{_is_canonical} ? 1 : 0 ); }
Subroutine is_canonical: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'_is_canonical'} ? : 0 0 0
774  
775 sub is_dst_for_datetime
776 13 ▶{
Subroutine is_dst_for_datetime: called CC=11 SCAR=28.8
Pod documented
777 13 my $self = shift( @_ );
778 13 my $dt = shift( @_ );
779 13 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 13 13
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
780 {
781 0 return( $self->error( "is_dst_for_datetime() must be called on a class instance." ) );
782 }
783 13 ▶ return(0) if( $self->{is_floating} || $self->{is_utc} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_floating"} or $self->{"is_utc"} 1 12 13
Condition66%2/3
$self->{"is_floating"} or $self->{"is_utc"}
l!l&&r!l&&!r
0112
MC/DC50%1/2
$self->{"is_floating"} or $self->{"is_utc"}
$self->{"is_floating"} $self->{"is_utc"}
Truth table66%2/3
A or B
A= $self->{"is_floating"}B= $self->{"is_utc"}
ABresult
1X1
011
000
784 12 ▶ return(0) if( exists( $self->{fixed_offset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"fixed_offset"} 0 12 12
785 12 ▶ if( !defined( $dt ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $dt) { } 0 12 12
elsif (not builtin::blessed($dt)) { } 0 12 12
elsif (not $dt->can('utc_rd_as_seconds')) { } 0 12 12
786 {
787 0 return( $self->error( "No DateTime::Lite or DateTime object was provided." ) );
788 }
789 elsif( !Scalar::Util::blessed( $dt ) )
790 {
791 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") is not an object." ) );
792 }
793 elsif( !$dt->can( 'utc_rd_as_seconds' ) )
794 {
795 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") does not support the method 'utc_rd_as_seconds'." ) );
796 }
797 12 ▶ my $span = $self->_lookup_span( $dt->utc_rd_as_seconds ) || return(0);
Condition50%1/2
$self->_lookup_span($dt->utc_rd_as_seconds) || (return 0)
l!l
120
MC/DC0%0/1
$self->_lookup_span($dt->utc_rd_as_seconds) || (return 0)
$self->_lookup_span($dt->utc_rd_as_seconds)
Truth table50%1/2
A
A= $self->_lookup_span($dt->utc_rd_as_seconds)
Aresult
11
00
798 12 ▶ return( $span->{is_dst} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$span->{'is_dst'} ? : 4 8 12
799 }
800  
801 534 ▶sub is_floating { return( $_[0]->{is_floating} ? 1 : 0 ) }
Subroutine is_floating: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'is_floating'} ? : 63 471 534
802  
803 5 ▶sub is_olson { return( $_[0]->{is_olson} ? 1 : 0 ) }
Subroutine is_olson: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'is_olson'} ? : 4 1 5
804  
805 459 ▶sub is_utc { return( $_[0]->{is_utc} ? 1 : 0 ) }
Subroutine is_utc: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'is_utc'} ? : 337 122 459
806  
807 sub is_valid_name
808 0 ▶{
Subroutine is_valid_name: not called CC=7 SCAR=40.3
Pod documented
809 # Can be called as class method, instance method, or plain function.
810 0 my $class_or_self = shift( @_ );
811 0 ▶ my $name = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $class_or_self->error('No timezone name was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $class_or_self->error('No timezone name was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
812 return( $class_or_self->error( "No timezone name was provided." ) );
813 0 my $canon = $class_or_self->_resolve_alias( $name );
814 0 ▶ return( $class_or_self->pass_error ) if( !defined( $canon ) && $class_or_self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $canon and $class_or_self->error 0 0 0
Condition0%0/3
not defined $canon and $class_or_self->error
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $canon and $class_or_self->error
not defined $canon $class_or_self->error
Truth table0%0/3
not(A) and B
A= not defined $canonB= $class_or_self->error
ABresult
0X0
100
111
815 0 my $orig;
816 0 ▶ if( defined( $canon ) && $name ne $canon )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $canon and $name ne $canon) 0 0 0
Condition0%0/3
defined $canon and $name ne $canon
!ll&&!rl&&r
000
MC/DC0%0/2
defined $canon and $name ne $canon
defined $canon $name ne $canon
Truth table0%0/3
A and B
A= defined $canonB= $name ne $canon
ABresult
0X0
100
111
817 {
818 0 $orig = $name;
819 0 $name = $canon;
820 }
821 0 ▶ my $ref = $class_or_self->_get_zone_info( $name ) || return(0);
Condition0%0/2
$class_or_self->_get_zone_info($name) || (return 0)
l!l
00
MC/DC0%0/1
$class_or_self->_get_zone_info($name) || (return 0)
$class_or_self->_get_zone_info($name)
Truth table0%0/2
A
A= $class_or_self->_get_zone_info($name)
Aresult
11
00
822 0 return(1);
823 }
824  
825 0 ▶sub isstd_count { return( $_[0]->{isstd_count} ); }
Subroutine isstd_count: not called CC=1 SCAR=6.9
Pod documented
826  
827 0 ▶sub isut_count { return( $_[0]->{isut_count} ); }
Subroutine isut_count: not called CC=1 SCAR=6.9
Pod documented
828  
829 0 ▶sub latitude { return( $_[0]->{latitude} ) }
Subroutine latitude: not called CC=1 SCAR=6.9
Pod documented
830  
831 0 ▶sub leap_count { return( $_[0]->{leap_count} ); }
Subroutine leap_count: not called CC=1 SCAR=6.9
Pod documented
832  
833 0 ▶sub longitude { return( $_[0]->{longitude} ) }
Subroutine longitude: not called CC=1 SCAR=6.9
Pod documented
834  
835 218 ▶sub name { return( $_[0]->{name} ) }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
836  
837 sub names_in_category
838 0 ▶{
Subroutine names_in_category: not called CC=12 SCAR=50.5
Pod documented
839 # Can be called as class method, instance method, or plain function.
840 0 my $class_or_self = shift( @_ );
841 0 ▶ my $cat = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $class_or_self->error('No timezone category was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $class_or_self->error('No timezone category was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
842 return( $class_or_self->error( "No timezone category was provided." ) );
843 0 local $@;
844 0 my $sth;
845 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'names_in_category' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("names_in_category")) 0 0 0
846 {
847 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
848 0 my $query = <<'SQL';
849 SELECT DISTINCT
850 CASE
851 WHEN subregion IS NOT NULL
852 THEN subregion || '/' || location
853 ELSE location
854 END AS name
855 FROM zones
856 WHERE category = ?
857 ORDER BY name
858 SQL
859 $sth = eval
860 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all local names for a category: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all local names for a category: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
861 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
862 } || return( $class_or_self->error( "Error preparing the query to get all local names for a category: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
863 0 $class_or_self->_set_cached_statement( names_in_category => $sth );
864 }
865  
866 0 my $rv = eval{ $sth->execute( $cat ) };
867 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
868 {
869 0 $sth->finish;
870 0 return( $class_or_self->error( "Error executing the query to get all local names for the category $cat: $@", "\nSQL query was ", $sth->{Statement} ) );
871 }
872 elsif( !defined( $rv ) )
873 {
874 0 $sth->finish;
875 0 return( $class_or_self->error( "Error executing the query to get all local names for the category $cat: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
876 }
877  
878 0 my $all = eval{ $sth->fetchall_arrayref([0]) };
879 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
880 {
881 0 $sth->finish;
882 0 return( $class_or_self->error( "Error retrieving all local names for the category $cat: $@", "\nSQL query was ", $sth->{Statement} ) );
883 }
884 # We check for definedness, which means an error in DBI
885 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
886 {
887 0 $sth->finish;
888 0 return( $class_or_self->error( "Error retrieving all local names for the category $cat: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
889 }
890 0 $sth->finish;
891 0 my $names = [map{ $_->[0] } @$all];
892 0 ▶ return( wantarray() ? @$names : $names );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
893 }
894  
895 sub names_in_country
896 0 ▶{
Subroutine names_in_country: not called CC=12 SCAR=50.5
Pod documented
897 # Can be called as class method, instance method, or plain function.
898 0 my $class_or_self = shift( @_ );
899 0 ▶ my $code = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $class_or_self->error('No country code was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $class_or_self->error('No country code was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
900 return( $class_or_self->error( "No country code was provided." ) );
901 # Because the country codes are stored in upper case, and there is no need to have SQL change the case when we can do it.
902 0 $code = uc( $code );
903 0 local $@;
904 0 my $sth;
905 0 ▶ unless( $sth = $class_or_self->_get_cached_statement( 'names_in_country' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class_or_self->_get_cached_statement("names_in_country")) 0 0 0
906 {
907 0 ▶ my $dbh = $class_or_self->_dbh || return( $class_or_self->pass_error );
Condition0%0/2
$class_or_self->_dbh || (return $class_or_self->pass_error)
l!l
00
MC/DC0%0/1
$class_or_self->_dbh || (return $class_or_self->pass_error)
$class_or_self->_dbh
Truth table0%0/2
A
A= $class_or_self->_dbh
Aresult
11
00
908 0 my $query = <<'SQL';
909 SELECT DISTINCT
910 z.name
911 FROM zones z
912 JOIN json_each( z.countries ) j
913 ON 1 = 1
914 WHERE j.value = ?
915 ORDER BY z.name
916 SQL
917 $sth = eval
918 0 ▶ {
Condition0%0/2
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all zone names for a given country code: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
00
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class_or_self->error('Error preparing the query to get all zone names for a given country code: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table0%0/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
919 0 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
920 } || return( $class_or_self->error( "Error preparing the query to get all zone names for a given country code: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
921 0 $class_or_self->_set_cached_statement( names_in_country => $sth );
922 }
923  
924 0 my $rv = eval{ $sth->execute( $code ) };
925 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $rv) { } 0 0 0
926 {
927 0 $sth->finish;
928 0 return( $class_or_self->error( "Error executing the query to get all zone names for the country code $code: $@", "\nSQL query was ", $sth->{Statement} ) );
929 }
930 elsif( !defined( $rv ) )
931 {
932 0 $sth->finish;
933 0 return( $class_or_self->error( "Error executing the query to get all zone names for the country code $code: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
934 }
935  
936 0 my $all = eval{ $sth->fetchall_arrayref([0]) };
937 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $all and $sth->errstr) { } 0 0 0
938 {
939 0 $sth->finish;
940 0 return( $class_or_self->error( "Error retrieving all zone names for the country code $code: $@" ) );
941 }
942 # We check for definedness, which means an error in DBI
943 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition0%0/3
not defined $all and $sth->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table0%0/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
944 {
945 0 $sth->finish;
946 0 return( $class_or_self->error( "Error retrieving all zone names for the country code $code: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
947 }
948 0 $sth->finish;
949 0 my $names = [map{ $_->[0] } @$all];
950 0 ▶ return( wantarray() ? @$names : $names );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
951 }
952  
953 sub offset_as_seconds
954 6 ▶{
Subroutine offset_as_seconds: called CC=15 SCAR=33.3
Pod documented
955 # Can be called as class method, instance method, or plain function.
956 6 my $class_or_self = shift( @_ );
957 6 my $offset = shift( @_ );
958  
959 6 ▶ return( $class_or_self->error( "No offset was provided." ) ) unless( defined( $offset ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 2 4 6
960 4 ▶ return(0) if( $offset eq '0' );
Branch: 1 branch
BranchTrueFalseTotal
if $offset eq 0 0 4 4
961  
962 4 my( $sign, $hours, $minutes, $seconds );
963 # Colon form: [+-]H:MM[:SS] or [+-]HH:MM[:SS]
964 4 ▶ if( $offset =~ /\A([+-])?(\d{1,2}):(\d{2})(?::(\d{2}))?\z/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($offset =~ /\A([+-])?(\d{1,2}):(\d{2})(?::(\d{2}))?\z/) { } 3 1 4
elsif ($offset =~ /\A([+-])?(\d{2})(\d{2})(\d{2})?\z/) { } 1 0 1
965 {
966 3 ( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 );
967 }
968 # Compact form: [+-]HHMM[SS]
969 elsif( $offset =~ /\A([+-])?(\d{2})(\d{2})(\d{2})?\z/ )
970 {
971 1 ( $sign, $hours, $minutes, $seconds ) = ( $1, $2, $3, $4 );
972 }
973 else
974 {
975 # Will return undef in scalar context, and an empty list in list context.
976 0 return( $class_or_self->error( "Unsupported offset format '$offset'" ) );
977 }
978  
979 4 ▶ $sign //= '+';
Condition50%1/2
$sign //= "+"
l!l
40
MC/DC0%0/1
$sign //= "+"
$sign
Truth table50%1/2
A
A= $sign
Aresult
11
00
980 4 ▶ unless( $hours >= 0 && $hours <= 99 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($hours >= 0 and $hours <= 99) 0 4 4
Condition33%1/3
$hours >= 0 and $hours <= 99
!ll&&!rl&&r
004
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
981 {
982 0 return( $class_or_self->error( "Unsupported hours ($hours). It must be greater or equal to 0 and lower or equal to 99." ) );
983 }
984 4 ▶ unless( $minutes >= 0 && $minutes <= 59 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($minutes >= 0 and $minutes <= 59) 0 4 4
Condition33%1/3
$minutes >= 0 and $minutes <= 59
!ll&&!rl&&r
004
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
985 {
986 0 return( $class_or_self->error( "Unsupported minutes ($minutes). It must be greater or equal to 0 and lower or equal to 59." ) );
987 }
988 4 ▶ if( defined( $seconds ) && ( $seconds < 0 || $seconds > 59 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seconds and $seconds < 0 || $seconds > 59) 0 4 4
Condition16%1/6
defined $seconds and $seconds < 0 || $seconds > 59
!ll&&!rl&&r
400
$seconds < 0 or $seconds > 59
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $seconds and $seconds < 0 || $seconds > 59
defined $seconds $seconds < 0 $seconds > 59
Truth table25%1/4
A and B or C
A= defined $secondsB= $seconds < 0C= $seconds > 59
ABCresult
0XX0
1000
11X1
1011
989 {
990 0 return( $class_or_self->error( "Unsupported seconds ($seconds). It must be greater or equal to 0 and lower or equal to 59." ) );
991 }
992  
993 4 my $total = $hours * 3600 + $minutes * 60;
994 4 ▶ $total += $seconds if( defined( $seconds ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $seconds 0 4 4
995 4 ▶ $total *= -1 if( $sign eq '-' );
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "-" 2 2 4
996  
997 4 return( $total );
998 }
999  
1000 # Class or instance method: convert an offset in seconds to a formatted string.
1001 # With no separator: "+0900"; with ':' as separator: "+09:00"
1002 # Drop-in compatible with DateTime::TimeZone->offset_as_string.
1003 sub offset_as_string
1004 10 ▶{
Subroutine offset_as_string: called CC=9 SCAR=24.8
Pod documented
1005 # Can be called as class method, instance method, or plain function.
1006 # Second arg is the offset in seconds; third (optional) is a separator
1007 # (':' gives '+09:00' style, default gives '+0900').
1008 10 my $class_or_self = shift( @_ );
1009 10 my $offset = shift( @_ );
1010 10 ▶ my $sep = shift( @_ ) // '';
Condition100%2/2
shift @_ // ""
l!l
64
MC/DC100%1/1
shift @_ // ""
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
1011 10 ▶ unless( defined( $offset ) && length( $offset // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $offset and length($offset // "")) 0 10 10
Condition40%2/5
defined $offset and length($offset // "")
!ll&&!rl&&r
0010
$offset // ""
l!l
100
MC/DC0%0/2
defined $offset and length($offset // "")
defined $offset $offset
Truth table33%1/3
A and B
A= defined $offsetB= $offset
ABresult
0X0
100
111
1012 {
1013 0 return( $class_or_self->error( "No offset was provided." ) );
1014 }
1015 10 ▶ unless( $offset >= -359999 && $offset <= 359999 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($offset >= -359999 and $offset <= 359999) 0 10 10
Condition33%1/3
$offset >= -359999 and $offset <= 359999
!ll&&!rl&&r
0010
MC/DC0%0/2
$offset >= -359999 and $offset <= 359999
$offset >= -359999 $offset <= 359999
Truth table33%1/3
A and B
A= $offset >= -359999B= $offset <= 359999
ABresult
0X0
100
111
1016 {
1017 0 return( $class_or_self->error( "Offset must be comprised between -359999 and 359999" ) );
1018 }
1019  
1020 10 ▶ my $sign = $offset < 0 ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 ? : 2 8 10
1021 10 my $abs = abs( $offset );
1022 10 my $hours = int( $abs / 3600 );
1023 10 my $mins = int( ( $abs % 3600 ) / 60 );
1024 10 my $secs = $abs % 60;
1025  
1026 10 ▶ if( $secs )
Branch: 1 branch
BranchTrueFalseTotal
if ($secs) 0 10 10
1027 {
1028 0 return( sprintf( "%s%02d%s%02d%s%02d", $sign, $hours, $sep, $mins, $sep, $secs ) );
1029 }
1030 10 return( sprintf( "%s%02d%s%02d", $sign, $hours, $sep, $mins ) );
1031 }
1032  
1033 sub offset_for_datetime
1034 102 ▶{
Subroutine offset_for_datetime: called CC=10 SCAR=28.2
Pod documented
1035 102 my $self = shift( @_ );
1036 102 my $dt = shift( @_ );
1037 102 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 102 102
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
00102
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1038 {
1039 0 return( $self->error( "offset_for_datetime() must be called on a class instance." ) );
1040 }
1041 102 ▶ return(0) if( $self->{is_floating} || $self->{is_utc} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_floating"} or $self->{"is_utc"} 2 100 102
Condition66%2/3
$self->{"is_floating"} or $self->{"is_utc"}
l!l&&r!l&&!r
02100
MC/DC50%1/2
$self->{"is_floating"} or $self->{"is_utc"}
$self->{"is_floating"} $self->{"is_utc"}
Truth table66%2/3
A or B
A= $self->{"is_floating"}B= $self->{"is_utc"}
ABresult
1X1
011
000
1042 100 ▶ return( $self->{fixed_offset} ) if( exists( $self->{fixed_offset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"fixed_offset"} 0 100 100
1043 100 ▶ if( !defined( $dt ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $dt) { } 0 100 100
elsif (not builtin::blessed($dt)) { } 0 100 100
elsif (not $dt->can('utc_rd_as_seconds')) { } 0 100 100
1044 {
1045 0 return( $self->error( "No DateTime::Lite or DateTime object was provided." ) );
1046 }
1047 elsif( !Scalar::Util::blessed( $dt ) )
1048 {
1049 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") is not an object." ) );
1050 }
1051 elsif( !$dt->can( 'utc_rd_as_seconds' ) )
1052 {
1053 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") does not support the method 'utc_rd_as_seconds'." ) );
1054 }
1055 100 ▶ my $span = $self->_lookup_span( $dt->utc_rd_as_seconds ) || return(0);
Condition50%1/2
$self->_lookup_span($dt->utc_rd_as_seconds) || (return 0)
l!l
1000
MC/DC0%0/1
$self->_lookup_span($dt->utc_rd_as_seconds) || (return 0)
$self->_lookup_span($dt->utc_rd_as_seconds)
Truth table50%1/2
A
A= $self->_lookup_span($dt->utc_rd_as_seconds)
Aresult
11
00
1056 100 return( $span->{offset} + 0 );
1057 }
1058  
1059 sub offset_for_local_datetime
1060 266 ▶{
Subroutine offset_for_local_datetime: called CC=10 SCAR=28.2
Pod documented
1061 266 my $self = shift( @_ );
1062 266 my $dt = shift( @_ );
1063 266 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 266 266
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
00266
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1064 {
1065 0 return( $self->error( "offset_for_local_datetime() must be called on a class instance." ) );
1066 }
1067 266 ▶ return(0) if( $self->{is_floating} || $self->{is_utc} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_floating"} or $self->{"is_utc"} 193 73 266
Condition66%2/3
$self->{"is_floating"} or $self->{"is_utc"}
l!l&&r!l&&!r
019373
MC/DC50%1/2
$self->{"is_floating"} or $self->{"is_utc"}
$self->{"is_floating"} $self->{"is_utc"}
Truth table66%2/3
A or B
A= $self->{"is_floating"}B= $self->{"is_utc"}
ABresult
1X1
011
000
1068 73 ▶ return( $self->{fixed_offset} ) if( exists( $self->{fixed_offset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"fixed_offset"} 0 73 73
1069 73 ▶ if( !defined( $dt ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $dt) { } 0 73 73
elsif (not builtin::blessed($dt)) { } 0 73 73
elsif (not $dt->can('local_rd_as_seconds')) { } 0 73 73
1070 {
1071 0 return( $self->error( "No DateTime::Lite or DateTime object was provided." ) );
1072 }
1073 elsif( !Scalar::Util::blessed( $dt ) )
1074 {
1075 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") is not an object." ) );
1076 }
1077 elsif( !$dt->can( 'local_rd_as_seconds' ) )
1078 {
1079 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") does not support the method 'local_rd_as_seconds'." ) );
1080 }
1081 73 ▶ my $span = $self->_lookup_span_local( $dt->local_rd_as_seconds ) || return(0);
Condition50%1/2
$self->_lookup_span_local($dt->local_rd_as_seconds) || (return 0)
l!l
730
MC/DC0%0/1
$self->_lookup_span_local($dt->local_rd_as_seconds) || (return 0)
$self->_lookup_span_local($dt->local_rd_as_seconds)
Truth table50%1/2
A
A= $self->_lookup_span_local($dt->local_rd_as_seconds)
Aresult
11
00
1082 73 return( $span->{offset} + 0 );
1083 }
1084  
1085 sub pass_error
1086 3 ▶{
Subroutine pass_error: called CC=37 SCAR=61.3
Pod undocumented
1087 3 my $self = shift( @_ );
1088 3 ▶ my $pack = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1089 3 my $opts = {};
1090 3 my( $err, $class, $code );
1091 20 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1092 3 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 3 3
1093 {
1094 # Either an hash defining a new error and this will be passed along to error(); or
1095 # an hash with a single property: { class => 'Some::ExceptionClass' }
1096 0 ▶ if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1097 {
1098 0 $opts = $_[0];
1099 }
1100 else
1101 {
1102 0 ▶ if( scalar( @_ ) > 1 && ref( $_[-1] ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1 and ref $_[-1] eq "HASH") 0 0 0
Condition0%0/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1 ref $_[-1] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
1103 {
1104 0 $opts = pop( @_ );
1105 }
1106 0 $err = $_[0];
1107 }
1108 }
1109 3 ▶ $err = $opts->{error} if( !defined( $err ) && CORE::exists( $opts->{error} ) && defined( $opts->{error} ) && CORE::length( $opts->{error} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"} 0 3 3
Condition33%3/9
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
!ll&&!rl&&r
300
not defined $err and exists $opts->{"error"} and defined $opts->{"error"}
!ll&&!rl&&r
300
not defined $err and exists $opts->{"error"}
!ll&&!rl&&r
030
MC/DC0%0/4
not defined $err and exists $opts->{"error"} and defined $opts->{"error"} and length $opts->{"error"}
not defined $err exists $opts->{"error"} defined $opts->{"error"} length $opts->{"error"}
Truth table20%1/5
not(A) and B and C and D
A= not defined $errB= exists $opts->{"error"}C= defined $opts->{"error"}D= length $opts->{"error"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1110 # We set $class only if the hash provided is a one-element hash and not an error-defining hash
1111 3 ▶ $class = $opts->{class} if( CORE::exists( $opts->{class} ) && defined( $opts->{class} ) && CORE::length( $opts->{class} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"} 0 3 3
Condition33%2/6
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
!ll&&!rl&&r
300
exists $opts->{"class"} and defined $opts->{"class"}
!ll&&!rl&&r
300
MC/DC0%0/3
exists $opts->{"class"} and defined $opts->{"class"} and length $opts->{"class"}
exists $opts->{"class"} defined $opts->{"class"} length $opts->{"class"}
Truth table25%1/4
A and B and C
A= exists $opts->{"class"}B= defined $opts->{"class"}C= length $opts->{"class"}
ABCresult
0XX0
10X0
1100
1111
1112 3 ▶ $code = $opts->{code} if( CORE::exists( $opts->{code} ) && defined( $opts->{code} ) && CORE::length( $opts->{code} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"} 0 3 3
Condition33%2/6
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
!ll&&!rl&&r
300
exists $opts->{"code"} and defined $opts->{"code"}
!ll&&!rl&&r
300
MC/DC0%0/3
exists $opts->{"code"} and defined $opts->{"code"} and length $opts->{"code"}
exists $opts->{"code"} defined $opts->{"code"} length $opts->{"code"}
Truth table25%1/4
A and B and C
A= exists $opts->{"code"}B= defined $opts->{"code"}C= length $opts->{"code"}
ABCresult
0XX0
10X0
1100
1111
1113  
1114 # called with no argument, most likely from the same class to pass on an error
1115 # set up earlier by another method; or
1116 # with an hash containing just one argument class => 'Some::ExceptionClass'
1117 3 ▶ if( !defined( $err ) && ( !scalar( @_ ) || defined( $class ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $err and !scalar(@_) || defined $class) { } 3 0 3
elsif (defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class) { } 0 0 0
Condition33%2/6
not defined $err and !scalar(@_) || defined $class
!ll&&!rl&&r
003
not scalar @_ or defined $class
l!l&&r!l&&!r
300
MC/DC0%0/3
not defined $err and !scalar(@_) || defined $class
not defined $err not scalar @_ defined $class
Truth table25%1/4
not(A) and not(B) or C
A= not defined $errB= not scalar @_C= defined $class
ABCresult
0XX0
1000
11X1
1011
1118 {
1119 # $error is a previous erro robject
1120 3 ▶ my $error = ref( $self ) ? $self->{error} : length( ${ $pack . '::ERROR' } ) ? ${ $pack . '::ERROR' } : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $self ? : 0 3 3
length ${$pack . '::ERROR';} ? : 3 0 3
1121 3 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 3 3
1122 {
1123 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef" );
1124 }
1125 else
1126 {
1127 3 ▶ $err = ( defined( $class ) ? bless( $error => $class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 3 3
1128 3 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 3 3
1129 }
1130 }
1131 ▶ elsif( defined( $err ) &&
Condition0%0/12
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class
!ll&&!rl&&r
000
defined $err and builtin::blessed($err)
!ll&&!rl&&r
000
scalar @_ == 1 or scalar @_ == 2 and defined $class
l!l&&r!l&&!r
000
scalar @_ == 2 and defined $class
!ll&&!rl&&r
000
MC/DC0%0/5
defined $err and builtin::blessed($err) and scalar @_ == 1 || scalar @_ == 2 && defined $class
defined $err builtin::blessed($err) scalar @_ == 1 scalar @_ == 2 defined $class
Truth table0%0/6
A and B and C or D and E
A= defined $errB= builtin::blessed($err)C= scalar @_ == 1D= scalar @_ == 2E= defined $class
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1132 Scalar::Util::blessed( $err ) &&
1133 ( scalar( @_ ) == 1 ||
1134 ( scalar( @_ ) == 2 && defined( $class ) )
1135 ) )
1136 {
1137 0 ▶ $self->{error} = ${ $pack . '::ERROR' } = ( defined( $class ) ? bless( $err => $class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 0 0
1138 0 ▶ $self->{error}->code( $code ) if( defined( $code ) && $self->{error}->can( 'code' ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code and $self->{"error"}->can("code") 0 0 0
Condition0%0/3
defined $code and $self->{"error"}->can("code")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $code and $self->{"error"}->can("code")
defined $code $self->{"error"}->can("code")
Truth table0%0/3
A and B
A= defined $codeB= $self->{"error"}->can("code")
ABresult
0X0
100
111
1139  
1140 0 ▶ if( $self->{fatal} || ( defined( ${"${pack}\::FATAL_EXCEPTIONS"} ) && ${"${pack}\::FATAL_EXCEPTIONS"} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fatal"} or defined ${"${pack}::FATAL_EXCEPTIONS";} and ${"${pack}::FATAL_EXCEPTIONS";}) 0 0 0
Condition0%0/6
$self->{"fatal"} or defined ${"${pack}::FATAL_EXCEPTIONS";} and ${"${pack}::FATAL_EXCEPTIONS";}
l!l&&r!l&&!r
000
defined ${"${pack}::FATAL_EXCEPTIONS";} and ${"${pack}::FATAL_EXCEPTIONS";}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"fatal"} or defined ${"${pack}::FATAL_EXCEPTIONS";} and ${"${pack}::FATAL_EXCEPTIONS";}
$self->{"fatal"} defined ${"${pack}::FATAL_EXCEPTIONS";} ${"${pack}::FATAL_EXCEPTIONS";}
Truth table0%0/4
A or B and C
A= $self->{"fatal"}B= defined ${"${pack}::FATAL_EXCEPTIONS";}C= ${"${pack}::FATAL_EXCEPTIONS";}
ABCresult
1XX1
0111
00X0
0100
1141 {
1142 0 die( $self->{error} );
1143 }
1144 }
1145 # If the error provided is not an object, we call error to create one
1146 else
1147 {
1148 0 return( $self->error( @_ ) );
1149 }
1150  
1151 3 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 3 3
1152 {
1153 0 rreturn( DateTime::Lite::NullObject->new );
1154 }
1155 3 return;
1156 }
1157  
1158 sub resolve_abbreviation
1159 28 ▶{
Subroutine resolve_abbreviation: called CC=49 SCAR=43.2
Pod documented
1160 28 my $self = shift( @_ );
1161 28 ▶ my $abbr = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No timezone abbreviation was provided.'))
l!l
280
MC/DC0%0/1
shift @_ || (return $self->error('No timezone abbreviation was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1162 return( $self->error( "No timezone abbreviation was provided." ) );
1163 28 my %opts = @_;
1164  
1165 28 local $@;
1166 28 my $sth;
1167 my $has_offset = (
1168 defined( $opts{utc_offset} ) &&
1169 Scalar::Util::looks_like_number( $opts{utc_offset} )
1170 28 ▶ ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'utc_offset'} && &Scalar::Util::looks_like_number($opts{'utc_offset'}) ? : 1 27 28
Condition66%2/3
defined $opts{"utc_offset"} and &Scalar::Util::looks_like_number($opts{"utc_offset"})
!ll&&!rl&&r
2701
MC/DC50%1/2
defined $opts{"utc_offset"} and &Scalar::Util::looks_like_number($opts{"utc_offset"})
defined $opts{"utc_offset"} &Scalar::Util::looks_like_number($opts{"utc_offset"})
Truth table66%2/3
A and B
A= defined $opts{"utc_offset"}B= &Scalar::Util::looks_like_number($opts{"utc_offset"})
ABresult
0X0
100
111
1171 28 ▶ my $extended = $opts{extended} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'extended'} ? : 8 20 28
1172  
1173 # Build the dynamic WHERE skeleton for the IANA types query.
1174 # Based on Locale::Unicode::Data::_fetch_all(): each filter value may be prefixed
1175 # with a comparison operator (<, <=, >, >=, =, !=).
1176 # When period is an array ref, each element adds one AND condition on
1177 # MAX(tr.trans_time). When period is the special string 'current', the query
1178 # is restricted to the zone's last transition (MAX = most recent) and requires
1179 # that last transition to be in the past, effectively returning only zones that
1180 # still use the abbreviation today.
1181 28 my $op_map = { '=' => 'IS', '!=' => 'IS NOT' };
1182  
1183 # Conditions on MAX(tr.trans_time) built from the 'period' option.
1184 # Each element of @period_skels is a HAVING clause fragment.
1185 # @period_key_parts accumulates tokens for the cache key; they must distinguish
1186 # ISO date strings from raw epoch integers since each uses a different SQL
1187 # placeholder form ('e' = epoch, 'd' = ISO date).
1188 28 my @period_skels = ();
1189 28 my @period_values = ();
1190 28 my @period_key_parts = ();
1191 28 my $current_special = 0;
1192  
1193 28 ▶ if( defined( $opts{period} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"period"}) 8 20 28
1194 {
1195 my @period_items = ref( $opts{period} ) eq 'ARRAY'
1196 1 ? @{$opts{period}}
1197 8 ▶ : ( $opts{period} );
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'period'} eq 'ARRAY' ? : 1 7 8
1198  
1199 8 foreach my $item ( @period_items )
1200 {
1201 9 ▶ if( !defined( $item ) || !length( $item ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $item and length $item) 1 8 9
Condition66%2/3
defined $item and length $item
!ll&&!rl&&r
018
MC/DC50%1/2
defined $item and length $item
defined $item length $item
Truth table66%2/3
A and B
A= defined $itemB= length $item
ABresult
0X0
100
111
1202 {
1203 1 return( $self->error( "Empty value in 'period' option for resolve_abbreviation." ) );
1204 }
1205  
1206 # Special value 'current': return only zones whose most recent transition
1207 # for this abbreviation is in the past and whose next transition has not yet
1208 # occurred. Handled via LEFT JOIN below.
1209 8 ▶ if( $item eq 'current' )
Branch: 1 branch
BranchTrueFalseTotal
if ($item eq "current") 1 7 8
1210 {
1211 1 $current_special = 1;
1212 1 push( @period_key_parts, 'current' );
1213 1 next;
1214 }
1215  
1216 7 my $op = '>';
1217 7 my $val = $item;
1218 # Strip leading operator prefix, e.g. '>1950-01-01' -> op='>', val='1950-01-01'
1219 7 ▶ if( $val =~ s/^[[:blank:]\h]*(?<op>\<|\<=|\>|\>=|=|\!=)[[:blank:]\h]*(?<val>.+?)$/$+{val}/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s/^[[:blank:]\h]*(?<op>\<|\<=|\>|\>=|=|\!=)[[:blank:]\h]*(?<val>.+?)$/$+{"val"}/) 7 0 7
1220 {
1221 7 $op = $+{op};
1222 }
1223 7 ▶ $op = $op_map->{ $op } if( exists( $op_map->{ $op } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $op_map->{$op} 0 7 7
1224 # Dates are stored as Unix epoch integers; convert ISO date string via
1225 # SQLite strftime('%s', ...) so the user can pass '1950-01-01'.
1226 # Numeric values are used as-is (already epoch seconds).
1227 # IMPORTANT: the two paths generate different SQL, so the cache key must
1228 # distinguish them via 'e' (epoch int) vs 'd' (ISO date string).
1229 7 ▶ if( Scalar::Util::looks_like_number( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($val)) { } 1 6 7
1230 {
1231 # Use CAST(? AS INTEGER) rather than a bare ? to ensure SQLite
1232 # treats the bind value as an integer regardless of how DBD::SQLite
1233 # represents the Perl scalar internally (string vs numeric).
1234 1 push( @period_skels, "MAX(tr.trans_time) ${op} CAST(? AS INTEGER)" );
1235 1 push( @period_values, $val + 0 );
1236 1 push( @period_key_parts, "${op}e" );
1237 }
1238 else
1239 {
1240 6 push( @period_skels, "MAX(tr.trans_time) ${op} CAST(strftime('%s', ?) AS INTEGER)" );
1241 6 push( @period_values, $val );
1242 6 push( @period_key_parts, "${op}d" );
1243 }
1244 }
1245 }
1246  
1247 # The HAVING clause combines the utc_offset filter and any period conditions.
1248 # Because we GROUP BY zone to obtain MAX(trans_time) for ordering and period
1249 # filtering, utc_offset is also moved into HAVING (it is functionally constant
1250 # per (zone, abbreviation) pair so this is semantically equivalent).
1251 27 my @having_skels = ();
1252 27 my @having_values = ();
1253  
1254 27 ▶ if( $has_offset )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_offset) 1 26 27
1255 {
1256 1 push( @having_skels, "t.utc_offset = ?" );
1257 1 push( @having_values, $opts{utc_offset} );
1258 }
1259 27 push( @having_skels, @period_skels );
1260 27 push( @having_values, @period_values );
1261  
1262 # Build the HAVING clause first so we can derive the cache key from the actual SQL
1263 # string, which is provably collision-free.
1264 # 'current' restricts to zones where the matched abbreviation type's most recent
1265 # transition IS the zone's overall most recent transition, meaning the abbreviation
1266 # is still active right now. The conditions are added directly to @having_skels so
1267 # that the HAVING keyword is always emitted when needed, avoiding any
1268 # GROUP BY / HAVING confusion.
1269 # A correlated subquery referencing the outer MAX() is not supported by SQLite in
1270 # HAVING; we use an independent scalar subquery instead.
1271 27 ▶ if( $current_special )
Branch: 1 branch
BranchTrueFalseTotal
if ($current_special) 1 26 27
1272 {
1273 1 push( @having_skels, <<'SQL' );
1274 MAX(tr.trans_time) <= CAST(strftime('%s', 'now') AS INTEGER)
1275 SQL
1276 1 push( @having_skels, <<'SQL' );
1277 MAX(tr.trans_time) = (
1278 SELECT MAX(tr2.trans_time)
1279 FROM transition tr2
1280 WHERE tr2.zone_id = t.zone_id
1281 )
1282 SQL
1283 }
1284 # Build the HAVING clause from all accumulated conditions.
1285 # Conditions are joined with AND; the HAVING keyword is only emitted when at least
1286 # one condition exists, keeping the SQL clean.
1287 27 my @having_parts = ();
1288 27 foreach my $skel ( @having_skels )
1289 {
1290 10 chomp( my $s = $skel );
1291 10 push( @having_parts, $s );
1292 }
1293 27 ▶ my $having_sql = scalar( @having_parts )
Branch: 1 branch
BranchTrueFalseTotal
scalar @having_parts ? : 7 20 27
1294 ? "\nHAVING " . join( "\n AND ", @having_parts )
1295 : "";
1296 # We JOIN transition to get MAX(trans_time) per zone for:
1297 # 1. Period filtering via HAVING on MAX(trans_time).
1298 # 2. Secondary sort keys: MIN(trans_time) = first use of the abbreviation,
1299 # MAX(trans_time) = most recent use.
1300 # DISTINCT is replaced by GROUP BY zone since we aggregate.
1301 #
1302 # Sort strategy (most discriminating first):
1303 # 1. is_active DESC: zones whose POSIX footer still mentions the
1304 # abbreviation come before zones that no longer use it.
1305 # 2. first_trans_time ASC: among active (or among inactive) zones,
1306 # the one that adopted the abbreviation earliest comes first.
1307 # 3. last_trans_time DESC: tie-break by persistence (still-using vs
1308 # early-abandoned) when first_trans_time is equal.
1309 # 4. z.name ASC: final deterministic tie-breaker.
1310 #
1311 # is_active cannot be computed in SQL (word-boundary regex over
1312 # footer_tz_string), so we fetch footer_tz_string, compute is_active in
1313 # Perl post-query, then re-sort. The SQL ORDER BY below applies the other
1314 # three keys, which is useful because the final Perl sort is stable over
1315 # rows already ordered by (first ASC, last DESC, name ASC).
1316 27 my $query = <<SQL;
1317 SELECT z.name AS zone_name, t.utc_offset, t.is_dst,
1318 z.footer_tz_string,
1319 MIN(tr.trans_time) AS first_trans_time,
1320 MAX(tr.trans_time) AS last_trans_time
1321 FROM types t
1322 JOIN zones z ON z.zone_id = t.zone_id
1323 JOIN transition tr ON tr.zone_id = t.zone_id AND tr.type_id = t.type_id
1324 WHERE z.canonical = 1
1325 AND t.abbreviation = ?
1326 GROUP BY z.name, t.utc_offset, t.is_dst, z.footer_tz_string${having_sql}
1327 ORDER BY first_trans_time ASC, last_trans_time DESC, z.name ASC
1328 SQL
1329 # Use the SQL string itself as the cache key - provably collision-free
1330 # regardless of any subtlety in the period_key_parts logic.
1331 27 my $cache_id = 'resolve_abbreviation_sql_' . $query;
1332 27 ▶ unless( $sth = $self->_get_cached_statement( $cache_id ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->_get_cached_statement($cache_id)) 9 18 27
1333 {
1334 9 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
90
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
1335 $sth = eval
1336 9 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Error preparing the abbreviation resolution query: ', $@ || $dbh->errstr, "\nSQL query was: $query"))
l!l
90
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Error preparing the abbreviation resolution query: ', $@ || $dbh->errstr, "\nSQL query was: $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
1337 9 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
1338 } || return( $self->error( "Error preparing the abbreviation resolution query: ", ( $@ || $dbh->errstr ), "\nSQL query was: $query" ) );
1339 9 $self->_set_cached_statement( $cache_id => $sth );
1340 }
1341  
1342 my $rv = eval
1343 27 {
1344 27 $sth->execute( $abbr, @having_values );
1345 };
1346 27 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 27 27
elsif (not defined $rv) { } 0 27 27
1347 {
1348 0 $sth->finish;
1349 0 return( $self->error( "Error executing the abbreviation resolution query for '$abbr': $@\nSQL query was: ", $sth->{Statement} ) );
1350 }
1351 elsif( !defined( $rv ) )
1352 {
1353 0 $sth->finish;
1354 0 return( $self->error( "Error executing the abbreviation resolution query for '$abbr': ", $sth->errstr, "\nSQL query was: ", $sth->{Statement} ) );
1355 }
1356  
1357 27 my $all = eval{ $sth->fetchall_arrayref( {} ) };
1358 27 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 27 27
elsif (not defined $all and $sth->errstr) { } 0 54 54
1359 {
1360 0 $sth->finish;
1361 0 return( $self->error( "Error retrieving abbreviation resolution results for '$abbr': $@\nSQL query was: ", $sth->{Statement} ) );
1362 }
1363 ▶ elsif( !defined( $all ) && $sth->errstr )
Condition33%1/3
not defined $all and $sth->errstr
!ll&&!rl&&r
2700
MC/DC0%0/2
not defined $all and $sth->errstr
not defined $all $sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $allB= $sth->errstr
ABresult
0X0
100
111
1364 {
1365 0 $sth->finish;
1366 0 return( $self->error( "Error retrieving abbreviation resolution results for '$abbr': ", $sth->errstr, "\nSQL query was: ", $sth->{Statement} ) );
1367 }
1368 27 $sth->finish;
1369  
1370 # IANA types table returned results: use them directly.
1371 27 ▶ if( @$all )
Branch: 1 branch
BranchTrueFalseTotal
if (@$all) 17 10 27
1372 {
1373 # Determine whether all candidates share the same UTC offset.
1374 # If they do, the abbreviation is unambiguous in terms of wall-clock meaning,
1375 # even if multiple zone names match (such as JST covering several Asian zones
1376 # all at +09:00). Genuinely ambiguous abbreviations such as IST or CST map to
1377 # different offsets and get ambiguous => 1.
1378 17 my %offsets = map{ $_->{utc_offset} => 1 } @$all;
1379 17 ▶ my $ambiguous = scalar( keys( %offsets ) ) > 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %offsets > 1 ? : 2 15 17
1380  
1381 # Compute is_active from footer_tz_string via word-bounded regex.
1382 # Alphabetic abbreviations: must not be adjacent to another alpha char
1383 # (so CEST's footer "CET-1CEST" does not match a search for "CST").
1384 # Numeric/sign-prefixed abbreviations (such as '-03' or '+0430'): must
1385 # appear wrapped in <...> per POSIX TZ spec. The regex is compiled
1386 # once per call; the resulting ~35 microseconds per call overhead
1387 # has been measured on the full 178-abbreviation test set.
1388 17 my $rx;
1389 17 ▶ if( $abbr =~ /^[A-Za-z]+\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($abbr =~ /^[A-Za-z]+\z/) { } 16 1 17
1390 {
1391 16 $rx = qr/(?:^|[^A-Za-z])\Q$abbr\E(?:[^A-Za-z]|\z)/;
1392 }
1393 else
1394 {
1395 1 $rx = qr/<\Q$abbr\E>/;
1396 }
1397  
1398 17 foreach my $row ( @$all )
1399 {
1400 260 my $footer = $row->{footer_tz_string};
1401 $row->{is_active} =
1402 260 ▶ ( defined( $footer ) && length( $footer ) && $footer =~ $rx )
Branch: 1 branch
BranchTrueFalseTotal
defined $footer && length $footer && $footer =~ /$rx/ ? : 155 105 260
Condition50%3/6
defined $footer and length $footer and $footer =~ /$rx/
!ll&&!rl&&r
0105155
defined $footer and length $footer
!ll&&!rl&&r
00260
MC/DC33%1/3
defined $footer and length $footer and $footer =~ /$rx/
defined $footer length $footer $footer =~ /$rx/
Truth table50%2/4
A and B and C
A= defined $footerB= length $footerC= $footer =~ /$rx/
ABCresult
0XX0
10X0
1100
1111
1403 ? 1 : 0;
1404 }
1405  
1406 # Re-sort with is_active as primary key. The SQL already gave us
1407 # (first_trans_time ASC, last_trans_time DESC, name ASC), so a
1408 # stable sort on is_active preserves that ordering within each group.
1409 # Perl's sort is stable since 5.8, so this is safe.
1410 17 my @sorted = sort { $b->{is_active} <=> $a->{is_active} } @$all;
1411  
1412 return([
1413 map
1414 {
1415 17 {
1416 zone_name => $_->{zone_name},
1417 utc_offset => $_->{utc_offset},
1418 is_dst => $_->{is_dst} ? 1 : 0,
1419 ambiguous => $ambiguous,
1420 is_active => $_->{is_active},
1421 extended => 0,
1422 first_trans_time => $_->{first_trans_time},
1423 last_trans_time => $_->{last_trans_time},
1424 }
1425 260 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$_->{'is_dst'} ? : 140 120 260
1426 @sorted
1427 ]);
1428 }
1429  
1430 # No results in the IANA types table.
1431 # If extended mode is not requested, fail with the standard message.
1432 10 ▶ unless( $extended )
Branch: 1 branch
BranchTrueFalseTotal
unless ($extended) 4 6 10
1433 {
1434 4 return( $self->error( "No timezone found for abbreviation '$abbr'." ) );
1435 }
1436  
1437 # Extended mode: fall back to the extended_aliases table.
1438 # Covers real-world abbreviations (such as BDT, CEST, JST) that are not stored as
1439 # type abbreviations in the IANA TZif data but map to known zones.
1440 # Note: extended aliases carry no utc_offset or is_dst data; those fields are
1441 # undef in the result. The caller must resolve offset from the zone itself if
1442 # needed.
1443 # Period filtering does not apply to extended aliases (no trans_time data).
1444 6 my $ext_sth;
1445 6 ▶ unless( $ext_sth = $self->_get_cached_statement( 'resolve_abbreviation_extended' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ext_sth = $self->_get_cached_statement("resolve_abbreviation_extended")) 2 4 6
1446 {
1447 2 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
1448 2 my $query = <<'SQL';
1449 SELECT ea.abbreviation, z.name AS zone_name, ea.is_primary
1450 FROM extended_aliases ea
1451 JOIN zones z ON z.zone_id = ea.zone_id
1452 WHERE ea.abbreviation = ?
1453 ORDER BY ea.is_primary DESC, z.name
1454 SQL
1455 $ext_sth = eval
1456 2 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Error preparing the extended alias resolution query: ', $@ || $dbh->errstr, "\nSQL query was: $query"))
l!l
20
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Error preparing the extended alias resolution query: ', $@ || $dbh->errstr, "\nSQL query was: $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
1457 2 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
1458 } || return( $self->error( "Error preparing the extended alias resolution query: ", ( $@ || $dbh->errstr ), "\nSQL query was: $query" ) );
1459 2 $self->_set_cached_statement( resolve_abbreviation_extended => $ext_sth );
1460 }
1461  
1462 6 my $ext_rv = eval{ $ext_sth->execute( $abbr ) };
1463 6 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 6 6
elsif (not defined $ext_rv) { } 0 6 6
1464 {
1465 0 $ext_sth->finish;
1466 0 return( $self->error( "Error executing the extended alias resolution query for '$abbr': $@\nSQL query was: ", $ext_sth->{Statement} ) );
1467 }
1468 elsif( !defined( $ext_rv ) )
1469 {
1470 0 $ext_sth->finish;
1471 0 return( $self->error( "Error executing the extended alias resolution query for '$abbr': ", $ext_sth->errstr, "\nSQL query was: ", $ext_sth->{Statement} ) );
1472 }
1473  
1474 6 my $ext_all = eval{ $ext_sth->fetchall_arrayref( {} ) };
1475 6 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 6 6
elsif (not defined $ext_all and $ext_sth->errstr) { } 0 12 12
1476 {
1477 0 $ext_sth->finish;
1478 0 return( $self->error( "Error retrieving extended alias results for '$abbr': $@\nSQL query was: ", $ext_sth->{Statement} ) );
1479 }
1480 ▶ elsif( !defined( $ext_all ) && $ext_sth->errstr )
Condition33%1/3
not defined $ext_all and $ext_sth->errstr
!ll&&!rl&&r
600
MC/DC0%0/2
not defined $ext_all and $ext_sth->errstr
not defined $ext_all $ext_sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $ext_allB= $ext_sth->errstr
ABresult
0X0
100
111
1481 {
1482 0 $ext_sth->finish;
1483 0 return( $self->error( "Error retrieving extended alias results for '$abbr': ", $ext_sth->errstr, "\nSQL query was: ", $ext_sth->{Statement} ) );
1484 }
1485 6 $ext_sth->finish;
1486  
1487 6 ▶ unless( @$ext_all )
Branch: 1 branch
BranchTrueFalseTotal
unless (@$ext_all) 1 5 6
1488 {
1489 1 return( $self->error( "No timezone found for abbreviation '$abbr' (including extended aliases)." ) );
1490 }
1491  
1492 # Ambiguity for extended aliases: more than one candidate with no single
1493 # is_primary designating the canonical choice.
1494 5 my $n_primary = scalar( grep{ $_->{is_primary} } @$ext_all );
1495 5 my $n_total = scalar( @$ext_all );
1496 5 ▶ my $ambiguous = ( $n_total > 1 && $n_primary != 1 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$n_total > 1 && $n_primary != 1 ? : 0 5 5
Condition66%2/3
$n_total > 1 and $n_primary != 1
!ll&&!rl&&r
320
MC/DC0%0/2
$n_total > 1 and $n_primary != 1
$n_total > 1 $n_primary != 1
Truth table66%2/3
A and B
A= $n_total > 1B= $n_primary != 1
ABresult
0X0
100
111
1497  
1498 return([
1499 map
1500 {
1501 5 {
1502 zone_name => $_->{zone_name},
1503 # Extended aliases carry no offset data.
1504 utc_offset => undef,
1505 is_dst => undef,
1506 ambiguous => $ambiguous,
1507 10 ▶ is_primary => $_->{is_primary} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$_->{'is_primary'} ? : 5 5 10
1508 extended => 1,
1509 }
1510 }
1511 @$ext_all
1512 ]);
1513 }
1514  
1515 sub short_name_for_datetime
1516 13 ▶{
Subroutine short_name_for_datetime: called CC=10 SCAR=28.7
Pod documented
1517 13 my $self = shift( @_ );
1518 13 my $dt = shift( @_ );
1519 13 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 13 13
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1520 {
1521 0 return( $self->error( "short_name_for_datetime() must be called on a class instance." ) );
1522 }
1523 13 ▶ return( 'floating' ) if( $self->{is_floating} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_floating"} 0 13 13
1524 13 ▶ return( 'UTC' ) if( $self->{is_utc} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_utc"} 1 12 13
1525 12 ▶ if( exists( $self->{fixed_offset} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"fixed_offset"}) 0 12 12
1526 {
1527 0 return( $self->offset_as_string( $self->{fixed_offset} ) );
1528 }
1529  
1530 12 ▶ if( !defined( $dt ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $dt) { } 0 12 12
elsif (not builtin::blessed($dt)) { } 0 12 12
elsif (not $dt->can('utc_rd_as_seconds')) { } 0 12 12
1531 {
1532 0 return( $self->error( "No DateTime::Lite or DateTime object was provided." ) );
1533 }
1534 elsif( !Scalar::Util::blessed( $dt ) )
1535 {
1536 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") is not an object." ) );
1537 }
1538 elsif( !$dt->can( 'utc_rd_as_seconds' ) )
1539 {
1540 0 return( $self->error( "The object provided (", overload::StrVal( $dt ), ") does not support the method 'utc_rd_as_seconds'." ) );
1541 }
1542 my $span = $self->_lookup_span( $dt->utc_rd_as_seconds ) ||
1543 12 ▶ return( $self->{name} );
Condition50%1/2
$self->_lookup_span($dt->utc_rd_as_seconds) || (return $self->{'name'})
l!l
120
MC/DC0%0/1
$self->_lookup_span($dt->utc_rd_as_seconds) || (return $self->{'name'})
$self->_lookup_span($dt->utc_rd_as_seconds)
Truth table50%1/2
A
A= $self->_lookup_span($dt->utc_rd_as_seconds)
Aresult
11
00
1544 12 return( $span->{short_name} );
1545 }
1546  
1547 0 ▶sub transition_count { return( $_[0]->{transition_count} ); }
Subroutine transition_count: not called CC=1 SCAR=6.9
Pod documented
1548  
1549 0 ▶sub type_count { return( $_[0]->{type_count} ); }
Subroutine type_count: not called CC=1 SCAR=6.9
Pod documented
1550  
1551 # Returns the tzdata version string from the database metadata, such as "2026a"
1552 sub tz_version
1553 1 ▶{
Subroutine tz_version: called CC=11 SCAR=30.5
Pod documented
1554 1 my $self = shift( @_ );
1555 1 local $@;
1556 1 my $sth;
1557 1 ▶ unless( $sth = $self->_get_cached_statement( 'tz_version' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->_get_cached_statement("tz_version")) 1 0 1
1558 {
1559 1 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
1560 1 my $query = "SELECT value FROM metadata WHERE key = 'tz_version'";
1561 1 local $@;
1562 $sth = eval
1563 1 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare tz_version query: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
10
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare tz_version query: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
1564 1 ▶ $dbh->prepare( $query )
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
1565 } || return( $self->error( "Cannot prepare tz_version query: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
1566 1 $self->_set_cached_statement( tz_version => $sth );
1567 }
1568  
1569 1 my $rv = eval{ $sth->execute };
1570 1 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not defined $rv) { } 0 1 1
1571 {
1572 0 $sth->finish;
1573 0 return( $self->error( "Error executing the query to get the tz_version: $@", "\nSQL query was ", $sth->{Statement} ) );
1574 }
1575 elsif( !defined( $rv ) )
1576 {
1577 0 $sth->finish;
1578 0 return( $self->error( "Error executing the query to get the tz_version: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
1579 }
1580 1 my $row = eval{ $sth->fetchrow_arrayref };
1581 1 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not defined $row and $sth->errstr) { } 0 2 2
1582 {
1583 0 $sth->finish;
1584 0 return( $self->error( "Error retrieving the tz_version: $@", "\nSQL query was ", $sth->{Statement} ) );
1585 }
1586 # We check for definedness, which means an error in DBI
1587 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition33%1/3
not defined $row and $sth->errstr
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
1588 {
1589 0 $sth->finish;
1590 0 return( $self->error( "Error retrieving the tz_version: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
1591 }
1592 1 $sth->finish;
1593 1 ▶ return( $row ? $row->[0] : undef );
Branch: 1 branch
BranchTrueFalseTotal
$row ? : 1 0 1
1594 }
1595  
1596 sub tzif_version
1597 0 ▶{
Subroutine tzif_version: not called CC=3 SCAR=24.8
Pod documented
1598 0 my $self = shift( @_ );
1599 0 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 0 0
Condition0%0/3
defined $self and ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table0%0/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
1600 {
1601 0 return( $self->error( "tzif_version() must be called on a class instance." ) );
1602 }
1603 0 return( $self->{tzif_version} );
1604 }
1605  
1606 # NOTE: Windows timezone name -> IANA mapping
1607 # Source: DateTime::TimeZone::Local::Win32 by Dave Rolsky and David Pinkowitz.
1608 # Built lazily via state in _local_tz_mswin32; consumes no memory on non-Windows
1609 # platforms.
1610 sub _build_win_to_iana
1611 0 ▶{
Subroutine _build_win_to_iana: not called CC=1 SCAR=6.9
1612 return(
1613 {
1614 0 'Afghanistan' => 'Asia/Kabul',
1615 'Afghanistan Standard Time' => 'Asia/Kabul',
1616 'Alaskan' => 'America/Anchorage',
1617 'Alaskan Standard Time' => 'America/Anchorage',
1618 'Aleutian Standard Time' => 'America/Adak',
1619 'Altai Standard Time' => 'Asia/Barnaul',
1620 'Arab' => 'Asia/Riyadh',
1621 'Arab Standard Time' => 'Asia/Riyadh',
1622 'Arabian' => 'Asia/Muscat',
1623 'Arabian Standard Time' => 'Asia/Muscat',
1624 'Arabic Standard Time' => 'Asia/Baghdad',
1625 'Argentina Standard Time' => 'America/Argentina/Buenos_Aires',
1626 'Armenian Standard Time' => 'Asia/Yerevan',
1627 'Astrakhan Standard Time' => 'Europe/Astrakhan',
1628 'Atlantic' => 'America/Halifax',
1629 'Atlantic Standard Time' => 'America/Halifax',
1630 'AUS Central' => 'Australia/Darwin',
1631 'AUS Central Standard Time' => 'Australia/Darwin',
1632 'Aus Central W. Standard Time' => 'Australia/Eucla',
1633 'AUS Eastern' => 'Australia/Sydney',
1634 'AUS Eastern Standard Time' => 'Australia/Sydney',
1635 'Azerbaijan Standard Time' => 'Asia/Baku',
1636 'Azores' => 'Atlantic/Azores',
1637 'Azores Standard Time' => 'Atlantic/Azores',
1638 'Bahia Standard Time' => 'America/Bahia',
1639 'Bangkok' => 'Asia/Bangkok',
1640 'Bangkok Standard Time' => 'Asia/Bangkok',
1641 'Bangladesh Standard Time' => 'Asia/Dhaka',
1642 'Beijing' => 'Asia/Shanghai',
1643 'Belarus Standard Time' => 'Europe/Minsk',
1644 'Bougainville Standard Time' => 'Pacific/Bougainville',
1645 'Canada Central' => 'America/Regina',
1646 'Canada Central Standard Time' => 'America/Regina',
1647 'Cape Verde Standard Time' => 'Atlantic/Cape_Verde',
1648 'Caucasus' => 'Asia/Yerevan',
1649 'Caucasus Standard Time' => 'Asia/Yerevan',
1650 'Cen. Australia' => 'Australia/Adelaide',
1651 'Cen. Australia Standard Time' => 'Australia/Adelaide',
1652 'Central' => 'America/Chicago',
1653 'Central America Standard Time' => 'America/Tegucigalpa',
1654 'Central Asia' => 'Asia/Almaty',
1655 'Central Asia Standard Time' => 'Asia/Almaty',
1656 'Central Brazilian Standard Time' => 'America/Cuiaba',
1657 'Central Europe' => 'Europe/Prague',
1658 'Central Europe Standard Time' => 'Europe/Prague',
1659 'Central European' => 'Europe/Belgrade',
1660 'Central European Standard Time' => 'Europe/Warsaw',
1661 'Central Pacific' => 'Pacific/Guadalcanal',
1662 'Central Pacific Standard Time' => 'Pacific/Guadalcanal',
1663 'Central Standard Time' => 'America/Chicago',
1664 'Central Standard Time (Mexico)' => 'America/Mexico_City',
1665 'Chatham Islands Standard Time' => 'Pacific/Chatham',
1666 'China' => 'Asia/Shanghai',
1667 'China Standard Time' => 'Asia/Shanghai',
1668 'Cuba Standard Time' => 'America/Havana',
1669 'Dateline' => '-1200',
1670 'Dateline Standard Time' => 'Etc/GMT+12',
1671 'E. Africa' => 'Africa/Nairobi',
1672 'E. Africa Standard Time' => 'Africa/Nairobi',
1673 'E. Australia' => 'Australia/Brisbane',
1674 'E. Australia Standard Time' => 'Australia/Brisbane',
1675 'E. Europe' => 'Europe/Helsinki',
1676 'E. Europe Standard Time' => 'Europe/Chisinau',
1677 'E. South America' => 'America/Sao_Paulo',
1678 'E. South America Standard Time' => 'America/Sao_Paulo',
1679 'Easter Island Standard Time' => 'Pacific/Easter',
1680 'Eastern' => 'America/New_York',
1681 'Eastern Standard Time' => 'America/New_York',
1682 'Eastern Standard Time (Mexico)' => 'America/Cancun',
1683 'Egypt' => 'Africa/Cairo',
1684 'Egypt Standard Time' => 'Africa/Cairo',
1685 'Ekaterinburg' => 'Asia/Yekaterinburg',
1686 'Ekaterinburg Standard Time' => 'Asia/Yekaterinburg',
1687 'Fiji' => 'Pacific/Fiji',
1688 'Fiji Standard Time' => 'Pacific/Fiji',
1689 'FLE' => 'Europe/Helsinki',
1690 'FLE Standard Time' => 'Europe/Helsinki',
1691 'Georgian Standard Time' => 'Asia/Tbilisi',
1692 'GFT' => 'Europe/Athens',
1693 'GFT Standard Time' => 'Europe/Athens',
1694 'GMT' => 'Europe/London',
1695 'GMT Standard Time' => 'Europe/London',
1696 'Greenland Standard Time' => 'America/Godthab',
1697 'Greenwich' => 'GMT',
1698 'Greenwich Standard Time' => 'GMT',
1699 'GTB' => 'Europe/Athens',
1700 'GTB Standard Time' => 'Europe/Athens',
1701 'Haiti Standard Time' => 'America/Port-au-Prince',
1702 'Hawaiian' => 'Pacific/Honolulu',
1703 'Hawaiian Standard Time' => 'Pacific/Honolulu',
1704 'India' => 'Asia/Kolkata',
1705 'India Standard Time' => 'Asia/Kolkata',
1706 'Iran' => 'Asia/Tehran',
1707 'Iran Standard Time' => 'Asia/Tehran',
1708 'Israel' => 'Asia/Jerusalem',
1709 'Israel Standard Time' => 'Asia/Jerusalem',
1710 'Jordan Standard Time' => 'Asia/Amman',
1711 'Kaliningrad Standard Time' => 'Europe/Kaliningrad',
1712 'Kamchatka Standard Time' => 'Asia/Kamchatka',
1713 'Korea' => 'Asia/Seoul',
1714 'Korea Standard Time' => 'Asia/Seoul',
1715 'Libya Standard Time' => 'Africa/Tripoli',
1716 'Line Islands Standard Time' => 'Pacific/Kiritimati',
1717 'Lord Howe Standard Time' => 'Australia/Lord_Howe',
1718 'Magadan Standard Time' => 'Asia/Magadan',
1719 'Magallanes Standard Time' => 'America/Punta_Arenas',
1720 'Marquesas Standard Time' => 'Pacific/Marquesas',
1721 'Mauritius Standard Time' => 'Indian/Mauritius',
1722 'Mexico' => 'America/Mexico_City',
1723 'Mexico Standard Time' => 'America/Mexico_City',
1724 'Mexico Standard Time 2' => 'America/Chihuahua',
1725 'Mid-Atlantic' => 'Atlantic/South_Georgia',
1726 'Mid-Atlantic Standard Time' => 'Atlantic/South_Georgia',
1727 'Middle East Standard Time' => 'Asia/Beirut',
1728 'Montevideo Standard Time' => 'America/Montevideo',
1729 'Morocco Standard Time' => 'Africa/Casablanca',
1730 'Mountain' => 'America/Denver',
1731 'Mountain Standard Time' => 'America/Denver',
1732 'Mountain Standard Time (Mexico)' => 'America/Mazatlan',
1733 'Myanmar Standard Time' => 'Asia/Rangoon',
1734 'N. Central Asia Standard Time' => 'Asia/Novosibirsk',
1735 'Namibia Standard Time' => 'Africa/Windhoek',
1736 'Nepal Standard Time' => 'Asia/Katmandu',
1737 'New Zealand' => 'Pacific/Auckland',
1738 'New Zealand Standard Time' => 'Pacific/Auckland',
1739 'Newfoundland' => 'America/St_Johns',
1740 'Newfoundland Standard Time' => 'America/St_Johns',
1741 'Norfolk Standard Time' => 'Pacific/Norfolk',
1742 'North Asia East Standard Time' => 'Asia/Irkutsk',
1743 'North Asia Standard Time' => 'Asia/Krasnoyarsk',
1744 'North Korea Standard Time' => 'Asia/Pyongyang',
1745 'Omsk Standard Time' => 'Asia/Omsk',
1746 'Pacific' => 'America/Los_Angeles',
1747 'Pacific SA' => 'America/Santiago',
1748 'Pacific SA Standard Time' => 'America/Santiago',
1749 'Pacific Standard Time' => 'America/Los_Angeles',
1750 'Pacific Standard Time (Mexico)' => 'America/Tijuana',
1751 'Pakistan Standard Time' => 'Asia/Karachi',
1752 'Paraguay Standard Time' => 'America/Asuncion',
1753 'Prague Bratislava' => 'Europe/Prague',
1754 'Qyzylorda Standard Time' => 'Asia/Qyzylorda',
1755 'Romance' => 'Europe/Paris',
1756 'Romance Standard Time' => 'Europe/Paris',
1757 'Russia Time Zone 10' => 'Asia/Srednekolymsk',
1758 'Russia Time Zone 11' => 'Asia/Anadyr',
1759 'Russia Time Zone 3' => 'Europe/Samara',
1760 'Russian' => 'Europe/Moscow',
1761 'Russian Standard Time' => 'Europe/Moscow',
1762 'SA Eastern' => 'America/Cayenne',
1763 'SA Eastern Standard Time' => 'America/Cayenne',
1764 'SA Pacific' => 'America/Bogota',
1765 'SA Pacific Standard Time' => 'America/Bogota',
1766 'SA Western' => 'America/Guyana',
1767 'SA Western Standard Time' => 'America/Guyana',
1768 'Saint Pierre Standard Time' => 'America/Miquelon',
1769 'Sakhalin Standard Time' => 'Asia/Sakhalin',
1770 'Samoa' => 'Pacific/Apia',
1771 'Samoa Standard Time' => 'Pacific/Apia',
1772 'Sao Tome Standard Time' => 'Africa/Sao_Tome',
1773 'Saratov Standard Time' => 'Europe/Saratov',
1774 'Saudi Arabia' => 'Asia/Riyadh',
1775 'Saudi Arabia Standard Time' => 'Asia/Riyadh',
1776 'SE Asia' => 'Asia/Bangkok',
1777 'SE Asia Standard Time' => 'Asia/Bangkok',
1778 'Singapore' => 'Asia/Singapore',
1779 'Singapore Standard Time' => 'Asia/Singapore',
1780 'South Africa' => 'Africa/Harare',
1781 'South Africa Standard Time' => 'Africa/Harare',
1782 'South Sudan Standard Time' => 'Africa/Juba',
1783 'Sri Lanka' => 'Asia/Colombo',
1784 'Sri Lanka Standard Time' => 'Asia/Colombo',
1785 'Sudan Standard Time' => 'Africa/Khartoum',
1786 'Syria Standard Time' => 'Asia/Damascus',
1787 'Sydney Standard Time' => 'Australia/Sydney',
1788 'Taipei' => 'Asia/Taipei',
1789 'Taipei Standard Time' => 'Asia/Taipei',
1790 'Tasmania' => 'Australia/Hobart',
1791 'Tasmania Standard Time' => 'Australia/Hobart',
1792 'Tocantins Standard Time' => 'America/Araguaina',
1793 'Tokyo' => 'Asia/Tokyo',
1794 'Tokyo Standard Time' => 'Asia/Tokyo',
1795 'Tomsk Standard Time' => 'Asia/Tomsk',
1796 'Tonga Standard Time' => 'Pacific/Tongatapu',
1797 'Transbaikal Standard Time' => 'Asia/Chita',
1798 'Turkey Standard Time' => 'Europe/Istanbul',
1799 'Turks And Caicos Standard Time' => 'America/Grand_Turk',
1800 'Ulaanbaatar Standard Time' => 'Asia/Ulaanbaatar',
1801 'US Eastern' => 'America/Indianapolis',
1802 'US Eastern Standard Time' => 'America/Indianapolis',
1803 'US Mountain' => 'America/Phoenix',
1804 'US Mountain Standard Time' => 'America/Phoenix',
1805 'UTC' => 'UTC',
1806 'UTC+13' => 'Etc/GMT-13',
1807 'UTC+12' => 'Etc/GMT-12',
1808 'UTC-02' => 'America/Noronha',
1809 'UTC-08' => 'Etc/GMT+8',
1810 'UTC-09' => 'Etc/GMT+9',
1811 'UTC-11' => 'Etc/GMT+11',
1812 'Venezuela Standard Time' => 'America/Caracas',
1813 'Vladivostok' => 'Asia/Vladivostok',
1814 'Vladivostok Standard Time' => 'Asia/Vladivostok',
1815 'Volgograd Standard Time' => 'Europe/Volgograd',
1816 'W. Australia' => 'Australia/Perth',
1817 'W. Australia Standard Time' => 'Australia/Perth',
1818 'W. Central Africa Standard Time' => 'Africa/Luanda',
1819 'W. Europe' => 'Europe/Berlin',
1820 'W. Europe Standard Time' => 'Europe/Berlin',
1821 'W. Mongolia Standard Time' => 'Asia/Hovd',
1822 'Warsaw' => 'Europe/Warsaw',
1823 'West Asia' => 'Asia/Karachi',
1824 'West Asia Standard Time' => 'Asia/Tashkent',
1825 'West Bank Standard Time' => 'Asia/Gaza',
1826 'West Pacific' => 'Pacific/Guam',
1827 'West Pacific Standard Time' => 'Pacific/Guam',
1828 'Western Brazilian Standard Time' => 'America/Rio_Branco',
1829 'Yakutsk' => 'Asia/Yakutsk',
1830 'Yakutsk Standard Time' => 'Asia/Yakutsk',
1831 'Yukon Standard Time' => 'America/Whitehorse',
1832 });
1833 }
1834  
1835 sub _dbh
1836 56 ▶{
Subroutine _dbh: called CC=23 SCAR=37.2
1837 56 my $self = shift( @_ );
1838 56 my $file = $DB_FILE;
1839  
1840 56 ▶ my $tid = ( $Config{useithreads} && $INC{'threads.pm'} && threads->can('tid') ) ? threads->tid() : $$;
Branch: 1 branch
BranchTrueFalseTotal
$DateTime::Lite::TimeZone::Config{'useithreads'} && $INC{'threads.pm'} && 'threads'->can('tid') ? : 0 56 56
Condition33%2/6
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"} and "threads"->can("tid")
!ll&&!rl&&r
5600
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
5600
MC/DC0%0/3
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"} and "threads"->can("tid")
$DateTime::Lite::TimeZone::Config{"useithreads"} $INC{"threads.pm"} "threads"->can("tid")
Truth table25%1/4
A and B and C
A= $DateTime::Lite::TimeZone::Config{"useithreads"}B= $INC{"threads.pm"}C= "threads"->can("tid")
ABCresult
0XX0
10X0
1100
1111
1841 56 ▶ if( $DBH &&
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file}) and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->isa("DBI::db") and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->ping) 42 14 56
Condition62%17/27
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file}) and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->isa("DBI::db") and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->ping
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file}) and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->isa("DBI::db")
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file})
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file}
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH"
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid}
!ll&&!rl&&r
14042
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}
!ll&&!rl&&r
01442
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH"
!ll&&!rl&&r
0056
MC/DC10%1/10
$DateTime::Lite::TimeZone::DBH and ref $DateTime::Lite::TimeZone::DBH eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid} and defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" and exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and $DateTime::Lite::TimeZone::DBH->{$tid}{$file} and builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file}) and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->isa("DBI::db") and $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->ping
$DateTime::Lite::TimeZone::DBH ref $DateTime::Lite::TimeZone::DBH eq "HASH" exists $DateTime::Lite::TimeZone::DBH->{$tid} defined $DateTime::Lite::TimeZone::DBH->{$tid} ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file} $DateTime::Lite::TimeZone::DBH->{$tid}{$file} builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file}) $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->isa("DBI::db") $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->ping
Truth table18%2/11
A and B and C and D and E and F and G and H and I and J
A= $DateTime::Lite::TimeZone::DBHB= ref $DateTime::Lite::TimeZone::DBH eq "HASH"C= exists $DateTime::Lite::TimeZone::DBH->{$tid}D= defined $DateTime::Lite::TimeZone::DBH->{$tid}E= ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH"F= exists $DateTime::Lite::TimeZone::DBH->{$tid}{$file}G= $DateTime::Lite::TimeZone::DBH->{$tid}{$file}H= builtin::blessed($DateTime::Lite::TimeZone::DBH->{$tid}{$file})I= $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->isa("DBI::db")J= $DateTime::Lite::TimeZone::DBH->{$tid}{$file}->ping
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
110XXXXXXX0
1110XXXXXX0
11110XXXXX0
111110XXXX0
1111110XXX0
11111110XX0
111111110X0
11111111100
11111111111
1842 ref( $DBH ) eq 'HASH' &&
1843 exists( $DBH->{ $tid } ) &&
1844 defined( $DBH->{ $tid } ) &&
1845 ref( $DBH->{ $tid } ) eq 'HASH' &&
1846 exists( $DBH->{ $tid }->{ $file } ) &&
1847 $DBH->{ $tid }->{ $file } &&
1848 Scalar::Util::blessed( $DBH->{ $tid }->{ $file } ) &&
1849 $DBH->{ $tid }->{ $file }->isa( 'DBI::db' ) &&
1850 $DBH->{ $tid }->{ $file }->ping )
1851 {
1852 42 return( $DBH->{ $tid }->{ $file } );
1853 }
1854  
1855 14 ▶ return( $self->error( "Timezone database file '$file' does not exist." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 14 14
1856 unless( -e( $file ) );
1857 14 ▶ return( $self->error( "Timezone database file '$file' is not a regular file." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 14 14
1858 unless( -f( $file ) );
1859 14 ▶ return( $self->error( "Timezone database file '$file' is empty." ) )
Branch: 1 branch
BranchTrueFalseTotal
if -z $file 0 14 14
1860 if( -z( $file ) );
1861 14 ▶ return( $self->error( "Timezone database file '$file' is not readable by uid $>." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 14 14
1862 unless( -r( $file ) );
1863  
1864 # Require SQLite >= 3.6.19 for foreign key support (DBD::SQLite >= 1.27)
1865 14 ▶ if( version->parse( $DBD::SQLite::sqlite_version ) < version->parse( '3.6.19' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse($DBD::SQLite::sqlite_version) < "version"->parse("3.6.19")) 0 14 14
1866 {
1867 0 return( $self->error( "SQLite version 3.6.19 or higher is required. You have $DBD::SQLite::sqlite_version" ) );
1868 }
1869  
1870 14 my $params = {};
1871 14 ▶ if( $HAS_CONSTANTS )
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::TimeZone::HAS_CONSTANTS) 14 0 14
1872 {
1873 14 require DBD::SQLite::Constants;
1874 14 $params->{sqlite_open_flags} = DBD::SQLite::Constants::SQLITE_OPEN_READONLY();
1875 }
1876  
1877 14 ▶ my $dbh = DBI->connect(
Condition50%1/2
'DBI'->connect("dbi:SQLite:dbname=$file", '', '', {%$params, 'RaiseError', 0, 'PrintError', 0, 'AutoCommit', 1, 'sqlite_unicode', 1}) || (return $self->error("Cannot connect to timezone database '${file}': $DBI::errstr"))
l!l
140
MC/DC0%0/1
'DBI'->connect("dbi:SQLite:dbname=$file", '', '', {%$params, 'RaiseError', 0, 'PrintError', 0, 'AutoCommit', 1, 'sqlite_unicode', 1}) || (return $self->error("Cannot connect to timezone database '${file}': $DBI::errstr"))
'DBI'->connect("dbi:SQLite:dbname=$file", '', '', {%$params, 'RaiseError', 0, 'PrintError', 0, 'AutoCommit', 1, 'sqlite_unicode', 1})
Truth table50%1/2
A
A= 'DBI'->connect("dbi:SQLite:dbname=$file", '', '', {%$params, 'RaiseError', 0, 'PrintError', 0, 'AutoCommit', 1, 'sqlite_unicode', 1})
Aresult
11
00
1878 "dbi:SQLite:dbname=$file", '', '',
1879 {
1880 %$params,
1881 RaiseError => 0,
1882 PrintError => 0,
1883 AutoCommit => 1,
1884 sqlite_unicode => 1,
1885 }
1886 ) || return( $self->error( "Cannot connect to timezone database '$file': $DBI::errstr" ) );
1887  
1888 14 $dbh->do( "PRAGMA foreign_keys = ON" );
1889 14 $dbh->do( "PRAGMA query_only = ON" );
1890  
1891 # Native UTF-8 string mode available since DBD::SQLite 1.68
1892 14 ▶ if( !$MISSING_AUTO_UTF8_DECODING )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DateTime::Lite::TimeZone::MISSING_AUTO_UTF8_DECODING) 14 0 14
1893 {
1894 14 $dbh->{sqlite_string_mode} = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK();
1895 }
1896 14 ▶ $DBH->{ $tid } //= {};
Condition50%1/2
$DateTime::Lite::TimeZone::DBH->{$tid} //= {}
l!l
014
MC/DC0%0/1
$DateTime::Lite::TimeZone::DBH->{$tid} //= {}
$DateTime::Lite::TimeZone::DBH->{$tid}
Truth table50%1/2
A
A= $DateTime::Lite::TimeZone::DBH->{$tid}
Aresult
11
00
1897 14 return( $DBH->{ $tid }->{ $file } = $dbh );
1898 }
1899  
1900 sub _dbh_add_user_defined_functions
1901 1 ▶{
Subroutine _dbh_add_user_defined_functions: called CC=15 SCAR=39.0
1902 1 my( $this, $dbh ) = @_;
1903 1 ▶ if( defined( $SQLITE_HAS_MATH_FUNCTIONS ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $DateTime::Lite::TimeZone::SQLITE_HAS_MATH_FUNCTIONS) { } 0 1 1
elsif (not $dbh) { } 0 1 1
1904 {
1905 0 return( $SQLITE_HAS_MATH_FUNCTIONS );
1906 }
1907 elsif( !$dbh )
1908 {
1909 0 return( $this->error( "No database handle was provided." ) );
1910 }
1911 # Determine whether SQLite's built-in math functions are available.
1912 #
1913 # Detection strategy based on SQLite version:
1914 #
1915 # >= 3.35.0 (2021-03-12): built-in math functions may be available, but only if
1916 # compiled with -DSQLITE_ENABLE_MATH_FUNCTIONS (which DBD::SQLite enables by
1917 # default since ~1.72). Query pragma_function_list for 'sqrt' to confirm. Since
1918 # this check runs before any UDF is registered, a hit is guaranteed native.
1919 #
1920 # >= 3.16.0 (2017-01-02) and < 3.35.0: pragma_function_list exists but the math
1921 # functions do not, so querying it would be pointless.
1922 # Register Perl UDFs directly.
1923 #
1924 # < 3.16.0 (2017-01-02): pragma_function_list is not available as a table-valued
1925 # function. Register Perl UDFs directly.
1926 #
1927 # UDFs via sqlite_create_function() are available on all SQLite >= 3.0.0.
1928 # <https://sqlite.org/lang_mathfunc.html>
1929 # <https://sqlite.org/pragma.html#pragfunc>
1930 1 my $sqlite_ver = version->parse( $DBD::SQLite::sqlite_version );
1931 1 my $has_math = 0;
1932 # The virtual table pragma_function_list is available, so we query it to check if the math functions have been compiled with the macro 'SQLITE_ENABLE_MATH_FUNCTIONS'
1933 1 ▶ if( $sqlite_ver >= version->parse( '3.35.0' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlite_ver >= "version"->parse("3.35.0")) 1 0 1
1934 {
1935 1 my $query = "SELECT name FROM pragma_function_list WHERE name = 'sqrt'";
1936 1 local $@;
1937 my $sth = eval
1938 1 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $this->error('Error preparing the query to check if SQLite has math functions: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
10
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $this->error('Error preparing the query to check if SQLite has math functions: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
1939 1 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
1940 } || return( $this->error( "Error preparing the query to check if SQLite has math functions: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
1941 1 my $rv = eval{ $sth->execute };
1942 1 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not defined $rv) { } 0 1 1
1943 {
1944 0 $sth->finish;
1945 0 return( $this->error( "Error executing the query to check if SQLite has math functions: $@", "\nSQL query was ", $sth->{Statement} ) );
1946 }
1947 elsif( !defined( $rv ) )
1948 {
1949 0 $sth->finish;
1950 0 return( $this->error( "Error executing the query to check if SQLite has math functions: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
1951 }
1952 1 my $row = eval{ $sth->fetchrow_arrayref };
1953 1 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not defined $row and $sth->errstr) { } 0 2 2
1954 {
1955 0 $sth->finish;
1956 0 return( $this->error( "Error retrieving the value to check if SQLite has math functions: $@", "\nSQL query was ", $sth->{Statement} ) );
1957 }
1958 # We check for definedness, which means an error in DBI
1959 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition33%1/3
not defined $row and $sth->errstr
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
1960 {
1961 0 $sth->finish;
1962 0 return( $this->error( "Error retrieving the value to check if SQLite has math functions: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
1963 }
1964 1 $sth->finish;
1965 # Don't assume anything.
1966 1 ▶ if( $row && ref( $row ) eq 'ARRAY' && $row->[0] )
Branch: 1 branch
BranchTrueFalseTotal
if ($row and ref $row eq "ARRAY" and $row->[0]) 1 0 1
Condition33%2/6
$row and ref $row eq "ARRAY" and $row->[0]
!ll&&!rl&&r
001
$row and ref $row eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/3
$row and ref $row eq "ARRAY" and $row->[0]
$row ref $row eq "ARRAY" $row->[0]
Truth table25%1/4
A and B and C
A= $rowB= ref $row eq "ARRAY"C= $row->[0]
ABCresult
0XX0
10X0
1100
1111
1967 {
1968 1 $has_math = 1;
1969 }
1970 }
1971  
1972 1 ▶ if( $has_math )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_math) { } 1 0 1
1973 {
1974 # <https://sqlite.org/lang_mathfunc.html>
1975 1 $SQLITE_HAS_MATH_FUNCTIONS = 1;
1976 }
1977 else
1978 {
1979 # Native math functions are absent or unconfirmed; register Perl UDFs.
1980 0 require POSIX;
1981 0 ▶ $dbh->sqlite_create_function( 'sqrt', 1, sub{ CORE::sqrt( $_[0] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1982 0 ▶ $dbh->sqlite_create_function( 'sin', 1, sub{ CORE::sin( $_[0] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1983 0 ▶ $dbh->sqlite_create_function( 'cos', 1, sub{ CORE::cos( $_[0] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1984 0 ▶ $dbh->sqlite_create_function( 'asin', 1, sub{ POSIX::asin( $_[0] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1985 0 $SQLITE_HAS_MATH_FUNCTIONS = 0;
1986 }
1987 1 return(1);
1988 }
1989  
1990 # _decode_sql_array() decode the JSON array and returns an array reference.
1991 sub _decode_sql_array
1992 0 ▶{
Subroutine _decode_sql_array: not called CC=5 SCAR=34.0
1993 0 my $self = shift( @_ );
1994 0 ▶ die( "\$cldr->_decode_sql_array( \$data )" ) if( @_ != 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 0 0
1995 0 my $data = shift( @_ );
1996 # No data was provided
1997 0 ▶ if( !defined( $data ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $data) { } 0 0 0
elsif (ref $data) { } 0 0 0
1998 {
1999 0 return;
2000 }
2001 # Should not be a reference, but a plain string
2002 elsif( ref( $data ) )
2003 {
2004 0 die( "\$cldr->_decode_sql_array( \$data )" );
2005 }
2006  
2007 0 my $j = $JSON_CLASS->new->relaxed;
2008 0 local $@;
2009 my $decoded = eval
2010 0 {
2011 0 $j->decode( $data );
2012 };
2013 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2014 {
2015 0 warn( "Warning only: error attempting to decode $JSON_CLASS array: $@" );
2016 0 $decoded = [];
2017 }
2018 0 return( $decoded );
2019 }
2020  
2021 # _decode_sql_arrays() takes an hash reference, or an array of hash reference,
2022 # and decode the array fields of those tuples
2023 sub _decode_sql_arrays
2024 62 ▶{
Subroutine _decode_sql_arrays: called CC=17 SCAR=40.1
2025 62 my $self = shift( @_ );
2026 62 ▶ die( "\$cldr->_decode_sql_arrays( \$array_ref_of_array_fields, \$data )" ) if( @_ != 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 62 62
2027 62 my( $where, $ref ) = @_;
2028 62 ▶ if( ref( $where ) ne 'ARRAY' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $where ne 'ARRAY') { } 0 62 62
elsif (not defined $ref) { } 0 62 62
elsif (ref($ref // '') ne 'HASH' and builtin::reftype($ref // '') ne 'ARRAY') { } 0 124 124
2029 {
2030 0 die( "\$cldr->_decode_sql_arrays( \$array_ref_of_array_fields, \$data )" );
2031 }
2032 # No data was provided
2033 elsif( !defined( $ref ) )
2034 {
2035 0 return;
2036 }
2037 ▶ elsif( ref( $ref // '' ) ne 'HASH' && Scalar::Util::reftype( $ref // '' ) ne 'ARRAY' )
Condition28%2/7
ref($ref // "") ne "HASH" and builtin::reftype($ref // "") ne "ARRAY"
!ll&&!rl&&r
6200
$ref // ""
l!l
620
$ref // ""
l!l
00
MC/DC0%0/2
ref($ref // "") ne "HASH" and builtin::reftype($ref // "") ne "ARRAY"
$ref $ref
Truth table0%0/3
A and B
A= $refB= $ref
ABresult
0X0
100
111
2038 {
2039 0 die( "\$cldr->_decode_sql_arrays( \$array_ref_of_array_fields, \$data )" );
2040 }
2041  
2042 62 my $j = $JSON_CLASS->new->relaxed;
2043 62 local $@;
2044 62 ▶ if( ref( $ref ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref eq 'HASH') { } 62 0 62
elsif (builtin::reftype($ref) eq 'ARRAY') { } 0 0 0
2045 {
2046 62 foreach my $field ( @$where )
2047 {
2048 62 ▶ if( exists( $ref->{ $field } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ref->{$field} and defined $ref->{$field} and length $ref->{$field}) 60 2 62
Condition66%4/6
exists $ref->{$field} and defined $ref->{$field} and length $ref->{$field}
!ll&&!rl&&r
2060
exists $ref->{$field} and defined $ref->{$field}
!ll&&!rl&&r
0260
MC/DC33%1/3
exists $ref->{$field} and defined $ref->{$field} and length $ref->{$field}
exists $ref->{$field} defined $ref->{$field} length $ref->{$field}
Truth table50%2/4
A and B and C
A= exists $ref->{$field}B= defined $ref->{$field}C= length $ref->{$field}
ABCresult
0XX0
10X0
1100
1111
2049 defined( $ref->{ $field } ) &&
2050 length( $ref->{ $field } ) )
2051 {
2052 my $decoded = eval
2053 60 {
2054 60 $j->decode( $ref->{ $field } );
2055 };
2056 60 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 60 60
2057 {
2058 0 warn( "Warning only: error attempting to decode $JSON_CLASS array in field \"${field}\" for value '", $ref->{ $field }, "': $@" );
2059 0 $ref->{ $field } = [];
2060 }
2061 else
2062 {
2063 60 $ref->{ $field } = $decoded;
2064 }
2065 }
2066 }
2067 }
2068 elsif( Scalar::Util::reftype( $ref ) eq 'ARRAY' )
2069 {
2070 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
2071 {
2072 0 ▶ if( ref( $ref->[$i] ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref->[$i] ne "HASH") 0 0 0
2073 {
2074 0 warn( "SQL data at offset ${i} is not an HASH reference." );
2075 0 next;
2076 }
2077 0 $self->_decode_sql_arrays( $where, $ref->[$i] );
2078 }
2079 }
2080 62 return( $ref );
2081 }
2082  
2083 # Retrieve a cached prepared statement by ID.
2084 # Keyed by db file path so statements survive interpreter-level reuse.
2085 sub _get_cached_statement
2086 365 ▶{
Subroutine _get_cached_statement: called CC=11 SCAR=26.1
2087 365 my $self = shift( @_ );
2088 365 my $id = shift( @_ );
2089 365 ▶ die( "No statement ID provided." ) unless( defined( $id ) && length( $id ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 0 365 365
Condition33%1/3
defined $id and length $id
!ll&&!rl&&r
00365
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table33%1/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
2090 365 my $file = $DB_FILE;
2091 365 ▶ my $tid = ( $Config{useithreads} && $INC{'threads.pm'} && threads->can('tid') ) ? threads->tid() : $$;
Branch: 1 branch
BranchTrueFalseTotal
$DateTime::Lite::TimeZone::Config{'useithreads'} && $INC{'threads.pm'} && 'threads'->can('tid') ? : 0 365 365
Condition33%2/6
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"} and "threads"->can("tid")
!ll&&!rl&&r
36500
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
36500
MC/DC0%0/3
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"} and "threads"->can("tid")
$DateTime::Lite::TimeZone::Config{"useithreads"} $INC{"threads.pm"} "threads"->can("tid")
Truth table25%1/4
A and B and C
A= $DateTime::Lite::TimeZone::Config{"useithreads"}B= $INC{"threads.pm"}C= "threads"->can("tid")
ABCresult
0XX0
10X0
1100
1111
2092 365 ▶ $STHS->{ $tid } //= {};
Condition100%2/2
$DateTime::Lite::TimeZone::STHS->{$tid} //= {}
l!l
35114
MC/DC100%1/1
$DateTime::Lite::TimeZone::STHS->{$tid} //= {}
$DateTime::Lite::TimeZone::STHS->{$tid}
Truth table100%2/2
A
A= $DateTime::Lite::TimeZone::STHS->{$tid}
Aresult
11
00
2093 365 ▶ $STHS->{ $tid }->{ $file } //= {};
Condition100%2/2
$DateTime::Lite::TimeZone::STHS->{$tid}{$file} //= {}
l!l
35114
MC/DC100%1/1
$DateTime::Lite::TimeZone::STHS->{$tid}{$file} //= {}
$DateTime::Lite::TimeZone::STHS->{$tid}{$file}
Truth table100%2/2
A
A= $DateTime::Lite::TimeZone::STHS->{$tid}{$file}
Aresult
11
00
2094 365 my $sth = $STHS->{ $tid }->{ $file }->{ $id };
2095 365 ▶ if( defined( $sth ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sth and builtin::blessed($sth) and $sth->isa("DBI::st")) 309 56 365
Condition66%4/6
defined $sth and builtin::blessed($sth) and $sth->isa("DBI::st")
!ll&&!rl&&r
560309
defined $sth and builtin::blessed($sth)
!ll&&!rl&&r
560309
MC/DC33%1/3
defined $sth and builtin::blessed($sth) and $sth->isa("DBI::st")
defined $sth builtin::blessed($sth) $sth->isa("DBI::st")
Truth table50%2/4
A and B and C
A= defined $sthB= builtin::blessed($sth)C= $sth->isa("DBI::st")
ABCresult
0XX0
10X0
1100
1111
2096 Scalar::Util::blessed( $sth ) &&
2097 $sth->isa( 'DBI::st' ) )
2098 {
2099 309 return( $sth );
2100 }
2101 56 return;
2102 }
2103  
2104 # DateTime::Lite::TimeZone->_get_zone_info( $name );
2105 # $tz->_get_zone_info( $name );
2106 sub _get_zone_info
2107 63 ▶{
Subroutine _get_zone_info: called CC=11 SCAR=28.3
2108 63 my $self = shift( @_ );
2109 63 my $name = shift( @_ );
2110 63 local $@;
2111 # Verify the zone exists and cache its metadata
2112 63 my $sth;
2113 63 ▶ unless( $sth = $self->_get_cached_statement( 'get_zone_info' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->_get_cached_statement("get_zone_info")) 12 51 63
2114 {
2115 12 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
120
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
2116 # We handle each step of building the query, so we can report on any error with better accuracy.
2117 12 my $query = q{SELECT * FROM zones WHERE name = ?};
2118 $sth = eval
2119 12 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Error preparing the query to get the timezone information: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
120
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Error preparing the query to get the timezone information: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
2120 12 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
2121 } || return( $self->error( "Error preparing the query to get the timezone information: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
2122 12 $self->_set_cached_statement( get_zone_info => $sth );
2123 }
2124  
2125 63 my $rv = eval{ $sth->execute( $name ) };
2126 63 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 63 63
elsif (not defined $rv) { } 0 63 63
2127 {
2128 0 $sth->finish;
2129 0 return( $self->error( "Error executing the query to get the timezone information for $name: $@", "\nSQL query was ", $sth->{Statement} ) );
2130 }
2131 elsif( !defined( $rv ) )
2132 {
2133 0 $sth->finish;
2134 0 return( $self->error( "Error executing the query to get the timezone information for $name: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2135 }
2136  
2137 63 my $row = eval{ $sth->fetchrow_hashref };
2138 63 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 63 63
elsif (not defined $row and $sth->errstr) { } 0 125 125
2139 {
2140 0 $sth->finish;
2141 0 return( $self->error( "Error retrieving the timezone information for $name: $@", "\nSQL query was ", $sth->{Statement} ) );
2142 }
2143 # We check for definedness, which means an error in DBI
2144 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition66%2/3
not defined $row and $sth->errstr
!ll&&!rl&&r
6210
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table66%2/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
2145 {
2146 0 $sth->finish;
2147 0 return( $self->error( "Error retrieving the timezone information for $name: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2148 }
2149 63 $sth->finish;
2150 63 ▶ $self->_decode_sql_arrays( [qw( countries )], $row ) if( defined( $row ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $row 62 1 63
2151 63 return( $row );
2152 }
2153  
2154 sub _local_tz_android
2155 0 ▶{
Subroutine _local_tz_android: not called CC=6 SCAR=37.4
2156 0 my $class = shift( @_ );
2157  
2158 # Method 1: $ENV{TZ}
2159 0 my $name = $class->_local_tz_env( 'TZ' );
2160 0 ▶ return( $name ) if( defined( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
2161  
2162 # Method 2: getprop persist.sys.timezone (Android system property)
2163 {
2164 0 local $@;
2165 my $n = eval
2166 0 {
2167 0 my $r = `getprop persist.sys.timezone 2>/dev/null`;
2168 0 chomp( $r );
2169 0 return( $r );
2170 };
2171 0 ▶ if( !$@ &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $@ and defined $n and length $n and $class->is_valid_name($n)) 0 0 0
Condition0%0/9
not $@ and defined $n and length $n and $class->is_valid_name($n)
!ll&&!rl&&r
000
not $@ and defined $n and length $n
!ll&&!rl&&r
000
not $@ and defined $n
!ll&&!rl&&r
000
MC/DC0%0/4
not $@ and defined $n and length $n and $class->is_valid_name($n)
not $@ defined $n length $n $class->is_valid_name($n)
Truth table0%0/5
not(A) and B and C and D
A= not $@B= defined $nC= length $nD= $class->is_valid_name($n)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2172 defined( $n ) &&
2173 length( $n ) &&
2174 $class->is_valid_name( $n ) )
2175 {
2176 0 return( $n );
2177 }
2178 }
2179  
2180 # Android always defaults to UTC if nothing else is found
2181 0 return( 'UTC' );
2182 }
2183  
2184 sub _local_tz_env
2185 2 ▶{
Subroutine _local_tz_env: called CC=6 SCAR=22.8
2186 2 my $class = shift( @_ );
2187 2 my @vars = @_;
2188 2 foreach my $var ( @vars )
2189 {
2190 2 ▶ if( defined( $ENV{ $var } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{$var} and length $ENV{$var} and $ENV{$var} ne "local" and $ENV{$var} =~ m[^[\w/+\-]+$]) 2 0 2
Condition33%3/9
defined $ENV{$var} and length $ENV{$var} and $ENV{$var} ne "local" and $ENV{$var} =~ m[^[\w/+\-]+$]
!ll&&!rl&&r
002
defined $ENV{$var} and length $ENV{$var} and $ENV{$var} ne "local"
!ll&&!rl&&r
002
defined $ENV{$var} and length $ENV{$var}
!ll&&!rl&&r
002
MC/DC0%0/4
defined $ENV{$var} and length $ENV{$var} and $ENV{$var} ne "local" and $ENV{$var} =~ m[^[\w/+\-]+$]
defined $ENV{$var} length $ENV{$var} $ENV{$var} ne "local" $ENV{$var} =~ m[^[\w/+\-]+$]
Truth table20%1/5
A and B and C and D
A= defined $ENV{$var}B= length $ENV{$var}C= $ENV{$var} ne "local"D= $ENV{$var} =~ m[^[\w/+\-]+$]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2191 length( $ENV{ $var } ) &&
2192 $ENV{ $var } ne 'local' &&
2193 $ENV{ $var } =~ m{^[\w/+\-]+$} )
2194 {
2195 2 return( $ENV{ $var } );
2196 }
2197 }
2198 0 return;
2199 }
2200  
2201 sub _local_tz_env_only
2202 0 ▶{
Subroutine _local_tz_env_only: not called CC=1 SCAR=6.9
2203 0 my $class = shift( @_ );
2204 # Platforms with no filesystem or registry to query: check $ENV{TZ} only
2205 0 return( $class->_local_tz_env( 'TZ' ) );
2206 }
2207  
2208 20 my $win_map;
2209 sub _local_tz_mswin32
2210 0 ▶{
Subroutine _local_tz_mswin32: not called CC=7 SCAR=40.3
2211 0 my $class = shift( @_ );
2212  
2213 # Method 1: $ENV{TZ}
2214 0 my $name = $class->_local_tz_env( 'TZ' );
2215 0 ▶ return( $name ) if( defined( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
2216  
2217 # Method 2: Windows Registry via Win32::TieRegistry (non-core, optional)
2218 # The Windows->IANA mapping is built lazily via state so it consumes no
2219 # memory on non-Windows platforms.
2220 {
2221 0 local $@;
2222 0 eval{ require Win32::TieRegistry };
2223 0 ▶ if( !$@ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
2224 {
2225 0 my $win_name = $class->_win32_tz_from_registry;
2226 0 ▶ if( defined( $win_name ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $win_name) 0 0 0
2227 {
2228 0 ▶ $win_map = $class->_build_win_to_iana unless( defined( $win_map ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $win_map 0 0 0
2229 0 my $iana = $win_map->{ $win_name };
2230 0 ▶ if( defined( $iana ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $iana and $class->is_valid_name($iana)) 0 0 0
Condition0%0/3
defined $iana and $class->is_valid_name($iana)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $iana and $class->is_valid_name($iana)
defined $iana $class->is_valid_name($iana)
Truth table0%0/3
A and B
A= defined $ianaB= $class->is_valid_name($iana)
ABresult
0X0
100
111
2231 $class->is_valid_name( $iana ) )
2232 {
2233 0 return( $iana );
2234 }
2235 }
2236 }
2237 }
2238  
2239 0 return;
2240 }
2241  
2242 sub _local_tz_unix
2243 2 ▶{
Subroutine _local_tz_unix: called CC=34 SCAR=69.9
2244 2 my $class = shift( @_ );
2245  
2246 # Method 1: $ENV{TZ}
2247 2 my $name = $class->_local_tz_env( 'TZ' );
2248 2 ▶ return( $name ) if( defined( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 2 0 2
2249  
2250 # Method 2: /etc/localtime symlink or binary match against /usr/share/zoneinfo
2251 {
2252 0 require File::Spec; # Core module
2253 0 my $lt = File::Spec->catfile( '/etc', 'localtime' );
2254 0 ▶ if( -r( $lt ) && -s( $lt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-r $lt and -s $lt) 0 0 0
Condition0%0/3
-r $lt and -s $lt
!ll&&!rl&&r
000
MC/DC0%0/2
-r $lt and -s $lt
-r $lt -s $lt
Truth table0%0/3
A and B
A= -r $ltB= -s $lt
ABresult
0X0
100
111
2255 {
2256 0 my $real;
2257 0 ▶ if( -l( $lt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-l $lt) 0 0 0
2258 {
2259 # Will resolve the link
2260 0 $real = Cwd::abs_path( $lt );
2261 }
2262 0 ▶ $real ||= $class->_match_zoneinfo_file( $lt );
Condition0%0/3
$real ||= $class->_match_zoneinfo_file($lt)
l!l&&r!l&&!r
000
MC/DC0%0/2
$real ||= $class->_match_zoneinfo_file($lt)
$real $class->_match_zoneinfo_file($lt)
Truth table0%0/3
A ||= B
A= $realB= $class->_match_zoneinfo_file($lt)
ABresult
1X1
011
000
2263 0 ▶ if( defined( $real ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $real) 0 0 0
2264 {
2265 0 my( undef, $dirs, $file ) = File::Spec->splitpath( $real );
2266 0 ▶ my @parts = grep{ defined && length } File::Spec->splitdir( $dirs ), $file;
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2267 0 foreach my $x ( reverse( 0 .. $#parts ) )
2268 {
2269 0 ▶ my $tzname = $x < $#parts
Branch: 1 branch
BranchTrueFalseTotal
$x < $#parts ? : 0 0 0
2270 ? join( '/', @parts[ $x .. $#parts ] )
2271 : $parts[$x];
2272 0 ▶ return( $tzname ) if( $class->is_valid_name( $tzname ) );
Branch: 1 branch
BranchTrueFalseTotal
if $class->is_valid_name($tzname) 0 0 0
2273 }
2274 }
2275 }
2276 }
2277  
2278 # Method 3: /etc/timezone plain text file (Debian/Ubuntu)
2279 {
2280 0 my $f = '/etc/timezone';
2281 0 ▶ if( -f( $f ) && -r( $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-f $f and -r $f) 0 0 0
Condition0%0/3
-f $f and -r $f
!ll&&!rl&&r
000
MC/DC0%0/2
-f $f and -r $f
-f $f -r $f
Truth table0%0/3
A and B
A= -f $fB= -r $f
ABresult
0X0
100
111
2282 {
2283 0 ▶ if( open( my $fh, '<', $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $f) 0 0 0
2284 {
2285 0 my $n = <$fh>;
2286 0 chomp( $n );
2287 0 close( $fh );
2288 0 $n =~ s/^\s+|\s+$//g;
2289 0 ▶ return( $n ) if( $n && $class->is_valid_name( $n ) );
Branch: 1 branch
BranchTrueFalseTotal
if $n and $class->is_valid_name($n) 0 0 0
Condition0%0/3
$n and $class->is_valid_name($n)
!ll&&!rl&&r
000
MC/DC0%0/2
$n and $class->is_valid_name($n)
$n $class->is_valid_name($n)
Truth table0%0/3
A and B
A= $nB= $class->is_valid_name($n)
ABresult
0X0
100
111
2290 }
2291 }
2292 }
2293  
2294 # Method 4: /etc/TIMEZONE with TZ= line (Solaris, HP-UX)
2295 {
2296 0 my $f = '/etc/TIMEZONE';
2297 0 ▶ if( -f( $f ) && -r( $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-f $f and -r $f) 0 0 0
Condition0%0/3
-f $f and -r $f
!ll&&!rl&&r
000
MC/DC0%0/2
-f $f and -r $f
-f $f -r $f
Truth table0%0/3
A and B
A= -f $fB= -r $f
ABresult
0X0
100
111
2298 {
2299 0 ▶ if( open( my $fh, '<', $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $f) 0 0 0
2300 {
2301 0 ▶ while( <$fh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
2302 {
2303 0 ▶ if( /^\s*TZ\s*=\s*(\S+)/ &&
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*TZ\s*=\s*(\S+)/ and $class->is_valid_name($1)) 0 0 0
Condition0%0/3
/^\s*TZ\s*=\s*(\S+)/ and $class->is_valid_name($1)
!ll&&!rl&&r
000
MC/DC0%0/2
/^\s*TZ\s*=\s*(\S+)/ and $class->is_valid_name($1)
/^\s*TZ\s*=\s*(\S+)/ $class->is_valid_name($1)
Truth table0%0/3
A and B
A= /^\s*TZ\s*=\s*(\S+)/B= $class->is_valid_name($1)
ABresult
0X0
100
111
2304 $class->is_valid_name( $1 ) )
2305 {
2306 0 return( $1 );
2307 }
2308 }
2309 0 close( $fh );
2310 }
2311 }
2312 }
2313  
2314 # Method 5: /etc/sysconfig/clock with ZONE= or TIMEZONE= line (RedHat/CentOS)
2315 {
2316 0 my $f = '/etc/sysconfig/clock';
2317 0 ▶ if( -f( $f ) && -r( $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-f $f and -r $f) 0 0 0
Condition0%0/3
-f $f and -r $f
!ll&&!rl&&r
000
MC/DC0%0/2
-f $f and -r $f
-f $f -r $f
Truth table0%0/3
A and B
A= -f $fB= -r $f
ABresult
0X0
100
111
2318 {
2319 0 ▶ if( open( my $fh, '<', $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $f) 0 0 0
2320 {
2321 0 ▶ while( <$fh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
2322 {
2323 0 ▶ if( /^(?:TIME)?ZONE="([^"]+)"/ &&
Branch: 1 branch
BranchTrueFalseTotal
if (/^(?:TIME)?ZONE="([^"]+)"/ and $class->is_valid_name($1)) 0 0 0
Condition0%0/3
/^(?:TIME)?ZONE="([^"]+)"/ and $class->is_valid_name($1)
!ll&&!rl&&r
000
MC/DC0%0/2
/^(?:TIME)?ZONE="([^"]+)"/ and $class->is_valid_name($1)
/^(?:TIME)?ZONE="([^"]+)"/ $class->is_valid_name($1)
Truth table0%0/3
A and B
A= /^(?:TIME)?ZONE="([^"]+)"/B= $class->is_valid_name($1)
ABresult
0X0
100
111
2324 $class->is_valid_name( $1 ) )
2325 {
2326 0 return( $1 );
2327 }
2328 }
2329 0 close( $fh );
2330 }
2331 }
2332 }
2333  
2334 # Method 6: /etc/default/init with TZ= line (older Unix)
2335 {
2336 0 my $f = '/etc/default/init';
2337 0 ▶ if( -f( $f ) && -r( $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (-f $f and -r $f) 0 0 0
Condition0%0/3
-f $f and -r $f
!ll&&!rl&&r
000
MC/DC0%0/2
-f $f and -r $f
-f $f -r $f
Truth table0%0/3
A and B
A= -f $fB= -r $f
ABresult
0X0
100
111
2338 {
2339 0 ▶ if( open( my $fh, '<', $f ) )
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $f) 0 0 0
2340 {
2341 0 ▶ while( <$fh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
2342 {
2343 0 ▶ if( /^TZ=(\S+)/ &&
Branch: 1 branch
BranchTrueFalseTotal
if (/^TZ=(\S+)/ and $class->is_valid_name($1)) 0 0 0
Condition0%0/3
/^TZ=(\S+)/ and $class->is_valid_name($1)
!ll&&!rl&&r
000
MC/DC0%0/2
/^TZ=(\S+)/ and $class->is_valid_name($1)
/^TZ=(\S+)/ $class->is_valid_name($1)
Truth table0%0/3
A and B
A= /^TZ=(\S+)/B= $class->is_valid_name($1)
ABresult
0X0
100
111
2344 $class->is_valid_name( $1 ) )
2345 {
2346 0 return( $1 );
2347 }
2348 }
2349 0 close( $fh );
2350 }
2351 }
2352 }
2353  
2354 0 return;
2355 }
2356  
2357 sub _local_tz_vms
2358 0 ▶{
Subroutine _local_tz_vms: not called CC=1 SCAR=6.9
2359 0 my $class = shift( @_ );
2360 # VMS uses several environment variables for timezone
2361 0 return( $class->_local_tz_env(
2362 qw( TZ SYS$TIMEZONE_RULE SYS$TIMEZONE_NAME UCX$TZ TCPIP$TZ )
2363 ) );
2364 }
2365  
2366 # NOTE: OS aliases
2367 {
2368 20 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
2369 # Unix-like: use the full Unix detection chain
2370 # NOTE: _local_tz_aix -> _local_tz_unix
2371 20 *_local_tz_aix = \&_local_tz_unix;
2372 # NOTE: _local_tz_cygwin -> _local_tz_unix
2373 20 *_local_tz_cygwin = \&_local_tz_unix; # Cygwin on Windows
2374 # NOTE: _local_tz_darwin -> _local_tz_unix
2375 20 *_local_tz_darwin = \&_local_tz_unix; # macOS ($^O eq 'darwin')
2376 # NOTE: _local_tz_freebsd -> _local_tz_unix
2377 20 *_local_tz_freebsd = \&_local_tz_unix;
2378 # NOTE: _local_tz_hpux -> _local_tz_unix
2379 20 *_local_tz_hpux = \&_local_tz_unix; # HPUX IANA names; HP-UX-proprietary names require $ENV{TZ}
2380 # NOTE: _local_tz_netbsd -> _local_tz_unix
2381 20 *_local_tz_netbsd = \&_local_tz_unix;
2382 # NOTE: _local_tz_openbsd -> _local_tz_unix
2383 20 *_local_tz_openbsd = \&_local_tz_unix;
2384 # NOTE: _local_tz_os2 -> _local_tz_unix
2385 20 *_local_tz_os2 = \&_local_tz_unix; # OS/2 has a /etc filesystem
2386 # NOTE: _local_tz_solaris -> _local_tz_unix
2387 20 *_local_tz_solaris = \&_local_tz_unix;
2388 # Win32 variants
2389 # NOTE: _local_tz_netware -> _local_tz_mswin32
2390 20 *_local_tz_netware = \&_local_tz_mswin32;
2391 # Env-only platforms: no filesystem or registry to query
2392 # NOTE: _local_tz_symbian -> _local_tz_env_only (Symbian OS is not Win32)
2393 20 *_local_tz_symbian = \&_local_tz_env_only;
2394 # NOTE: _local_tz_epoc -> _local_tz_env_only
2395 20 *_local_tz_epoc = \&_local_tz_env_only; # EPOC (Symbian predecessor)
2396 # NOTE: _local_tz_dos -> _local_tz_env_only
2397 20 *_local_tz_dos = \&_local_tz_env_only; # MS-DOS
2398 # NOTE: _local_tz_macos -> _local_tz_env_only
2399 20 *_local_tz_macos = \&_local_tz_env_only; # Mac OS 9 and earlier (not macOS/darwin)
2400 }
2401  
2402 # Look up a span by UTC time (the common case).
2403 # $utc_rd_secs is in Rata Die seconds (as returned by $dt->utc_rd_as_seconds).
2404 # The database stores Unix seconds, so UNIX_TO_RD is subtracted before querying.
2405 # NULL utc_start means "before all recorded transitions" (effectively -Inf).
2406 # NULL utc_end means "after all recorded transitions" (effectively +Inf).
2407 sub _lookup_span
2408 127 ▶{
Subroutine _lookup_span: called CC=33 SCAR=48.5
2409 127 my( $self, $utc_rd_secs ) = @_;
2410 127 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 127 127
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
00127
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
2411 {
2412 # We die, because this is not a user bad call, but an internal design error that should not happen.
2413 0 die( "_lookup_span() must be called on a class instance." );
2414 }
2415 my $zone_id = $self->{_zone_id} ||
2416 127 ▶ return( $self->error( "No zone_id cached for '$self->{name}'." ) );
Condition50%1/2
$self->{'_zone_id'} || (return $self->error("No zone_id cached for '$self->{'name'}'."))
l!l
1270
MC/DC0%0/1
$self->{'_zone_id'} || (return $self->error("No zone_id cached for '$self->{'name'}'."))
$self->{'_zone_id'}
Truth table50%1/2
A
A= $self->{'_zone_id'}
Aresult
11
00
2417  
2418 # Per-object span cache (populated when use_cache_mem is active or
2419 # when _span_cache is explicitly used). Stores the last matched span's
2420 # boundaries so that repeated calls with timestamps in the same span
2421 # skip the SQLite query entirely. The slot is undef when caching is
2422 # disabled; an empty hashref {} means caching is enabled but no span
2423 # has been fetched yet.
2424 127 ▶ if( defined( $self->{_span_cache} ) && exists( $self->{_span_cache}->{offset} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache"} and exists $self->{"_span_cache"}{"offset"}) 0 127 127
Condition66%2/3
defined $self->{"_span_cache"} and exists $self->{"_span_cache"}{"offset"}
!ll&&!rl&&r
12430
MC/DC0%0/2
defined $self->{"_span_cache"} and exists $self->{"_span_cache"}{"offset"}
defined $self->{"_span_cache"} exists $self->{"_span_cache"}{"offset"}
Truth table66%2/3
A and B
A= defined $self->{"_span_cache"}B= exists $self->{"_span_cache"}{"offset"}
ABresult
0X0
100
111
2425 {
2426 0 my $c = $self->{_span_cache};
2427 0 my $unix = $utc_rd_secs - UNIX_TO_RD;
2428 0 my $s = $c->{utc_start};
2429 0 my $e = $c->{utc_end};
2430 # Range check: [utc_start, utc_end) — both bounds may be undef (open span)
2431 0 ▶ if( ( !defined( $s ) || $unix >= $s ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($s) || $unix >= $s and !defined($e) || $unix < $e) 0 0 0
Condition0%0/9
!defined($s) || $unix >= $s and !defined($e) || $unix < $e
!ll&&!rl&&r
000
not defined $s or $unix >= $s
l!l&&r!l&&!r
000
not defined $e or $unix < $e
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($s) || $unix >= $s and !defined($e) || $unix < $e
not defined $s $unix >= $s not defined $e $unix < $e
Truth table0%0/7
not(A) or B and not(C) or D
A= not defined $sB= $unix >= $sC= not defined $eD= $unix < $e
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
2432 ( !defined( $e ) || $unix < $e ) )
2433 {
2434 0 return( $c );
2435 }
2436 # Timestamp outside cached span — fall through to DB
2437 }
2438  
2439 # Footer result cache: keyed by day (unix_secs / 86400).
2440 # Checked before the SQL query to skip the DB entirely for zones
2441 # whose current dates are governed by a POSIX footer rule.
2442 127 ▶ if( defined( $self->{_footer_cache_key} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_footer_cache_key"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}) 2 125 127
Condition66%4/6
defined $self->{"_footer_cache_key"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
!ll&&!rl&&r
12502
defined $self->{"_footer_cache_key"} and defined $self->{"footer_tz_string"}
!ll&&!rl&&r
12502
MC/DC33%1/3
defined $self->{"_footer_cache_key"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
defined $self->{"_footer_cache_key"} defined $self->{"footer_tz_string"} length $self->{"footer_tz_string"}
Truth table50%2/4
A and B and C
A= defined $self->{"_footer_cache_key"}B= defined $self->{"footer_tz_string"}C= length $self->{"footer_tz_string"}
ABCresult
0XX0
10X0
1100
1111
2443 defined( $self->{footer_tz_string} ) &&
2444 length( $self->{footer_tz_string} ) )
2445 {
2446 2 my $unix_pre = $utc_rd_secs - UNIX_TO_RD;
2447 2 my $day_pre = int( $unix_pre / 86400 );
2448 2 ▶ if( $self->{_footer_cache_key} == $day_pre )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_footer_cache_key"} == $day_pre) 2 0 2
2449 {
2450 2 return( $self->{_footer_cache_val} );
2451 }
2452 }
2453  
2454 125 local $@;
2455 125 my $sth;
2456 125 ▶ unless( $sth = $self->_get_cached_statement( 'span_by_utc' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->_get_cached_statement("span_by_utc")) 11 114 125
2457 {
2458 11 my $query = <<'SQL';
2459 SELECT s.offset, s.is_dst, s.short_name, s.utc_start, s.utc_end
2460 FROM spans s
2461 WHERE s.zone_id = ?
2462 AND ( s.utc_start IS NULL OR s.utc_start <= ? )
2463 AND ( s.utc_end IS NULL OR s.utc_end > ? )
2464 ORDER BY (s.utc_start IS NULL) ASC, s.utc_start DESC
2465 LIMIT 1
2466 SQL
2467 11 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
110
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
2468 $sth = eval
2469 11 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare span_by_utc: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
110
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare span_by_utc: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
2470 11 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
2471 } || return( $self->error( "Cannot prepare span_by_utc: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
2472 11 $self->_set_cached_statement( span_by_utc => $sth );
2473 }
2474  
2475 125 my $unix_secs = $utc_rd_secs - UNIX_TO_RD;
2476 125 my $rv = eval{ $sth->execute( $zone_id, $unix_secs, $unix_secs ) };
2477 125 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 125 125
elsif (not defined $rv) { } 0 125 125
2478 {
2479 0 $sth->finish;
2480 0 return( $self->error( "Error executing the query to get the timezone spans information for $self->{name} and zone ID $zone_id: $@", "\nSQL query was ", $sth->{Statement} ) );
2481 }
2482 elsif( !defined( $rv ) )
2483 {
2484 0 $sth->finish;
2485 0 return( $self->error( "Error executing the query to get the timezone spans information for $self->{name} and zone ID $zone_id: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2486 }
2487  
2488 125 my $row = eval{ $sth->fetchrow_hashref };
2489 125 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 125 125
elsif (not defined $row and $sth->errstr) { } 0 250 250
2490 {
2491 0 $sth->finish;
2492 0 return( $self->error( "Error retrieving the timezone spans information for $self->{name} and zone ID $zone_id: $@", "\nSQL query was ", $sth->{Statement} ) );
2493 }
2494 # We check for definedness, which means an error in DBI
2495 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition33%1/3
not defined $row and $sth->errstr
!ll&&!rl&&r
12500
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
2496 {
2497 0 $sth->finish;
2498 0 return( $self->error( "Error retrieving the timezone spans information for $self->{name} and zone ID $zone_id: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2499 }
2500 125 $sth->finish;
2501  
2502 # If the matching span has an open end (utc_end IS NULL) and this zone has
2503 # a POSIX footer TZ string, the DB transitions may be incomplete for future
2504 # dates. The footer encodes the recurring DST rule for all dates beyond the
2505 # last stored transition, per RFC 9636 section 3.3.
2506 # IMPORTANT: we must only apply the footer when the timestamp is actually
2507 # beyond the last recorded transition (utc_start of the open-ended span).
2508 # If the SQL query returned a bounded span (utc_end IS NOT NULL), the timestamp
2509 # is within the stored transitions and the footer must NOT be applied, because
2510 # doing so would overwrite a historically correct DST span with the post-abolition
2511 # rule, as observed with Asia/Tehran (DST abolished September 2022).
2512 125 ▶ if( defined( $row ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $row and not defined $row->{"utc_end"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}) 111 14 125
Condition66%6/9
defined $row and not defined $row->{"utc_end"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
!ll&&!rl&&r
140111
defined $row and not defined $row->{"utc_end"} and defined $self->{"footer_tz_string"}
!ll&&!rl&&r
140111
defined $row and not defined $row->{"utc_end"}
!ll&&!rl&&r
014111
MC/DC25%1/4
defined $row and not defined $row->{"utc_end"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
defined $row not defined $row->{"utc_end"} defined $self->{"footer_tz_string"} length $self->{"footer_tz_string"}
Truth table40%2/5
A and not(B) and C and D
A= defined $rowB= not defined $row->{"utc_end"}C= defined $self->{"footer_tz_string"}D= length $self->{"footer_tz_string"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2513 !defined( $row->{utc_end} ) &&
2514 defined( $self->{footer_tz_string} ) &&
2515 length( $self->{footer_tz_string} ) )
2516 {
2517 # Fetch the utc_start of this span to check whether the timestamp is actually
2518 # beyond the last recorded transition.
2519 111 my $footer_row = $self->_posix_tz_lookup( $unix_secs, $self->{footer_tz_string} );
2520 111 ▶ if( defined( $footer_row ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $footer_row) 111 0 111
2521 {
2522 # Cache the footer result keyed by day (unix_secs rounded down
2523 # to midnight). DST transitions are rare (twice a year); on all
2524 # other days the same footer result applies for the whole day.
2525 111 ▶ if( defined( $self->{_span_cache} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache"}) 1 110 111
2526 {
2527 1 my $day_key = int( $unix_secs / 86400 );
2528 1 ▶ if( defined( $self->{_footer_cache_key} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_footer_cache_key"} and $self->{"_footer_cache_key"} == $day_key) 0 1 1
Condition33%1/3
defined $self->{"_footer_cache_key"} and $self->{"_footer_cache_key"} == $day_key
!ll&&!rl&&r
100
MC/DC0%0/2
defined $self->{"_footer_cache_key"} and $self->{"_footer_cache_key"} == $day_key
defined $self->{"_footer_cache_key"} $self->{"_footer_cache_key"} == $day_key
Truth table33%1/3
A and B
A= defined $self->{"_footer_cache_key"}B= $self->{"_footer_cache_key"} == $day_key
ABresult
0X0
100
111
2529 $self->{_footer_cache_key} == $day_key )
2530 {
2531 0 return( $self->{_footer_cache_val} );
2532 }
2533 1 $self->{_footer_cache_key} = $day_key;
2534 1 $self->{_footer_cache_val} = $footer_row;
2535 }
2536 111 return( $footer_row );
2537 }
2538 }
2539  
2540 # Store matched span in the per-object cache for future range checks.
2541 # We cache only when the object already has a _span_cache slot (i.e. the cache
2542 # was enabled by use_cache_mem or enable_mem_cache) to avoid allocating memory
2543 # for callers that never requested caching.
2544 14 ▶ if( defined( $self->{_span_cache} ) && defined( $row ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache"} and defined $row) 0 14 14
Condition33%1/3
defined $self->{"_span_cache"} and defined $row
!ll&&!rl&&r
1400
MC/DC0%0/2
defined $self->{"_span_cache"} and defined $row
defined $self->{"_span_cache"} defined $row
Truth table33%1/3
A and B
A= defined $self->{"_span_cache"}B= defined $row
ABresult
0X0
100
111
2545 {
2546 0 $self->{_span_cache} = $row;
2547 }
2548  
2549 14 return( $row );
2550 }
2551  
2552 # Look up a span by local (wall-clock) time.
2553 # Used by offset_for_local_datetime.
2554 # $local_rd_secs is in Rata Die seconds (as returned by $dt->local_rd_as_seconds).
2555 sub _lookup_span_local
2556 73 ▶{
Subroutine _lookup_span_local: called CC=49 SCAR=53.6
2557 73 my( $self, $local_rd_secs ) = @_;
2558 my $zone_id = $self->{_zone_id} ||
2559 73 ▶ return( $self->error( "No zone_id cached for '$self->{name}'." ) );
Condition50%1/2
$self->{'_zone_id'} || (return $self->error("No zone_id cached for '$self->{'name'}'."))
l!l
730
MC/DC0%0/1
$self->{'_zone_id'} || (return $self->error("No zone_id cached for '$self->{'name'}'."))
$self->{'_zone_id'}
Truth table50%1/2
A
A= $self->{'_zone_id'}
Aresult
11
00
2560  
2561 # Per-object span cache for local lookups (same logic as _lookup_span).
2562 73 ▶ if( defined( $self->{_span_cache_local} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache_local"} and exists $self->{"_span_cache_local"}{"offset"}) 0 73 73
Condition33%1/3
defined $self->{"_span_cache_local"} and exists $self->{"_span_cache_local"}{"offset"}
!ll&&!rl&&r
7300
MC/DC0%0/2
defined $self->{"_span_cache_local"} and exists $self->{"_span_cache_local"}{"offset"}
defined $self->{"_span_cache_local"} exists $self->{"_span_cache_local"}{"offset"}
Truth table33%1/3
A and B
A= defined $self->{"_span_cache_local"}B= exists $self->{"_span_cache_local"}{"offset"}
ABresult
0X0
100
111
2563 exists( $self->{_span_cache_local}->{offset} ) )
2564 {
2565 0 my $c = $self->{_span_cache_local};
2566 0 my $unix = $local_rd_secs - UNIX_TO_RD;
2567 0 my $s = $c->{local_start};
2568 0 my $e = $c->{local_end};
2569 0 ▶ if( ( !defined( $s ) || $unix >= $s ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($s) || $unix >= $s and !defined($e) || $unix < $e) 0 0 0
Condition0%0/9
!defined($s) || $unix >= $s and !defined($e) || $unix < $e
!ll&&!rl&&r
000
not defined $s or $unix >= $s
l!l&&r!l&&!r
000
not defined $e or $unix < $e
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($s) || $unix >= $s and !defined($e) || $unix < $e
not defined $s $unix >= $s not defined $e $unix < $e
Truth table0%0/7
not(A) or B and not(C) or D
A= not defined $sB= $unix >= $sC= not defined $eD= $unix < $e
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
2570 ( !defined( $e ) || $unix < $e ) )
2571 {
2572 0 return( $c );
2573 }
2574 }
2575  
2576 # Footer result cache for local lookups.
2577 73 ▶ if( defined( $self->{_footer_local_cache_key} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_footer_local_cache_key"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}) 0 73 73
Condition33%2/6
defined $self->{"_footer_local_cache_key"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
!ll&&!rl&&r
7300
defined $self->{"_footer_local_cache_key"} and defined $self->{"footer_tz_string"}
!ll&&!rl&&r
7300
MC/DC0%0/3
defined $self->{"_footer_local_cache_key"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
defined $self->{"_footer_local_cache_key"} defined $self->{"footer_tz_string"} length $self->{"footer_tz_string"}
Truth table25%1/4
A and B and C
A= defined $self->{"_footer_local_cache_key"}B= defined $self->{"footer_tz_string"}C= length $self->{"footer_tz_string"}
ABCresult
0XX0
10X0
1100
1111
2578 defined( $self->{footer_tz_string} ) &&
2579 length( $self->{footer_tz_string} ) )
2580 {
2581 0 my $day_pre = int( ( $local_rd_secs - UNIX_TO_RD ) / 86400 );
2582 0 ▶ if( $self->{_footer_local_cache_key} == $day_pre )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_footer_local_cache_key"} == $day_pre) 0 0 0
2583 {
2584 0 return( $self->{_footer_local_cache_val} );
2585 }
2586 }
2587  
2588 73 local $@;
2589 73 my $sth;
2590 73 ▶ unless( $sth = $self->_get_cached_statement( 'span_by_local' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->_get_cached_statement("span_by_local")) 8 65 73
2591 {
2592 8 my $query = <<'SQL';
2593 SELECT s.offset, s.is_dst, s.short_name, s.local_start, s.local_end
2594 FROM spans s
2595 WHERE s.zone_id = ?
2596 AND ( s.local_start IS NULL OR s.local_start <= ? )
2597 AND ( s.local_end IS NULL OR s.local_end > ? )
2598 ORDER BY (s.local_start IS NULL) ASC, s.local_start DESC
2599 LIMIT 1
2600 SQL
2601 8 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
80
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
2602 8 local $@;
2603 $sth = eval
2604 8 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare span_by_local: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
80
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare span_by_local: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
2605 8 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
2606 } || return( $self->error( "Cannot prepare span_by_local: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
2607 8 $self->_set_cached_statement( span_by_local => $sth );
2608 }
2609  
2610 73 my $unix_local = $local_rd_secs - UNIX_TO_RD;
2611 73 my $rv = eval{ $sth->execute( $zone_id, $unix_local, $unix_local ) };
2612 73 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 73 73
elsif (not defined $rv) { } 0 73 73
2613 {
2614 0 $sth->finish;
2615 0 return( $self->error( "Error executing the query to get all the spans for the zone ID $zone_id: $@", "\nSQL query was ", $sth->{Statement} ) );
2616 }
2617 elsif( !defined( $rv ) )
2618 {
2619 0 $sth->finish;
2620 0 return( $self->error( "Error executing the query to get all the spans for the zone ID $zone_id: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2621 }
2622  
2623 73 my $row = eval{ $sth->fetchrow_hashref };
2624 73 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 73 73
elsif (not defined $row and $sth->errstr) { } 0 146 146
2625 {
2626 0 $sth->finish;
2627 0 return( $self->error( "Error retrieving all the spans for the zone ID $zone_id: $@", "\nSQL query was ", $sth->{Statement} ) );
2628 }
2629 # We check for definedness, which means an error in DBI
2630 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition33%1/3
not defined $row and $sth->errstr
!ll&&!rl&&r
7300
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
2631 {
2632 0 $sth->finish;
2633 0 return( $self->error( "Error retrieving all the spans for the zone ID $zone_id: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2634 }
2635 73 $sth->finish;
2636  
2637 # If the matching span has an open end (local_end IS NULL) and this zone has
2638 # a POSIX footer TZ string, the DB transitions may be incomplete for future
2639 # dates. Convert the local timestamp to approximate UTC using both the standard
2640 # and DST offsets from the footer, then pick the self-consistent result. Decision
2641 # tree (std_ok = r_std is std, dst_ok = r_dst is DST):
2642 # std only -> standard time
2643 # dst only -> DST
2644 # both (overlap) -> prefer standard (fall-back convention)
2645 # neither (gap) -> r_std carries the post-gap DST info
2646 # IMPORTANT: only apply the footer when the span is open-ended (local_end IS NULL).
2647 # A bounded span means the timestamp is within stored transitions and the footer
2648 # must not overwrite the historically correct offset.
2649 73 ▶ if( defined( $row ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $row and not defined $row->{"local_end"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}) 59 14 73
Condition66%6/9
defined $row and not defined $row->{"local_end"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
!ll&&!rl&&r
14059
defined $row and not defined $row->{"local_end"} and defined $self->{"footer_tz_string"}
!ll&&!rl&&r
14059
defined $row and not defined $row->{"local_end"}
!ll&&!rl&&r
01459
MC/DC25%1/4
defined $row and not defined $row->{"local_end"} and defined $self->{"footer_tz_string"} and length $self->{"footer_tz_string"}
defined $row not defined $row->{"local_end"} defined $self->{"footer_tz_string"} length $self->{"footer_tz_string"}
Truth table40%2/5
A and not(B) and C and D
A= defined $rowB= not defined $row->{"local_end"}C= defined $self->{"footer_tz_string"}D= length $self->{"footer_tz_string"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2650 !defined( $row->{local_end} ) &&
2651 defined( $self->{footer_tz_string} ) &&
2652 length( $self->{footer_tz_string} ) )
2653 {
2654 59 my $footer = $self->{footer_tz_string};
2655  
2656 # Quick-parse std and dst offsets from the footer string.
2657 # POSIX convention: positive offset = WEST; we negate to get UTC east.
2658 # We only need the two offsets to build the two UTC guesses for disambiguation;
2659 # full parsing is done inside _posix_tz_lookup().
2660 59 my( $std_offset, $dst_offset );
2661 {
2662 59 my $s = $footer;
2663 59 $s =~ s/\A(?:<[^>]+>|[A-Za-z]{3,})//; # strip std name
2664 59 ▶ if( $s =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/) 59 0 59
2665 {
2666 # Negate POSIX sign convention to get seconds east of UTC
2667 59 my $raw = $1;
2668 59 ▶ my $sign = ( $raw =~ s/^-// ) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ s/^-// ? : 47 12 59
2669 59 $raw =~ s/^\+//;
2670 59 my( $h, $m, $sec ) = split( /:/, $raw );
2671 59 ▶ $std_offset = $sign * ( ( $h // 0 ) * 3600
Condition66%4/6
$h // 0
l!l
590
$m // 0
l!l
455
$sec // 0
l!l
059
MC/DC0%0/1
$h // 0
$h
MC/DC100%1/1
$m // 0
$m
MC/DC0%0/1
$sec // 0
$sec
Truth table50%1/2
A
A= $h
Aresult
11
00
Truth table100%2/2
A
A= $m
Aresult
11
00
Truth table50%1/2
A
A= $sec
Aresult
11
00
2672 + ( $m // 0 ) * 60
2673 + ( $sec // 0 ) );
2674 59 $s = $';
2675 59 $s =~ s/\A(?:<[^>]+>|[A-Za-z]{3,})//; # strip dst name
2676 59 ▶ if( $s =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/) { } 47 12 59
2677 {
2678 47 my $raw2 = $1;
2679 47 ▶ my $sign2 = ( $raw2 =~ s/^-// ) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$raw2 =~ s/^-// ? : 0 47 47
2680 47 $raw2 =~ s/^\+//;
2681 47 my( $h2, $m2, $s2 ) = split( /:/, $raw2 );
2682 47 ▶ $dst_offset = $sign2 * ( ( $h2 // 0 ) * 3600
Condition66%4/6
$h2 // 0
l!l
470
$m2 // 0
l!l
443
$s2 // 0
l!l
047
MC/DC0%0/1
$h2 // 0
$h2
MC/DC100%1/1
$m2 // 0
$m2
MC/DC0%0/1
$s2 // 0
$s2
Truth table50%1/2
A
A= $h2
Aresult
11
00
Truth table100%2/2
A
A= $m2
Aresult
11
00
Truth table50%1/2
A
A= $s2
Aresult
11
00
2683 + ( $m2 // 0 ) * 60
2684 + ( $s2 // 0 ) );
2685 }
2686 else
2687 {
2688 12 $dst_offset = $std_offset + 3600;
2689 }
2690 }
2691 }
2692  
2693 59 ▶ if( defined( $std_offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $std_offset) 59 0 59
2694 {
2695 59 my $r_std = $self->_posix_tz_lookup( $unix_local - $std_offset, $footer );
2696 59 my $r_dst = $self->_posix_tz_lookup( $unix_local - $dst_offset, $footer );
2697  
2698 59 ▶ if( defined( $r_std ) && defined( $r_dst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r_std and defined $r_dst) 59 0 59
Condition33%1/3
defined $r_std and defined $r_dst
!ll&&!rl&&r
0059
MC/DC0%0/2
defined $r_std and defined $r_dst
defined $r_std defined $r_dst
Truth table33%1/3
A and B
A= defined $r_stdB= defined $r_dst
ABresult
0X0
100
111
2699 {
2700 59 ▶ my $std_ok = !$r_std->{is_dst} && $r_std->{offset} == $std_offset;
Condition66%2/3
!$r_std->{'is_dst'} && $r_std->{'offset'} == $std_offset
!ll&&!rl&&r
17042
MC/DC50%1/2
!$r_std->{'is_dst'} && $r_std->{'offset'} == $std_offset
!$r_std->{'is_dst'} $r_std->{'offset'} == $std_offset
Truth table66%2/3
not(A) && B
A= !$r_std->{'is_dst'}B= $r_std->{'offset'} == $std_offset
ABresult
0X0
100
111
2701 59 ▶ my $dst_ok = $r_dst->{is_dst} && $r_dst->{offset} == $dst_offset;
Condition100%3/3
$r_dst->{'is_dst'} && $r_dst->{'offset'} == $dst_offset
!ll&&!rl&&r
4298
MC/DC100%2/2
$r_dst->{'is_dst'} && $r_dst->{'offset'} == $dst_offset
$r_dst->{'is_dst'} $r_dst->{'offset'} == $dst_offset
Truth table100%3/3
A && B
A= $r_dst->{'is_dst'}B= $r_dst->{'offset'} == $dst_offset
ABresult
0X0
100
111
2702  
2703 # Unambiguous DST: only DST assumption is self-consistent
2704 # Unambiguous DST: only DST assumption is self-consistent
2705 59 ▶ if( !$std_ok && $dst_ok && defined( $r_dst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $std_ok and $dst_ok and defined $r_dst) 8 51 59
Condition83%5/6
not $std_ok and $dst_ok and defined $r_dst
!ll&&!rl&&r
5108
not $std_ok and $dst_ok
!ll&&!rl&&r
4298
MC/DC66%2/3
not $std_ok and $dst_ok and defined $r_dst
not $std_ok $dst_ok defined $r_dst
Truth table75%3/4
not(A) and B and C
A= not $std_okB= $dst_okC= defined $r_dst
ABCresult
0XX0
10X0
1100
1111
2706 {
2707 8 ▶ if( defined( $self->{_span_cache_local} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache_local"}) 0 8 8
2708 {
2709 $self->{_footer_local_cache_key} =
2710 0 int( ( $local_rd_secs - UNIX_TO_RD ) / 86400 );
2711 0 $self->{_footer_local_cache_val} = $r_dst;
2712 }
2713 8 return( $r_dst );
2714 }
2715 # All other cases (unambiguous std, overlap, gap): return r_std
2716 # For gap: r_std contains the post-gap DST state, which is correct
2717 51 ▶ my $footer_result = $r_std || $row;
Condition33%1/3
$r_std || $row
l!l&&r!l&&!r
5100
MC/DC0%0/2
$r_std || $row
$r_std $row
Truth table33%1/3
A || B
A= $r_stdB= $row
ABresult
1X1
011
000
2718 51 ▶ if( defined( $self->{_span_cache_local} ) && defined( $footer_result ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache_local"} and defined $footer_result) 0 51 51
Condition33%1/3
defined $self->{"_span_cache_local"} and defined $footer_result
!ll&&!rl&&r
5100
MC/DC0%0/2
defined $self->{"_span_cache_local"} and defined $footer_result
defined $self->{"_span_cache_local"} defined $footer_result
Truth table33%1/3
A and B
A= defined $self->{"_span_cache_local"}B= defined $footer_result
ABresult
0X0
100
111
2719 {
2720 $self->{_footer_local_cache_key} =
2721 0 int( ( $local_rd_secs - UNIX_TO_RD ) / 86400 );
2722 0 $self->{_footer_local_cache_val} = $footer_result;
2723 }
2724 51 return( $footer_result );
2725 }
2726 }
2727 }
2728  
2729 # Store in local span cache.
2730 14 ▶ if( defined( $self->{_span_cache_local} ) && defined( $row ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_span_cache_local"} and defined $row) 0 14 14
Condition33%1/3
defined $self->{"_span_cache_local"} and defined $row
!ll&&!rl&&r
1400
MC/DC0%0/2
defined $self->{"_span_cache_local"} and defined $row
defined $self->{"_span_cache_local"} defined $row
Truth table33%1/3
A and B
A= defined $self->{"_span_cache_local"}B= defined $row
ABresult
0X0
100
111
2731 {
2732 0 $self->{_span_cache_local} = $row;
2733 }
2734  
2735 14 return( $row );
2736 }
2737  
2738 sub _match_zoneinfo_file
2739 0 ▶{
Subroutine _match_zoneinfo_file: not called CC=8 SCAR=42.8
2740 0 my( $class, $file_to_match ) = @_;
2741 0 my $zoneinfo_dir = '/usr/share/zoneinfo';
2742 0 my $this_dir = Cwd::realpath( $zoneinfo_dir );
2743 0 ▶ if( !defined( $this_dir ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $this_dir) { } 0 0 0
elsif (not -e $this_dir) { } 0 0 0
elsif (not -x $this_dir && -r $this_dir) { } 0 0 0
2744 {
2745 0 return( $class->error( "Failed to resolve the zoneinfo directory location '$zoneinfo_dir'." ) );
2746 }
2747 elsif( !-e( $this_dir ) )
2748 {
2749 0 return( $class->error( "The resolved directory for '$zoneinfo_dir' points to $this_dir, which does not exist." ) );
2750 }
2751 ▶ elsif( !-x( $this_dir ) || !-r( $this_dir ) )
Condition0%0/3
-x $this_dir && -r $this_dir
!ll&&!rl&&r
000
MC/DC0%0/2
-x $this_dir && -r $this_dir
-x $this_dir -r $this_dir
Truth table0%0/3
A && B
A= -x $this_dirB= -r $this_dir
ABresult
0X0
100
111
2752 {
2753 0 return( $class->error( "The resolved directory '$this_dir' does not have the necessary read/execute permissions." ) );
2754 }
2755 0 $zoneinfo_dir = $this_dir;
2756  
2757 0 require File::Basename;
2758 0 require File::Compare;
2759 0 require File::Find;
2760  
2761 0 my $size = -s( $file_to_match );
2762 0 my $real_name;
2763 0 local $@;
2764 eval
2765 0 {
2766 0 local $SIG{__DIE__};
2767 File::Find::find(
2768 {
2769 wanted => sub
2770 0 ▶ {
Subroutine __ANON__: not called CC=7 SCAR=40.3
2771 0 ▶ if( !defined( $real_name ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $real_name and -f $_ and not -l $_ and $size == -s $_ and File::Basename::basename($_) ne "posixrules" and File::Compare::compare($_, $file_to_match) == 0) 0 0 0
Condition0%0/15
not defined $real_name and -f $_ and not -l $_ and $size == -s $_ and File::Basename::basename($_) ne "posixrules" and File::Compare::compare($_, $file_to_match) == 0
!ll&&!rl&&r
000
not defined $real_name and -f $_ and not -l $_ and $size == -s $_ and File::Basename::basename($_) ne "posixrules"
!ll&&!rl&&r
000
not defined $real_name and -f $_ and not -l $_ and $size == -s $_
!ll&&!rl&&r
000
not defined $real_name and -f $_ and not -l $_
!ll&&!rl&&r
000
not defined $real_name and -f $_
!ll&&!rl&&r
000
MC/DC0%0/6
not defined $real_name and -f $_ and not -l $_ and $size == -s $_ and File::Basename::basename($_) ne "posixrules" and File::Compare::compare($_, $file_to_match) == 0
not defined $real_name -f $_ not -l $_ $size == -s $_ File::Basename::basename($_) ne "posixrules" File::Compare::compare($_, $file_to_match) == 0
Truth table0%0/7
not(A) and B and not(C) and D and E and F
A= not defined $real_nameB= -f $_C= not -l $_D= $size == -s $_E= File::Basename::basename($_) ne "posixrules"F= File::Compare::compare($_, $file_to_match) == 0
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
2772 -f( $_ ) &&
2773 !-l( $_ ) &&
2774 $size == -s( $_ ) &&
2775 File::Basename::basename( $_ ) ne 'posixrules' &&
2776 File::Compare::compare( $_, $file_to_match ) == 0 )
2777 {
2778 0 $real_name = $_;
2779 # Bail out of File::Find early using die with a sentinel
2780 0 die({ found => 1 });
2781 }
2782 },
2783 0 no_chdir => 1,
2784 },
2785 $zoneinfo_dir );
2786 };
2787 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2788 {
2789 # Re-raise anything that is not our own sentinel
2790 0 ▶ unless( ref( $@ ) eq 'HASH' && $@->{found} )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $@ eq "HASH" and $@->{"found"}) 0 0 0
Condition0%0/3
ref $@ eq "HASH" and $@->{"found"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $@ eq "HASH" and $@->{"found"}
ref $@ eq "HASH" $@->{"found"}
Truth table0%0/3
A and B
A= ref $@ eq "HASH"B= $@->{"found"}
ABresult
0X0
100
111
2791 {
2792 0 return( $class->error( "Error while searching zoneinfo directory: $@" ) );
2793 }
2794 }
2795 0 return( $real_name );
2796 }
2797  
2798 sub _nearest_zone
2799 10 ▶{
Subroutine _nearest_zone: called CC=21 SCAR=38.1
2800 10 my( $class, $latitude, $longitude ) = @_;
2801  
2802 10 ▶ return( $class->error( "Parameter 'latitude' must be a number." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $latitude and &Scalar::Util::looks_like_number($latitude) 1 9 10
Condition66%2/3
defined $latitude and &Scalar::Util::looks_like_number($latitude)
!ll&&!rl&&r
019
MC/DC50%1/2
defined $latitude and &Scalar::Util::looks_like_number($latitude)
defined $latitude &Scalar::Util::looks_like_number($latitude)
Truth table66%2/3
A and B
A= defined $latitudeB= &Scalar::Util::looks_like_number($latitude)
ABresult
0X0
100
111
2803 unless( defined( $latitude ) && Scalar::Util::looks_like_number( $latitude ) );
2804 9 ▶ return( $class->error( "Parameter 'longitude' must be a number." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $longitude and &Scalar::Util::looks_like_number($longitude) 0 9 9
Condition33%1/3
defined $longitude and &Scalar::Util::looks_like_number($longitude)
!ll&&!rl&&r
009
MC/DC0%0/2
defined $longitude and &Scalar::Util::looks_like_number($longitude)
defined $longitude &Scalar::Util::looks_like_number($longitude)
Truth table33%1/3
A and B
A= defined $longitudeB= &Scalar::Util::looks_like_number($longitude)
ABresult
0X0
100
111
2805 unless( defined( $longitude ) && Scalar::Util::looks_like_number( $longitude ) );
2806 9 ▶ return( $class->error( "Latitude must be between -90 and 90." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $latitude >= -90 and $latitude <= 90 1 8 9
Condition66%2/3
$latitude >= -90 and $latitude <= 90
!ll&&!rl&&r
018
MC/DC50%1/2
$latitude >= -90 and $latitude <= 90
$latitude >= -90 $latitude <= 90
Truth table66%2/3
A and B
A= $latitude >= -90B= $latitude <= 90
ABresult
0X0
100
111
2807 unless( $latitude >= -90 && $latitude <= 90 );
2808 8 ▶ return( $class->error( "Longitude must be between -180 and 180." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $longitude >= -180 and $longitude <= 180 1 7 8
Condition66%2/3
$longitude >= -180 and $longitude <= 180
!ll&&!rl&&r
017
MC/DC50%1/2
$longitude >= -180 and $longitude <= 180
$longitude >= -180 $longitude <= 180
Truth table66%2/3
A and B
A= $longitude >= -180B= $longitude <= 180
ABresult
0X0
100
111
2809 unless( $longitude >= -180 && $longitude <= 180 );
2810  
2811 7 my $sth;
2812 7 ▶ unless( $sth = $class->_get_cached_statement( 'nearest_zone' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $class->_get_cached_statement("nearest_zone")) 1 6 7
2813 {
2814 1 ▶ my $dbh = $class->_dbh || return( $class->pass_error );
Condition50%1/2
$class->_dbh || (return $class->pass_error)
l!l
10
MC/DC0%0/1
$class->_dbh || (return $class->pass_error)
$class->_dbh
Truth table50%1/2
A
A= $class->_dbh
Aresult
11
00
2815 1 ▶ $class->_dbh_add_user_defined_functions( $dbh ) ||
Branch: 1 branch
BranchTrueFalseTotal
$class->_dbh_add_user_defined_functions($dbh) or return $class->pass_error 1 0 1
2816 return( $class->pass_error );
2817 # Use the haversine formula entirely within SQLite to find the nearest zone.
2818 # Only canonical zones with coordinates are considered.
2819 # haversine(lat1, lon1, lat2, lon2):
2820 # a = sin((lat2-lat1)/2)^2 + cos(lat1)*cos(lat2)*sin((lon2-lon1)/2)^2
2821 # distance = 2 * asin(sqrt(a))
2822 # in radians; no need for Earth radius since we are only ranking, not computing
2823 # actual distance.
2824 1 my $query = <<'SQL';
2825 SELECT
2826 name,
2827 (
2828 2.0 * asin( sqrt(
2829 ( sin( ( (latitude - ?) * 0.017453292519943 ) / 2.0 ) *
2830 sin( ( (latitude - ?) * 0.017453292519943 ) / 2.0 ) )
2831 +
2832 cos( ? * 0.017453292519943 ) *
2833 cos( latitude * 0.017453292519943 ) *
2834 ( sin( ( (longitude - ?) * 0.017453292519943 ) / 2.0 ) *
2835 sin( ( (longitude - ?) * 0.017453292519943 ) / 2.0 ) )
2836 ) )
2837 ) AS distance
2838 FROM zones
2839 WHERE canonical = 1
2840 AND latitude IS NOT NULL
2841 AND longitude IS NOT NULL
2842 ORDER BY distance ASC
2843 LIMIT 1
2844 SQL
2845 1 local $@;
2846 $sth = eval
2847 1 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $class->error('Cannot prepare nearest_zone: ', $@ || $dbh->errstr, "\nQuery was: $query"))
l!l
10
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $class->error('Cannot prepare nearest_zone: ', $@ || $dbh->errstr, "\nQuery was: $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
2848 1 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
2849 } || return( $class->error( "Cannot prepare nearest_zone: ", ( $@ || $dbh->errstr ), "\nQuery was: $query" ) );
2850 1 $class->_set_cached_statement( nearest_zone => $sth );
2851 }
2852  
2853 7 my $rv = eval{ $sth->execute( $latitude, $latitude, $latitude, $longitude, $longitude ) };
2854 7 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 7 7
elsif (not defined $rv) { } 0 7 7
2855 {
2856 0 $sth->finish;
2857 0 return( $class->error( "Error executing the query to get the nearest zone for latitude $latitude and longitude $longitude: $@", "\nSQL query was ", $sth->{Statement} ) );
2858 }
2859 elsif( !defined( $rv ) )
2860 {
2861 0 $sth->finish;
2862 0 return( $class->error( "Error executing the query to get the nearest zone for latitude $latitude and longitude $longitude: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2863 }
2864  
2865 7 my $row = eval{ $sth->fetchrow_hashref };
2866 7 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 7 7
elsif (not defined $row and $sth->errstr) { } 0 14 14
2867 {
2868 0 $sth->finish;
2869 0 return( $class->error( "Error retrieving the nearest zone information for latitude $latitude and longitude $longitude: $@", "\nSQL query was ", $sth->{Statement} ) );
2870 }
2871 # We check for definedness, which means an error in DBI
2872 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition33%1/3
not defined $row and $sth->errstr
!ll&&!rl&&r
700
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table33%1/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
2873 {
2874 0 $sth->finish;
2875 0 return( $class->error( "Error retrieving the nearest zone information for latitude $latitude and longitude $longitude: ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
2876 }
2877 7 $sth->finish;
2878 7 ▶ unless( defined( $row ) && defined( $row->{name} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $row and defined $row->{"name"}) 0 7 7
Condition33%1/3
defined $row and defined $row->{"name"}
!ll&&!rl&&r
007
MC/DC0%0/2
defined $row and defined $row->{"name"}
defined $row defined $row->{"name"}
Truth table33%1/3
A and B
A= defined $rowB= defined $row->{"name"}
ABresult
0X0
100
111
2879 {
2880 0 return( $class->error( "No timezone found for coordinates ($latitude, $longitude)." ) );
2881 }
2882 7 return( $row->{name} );
2883 }
2884  
2885 # _posix_offset_to_utc( $raw )
2886 # Converts a POSIX TZ offset string (e.g. "5", "-10:30", "+9:30") to
2887 # seconds east of UTC.
2888 # POSIX convention is the inverse of the ISO 8601 convention: a positive
2889 # POSIX offset means WEST of UTC (e.g. "EST5" = UTC-5).
2890 sub _posix_offset_to_utc
2891 0 ▶{
Subroutine _posix_offset_to_utc: not called CC=5 SCAR=34.0
2892 0 my( $self, $raw ) = @_;
2893 # Positive POSIX value = west = negative UTC offset
2894 0 ▶ my $sign = ( $raw =~ s/^-// ) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ s/^-// ? : 0 0 0
2895 0 $raw =~ s/^\+//;
2896 0 my( $h, $m, $s ) = split( /:/, $raw );
2897 0 ▶ return( $sign * ( ( $h // 0 ) * 3600 + ( $m // 0 ) * 60 + ( $s // 0 ) ) );
Condition0%0/6
$h // 0
l!l
00
$m // 0
l!l
00
$s // 0
l!l
00
MC/DC0%0/1
$h // 0
$h
MC/DC0%0/1
$m // 0
$m
MC/DC0%0/1
$s // 0
$s
Truth table0%0/2
A
A= $h
Aresult
11
00
Truth table0%0/2
A
A= $m
Aresult
11
00
Truth table0%0/2
A
A= $s
Aresult
11
00
2898 }
2899  
2900 # _posix_rule_to_unix( $rule, $year, $wall_offset )
2901 # Computes the UTC Unix timestamp of a POSIX DST transition in a given year.
2902 # $rule is a Mm.w.d[/time] string (the only form present in tzdata 2026a).
2903 # $wall_offset is the UTC offset IN EFFECT when this transition occurs
2904 # (standard time offset for the start rule, DST offset for the end rule).
2905 sub _posix_rule_to_unix
2906 0 ▶{
Subroutine _posix_rule_to_unix: not called CC=13 SCAR=52.0
2907 0 my( $self, $rule, $year, $wall_offset ) = @_;
2908  
2909 # Only Mm.w.d form is supported (covers 100% of 2026a footer rules).
2910 0 ▶ return unless( $rule =~ /\AM(\d{1,2})\.(\d)\.(\d)(?:\/(.+))?\z/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $rule =~ m[\AM(\d{1,2})\.(\d)\.(\d)(?:/(.+))?\z] 0 0 0
2911  
2912 0 my( $mon, $week, $dow, $time_s ) = ( int($1), int($2), int($3), $4 );
2913  
2914 # Default wall-clock transition time is 02:00 (7200 seconds).
2915 0 my $wall_time = 7200;
2916 0 ▶ if( defined( $time_s ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time_s) 0 0 0
2917 {
2918 # Per RFC 9636 s3.3.2, time may be negative or exceed 24 h (v3+).
2919 0 ▶ my $tsign = ( $time_s =~ s/^-// ) ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$time_s =~ s/^-// ? : 0 0 0
2920 0 $time_s =~ s/^\+//;
2921 0 my( $th, $tm, $ts ) = split( /:/, $time_s );
2922 0 ▶ $wall_time = $tsign * ( ( $th // 0 ) * 3600 + ( $tm // 0 ) * 60 + ( $ts // 0 ) );
Condition0%0/6
$th // 0
l!l
00
$tm // 0
l!l
00
$ts // 0
l!l
00
MC/DC0%0/1
$th // 0
$th
MC/DC0%0/1
$tm // 0
$tm
MC/DC0%0/1
$ts // 0
$ts
Truth table0%0/2
A
A= $th
Aresult
11
00
Truth table0%0/2
A
A= $tm
Aresult
11
00
Truth table0%0/2
A
A= $ts
Aresult
11
00
2923 }
2924  
2925 # Days in each month for $year
2926 0 my @mlen = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
2927 0 ▶ $mlen[1] = 29 if( $year % 4 == 0 && ( $year % 100 != 0 || $year % 400 == 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $year % 4 == 0 and $year % 100 != 0 || $year % 400 == 0 0 0 0
Condition0%0/6
$year % 4 == 0 and $year % 100 != 0 || $year % 400 == 0
!ll&&!rl&&r
000
$year % 100 != 0 or $year % 400 == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$year % 4 == 0 and $year % 100 != 0 || $year % 400 == 0
$year % 4 == 0 $year % 100 != 0 $year % 400 == 0
Truth table0%0/4
A and B or C
A= $year % 4 == 0B= $year % 100 != 0C= $year % 400 == 0
ABCresult
0XX0
1000
11X1
1011
2928  
2929 # UTC timestamp of January 1 of $year
2930 0 require Time::Local;
2931 0 my $jan1 = Time::Local::timegm( 0, 0, 0, 1, 0, $year );
2932  
2933 # UTC timestamp of the first day of $mon
2934 0 my $days_before = 0;
2935 0 $days_before += $mlen[$_] for 0 .. $mon - 2;
2936 0 my $first_of_month = $jan1 + $days_before * 86400;
2937  
2938 # Day of week of the first day of $mon (0 = Sunday)
2939 0 my $first_dow = ( gmtime( $first_of_month ) )[6];
2940  
2941 # Find the first occurrence of $dow in this month
2942 0 my $diff = ( $dow - $first_dow + 7 ) % 7;
2943 0 my $mday = 1 + $diff;
2944  
2945 0 ▶ if( $week == 5 )
Branch: 1 branch
BranchTrueFalseTotal
if ($week == 5) { } 0 0 0
2946 {
2947 # Week 5 = last occurrence: advance by 7-day steps while still in month
2948 0 ▶ while( $mday + 7 <= $mlen[$mon - 1] ) { $mday += 7 }
Branch: 1 branch
BranchTrueFalseTotal
if ($mday + 7 <= $mlen[$mon - 1]) 0 0 0
2949 }
2950 else
2951 {
2952 0 $mday += ( $week - 1 ) * 7;
2953 }
2954  
2955 # UTC = midnight UTC of that day + wall_time - utc_offset_in_effect
2956 0 return( $first_of_month + ( $mday - 1 ) * 86400 + $wall_time - $wall_offset );
2957 }
2958  
2959 # _posix_tz_lookup( $unix_secs, $footer_tz_string )
2960 #
2961 # When XS is available, this is a thin wrapper around the XS function
2962 # DateTime::Lite::posix_tz_lookup(), which is implemented in dtl_posix.h using IANA
2963 # tzcode (public domain).
2964 # Falls back to the pure-Perl implementation when XS is not available.
2965 # Returns { offset, is_dst, short_name } or undef on parse error.
2966 #
2967 # The three pure-Perl helpers that this replaces
2968 # (_posix_offset_to_utc, _posix_rule_to_unix, _posix_tz_lookup) have been
2969 # removed; the XS implementation covers all their functionality and also handles
2970 # the Jn and n rule forms that the Perl code did not.
2971 sub _posix_tz_lookup
2972 229 ▶{
Subroutine _posix_tz_lookup: called CC=19 SCAR=56.8
2973 229 my( $self, $unix_secs, $tz_string ) = @_;
2974 20 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
2975 229 ▶ unless( $DateTime::Lite::IsPurePerl )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DateTime::Lite::IsPurePerl) 229 0 229
2976 {
2977 229 return( DateTime::Lite::posix_tz_lookup( $self, $unix_secs, $tz_string ) );
2978 }
2979  
2980 # NOTE: Pure-Perl fallback
2981 # Handles all footer formats present in tzdata 2026a:
2982 # - Fixed offset only: "JST-9", "<+0545>-5:45"
2983 # - DST with Mm.w.d: "EST5EDT,M3.2.0,M11.1.0"
2984 # - Quoted names: "<+1245>-12:45<+1345>,M9.5.0/2:45,M4.1.0/3:45"
2985 0 my $tz_str = $tz_string;
2986  
2987 # Parse the standard time abbreviation (quoted <n> or bare letters)
2988 0 my $std_name;
2989 0 ▶ if( $tz_str =~ /\A<([^>]+)>/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($tz_str =~ /\A<([^>]+)>/) { } 0 0 0
elsif ($tz_str =~ /\A([A-Za-z]{3,})/) { } 0 0 0
2990 {
2991 0 $std_name = $1;
2992 0 $tz_str = substr( $tz_str, length( $& ) );
2993 }
2994 elsif( $tz_str =~ /\A([A-Za-z]{3,})/ )
2995 {
2996 0 $std_name = $1;
2997 0 $tz_str = $';
2998 }
2999 else
3000 {
3001 0 return;
3002 }
3003  
3004 # Parse the standard time offset (mandatory, POSIX sign convention)
3005 0 ▶ $tz_str =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/ or return;
Branch: 1 branch
BranchTrueFalseTotal
$tz_str =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/ or return 0 0 0
3006 0 my $std_offset = $self->_posix_offset_to_utc( $1 );
3007 0 $tz_str = $';
3008  
3009 # No DST suffix -> always standard time
3010 0 ▶ unless( length( $tz_str ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length $tz_str) 0 0 0
3011 {
3012 return({
3013 0 offset => $std_offset,
3014 is_dst => 0,
3015 short_name => $std_name,
3016 });
3017 }
3018  
3019 # Parse the DST abbreviation
3020 0 my $dst_name;
3021 0 ▶ if( $tz_str =~ /\A<([^>]+)>/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($tz_str =~ /\A<([^>]+)>/) { } 0 0 0
elsif ($tz_str =~ /\A([A-Za-z]{3,})/) { } 0 0 0
3022 {
3023 0 $dst_name = $1;
3024 0 $tz_str = substr( $tz_str, length( $& ) );
3025 }
3026 elsif( $tz_str =~ /\A([A-Za-z]{3,})/ )
3027 {
3028 0 $dst_name = $1;
3029 0 $tz_str = $';
3030 }
3031 else
3032 {
3033 return({
3034 0 offset => $std_offset,
3035 is_dst => 0,
3036 short_name => $std_name,
3037 });
3038 }
3039  
3040 # Optional DST offset (defaults to standard + 1 hour)
3041 0 my $dst_offset = $std_offset + 3600;
3042 0 ▶ if( $tz_str =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($tz_str =~ /\A([+-]?\d{1,3}(?::\d{2}(?::\d{2})?)?)/) 0 0 0
3043 {
3044 0 $dst_offset = $self->_posix_offset_to_utc( $1 );
3045 0 $tz_str = $';
3046 }
3047  
3048 # DST transition rules (mandatory for correct DST handling)
3049 0 ▶ unless( $tz_str =~ /\A,(.+),(.+)\z/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz_str =~ /\A,(.+),(.+)\z/) 0 0 0
3050 {
3051 return({
3052 0 offset => $std_offset,
3053 is_dst => 0,
3054 short_name => $std_name,
3055 });
3056 }
3057  
3058 0 my( $start_rule, $end_rule ) = ( $1, $2 );
3059 0 my $year = ( gmtime( $unix_secs ) )[5] + 1900;
3060  
3061 0 my $dst_start = $self->_posix_rule_to_unix( $start_rule, $year, $std_offset );
3062 0 my $dst_end = $self->_posix_rule_to_unix( $end_rule, $year, $dst_offset );
3063  
3064 0 ▶ return unless( defined( $dst_start ) && defined( $dst_end ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dst_start and defined $dst_end 0 0 0
Condition0%0/3
defined $dst_start and defined $dst_end
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dst_start and defined $dst_end
defined $dst_start defined $dst_end
Truth table0%0/3
A and B
A= defined $dst_startB= defined $dst_end
ABresult
0X0
100
111
3065  
3066 0 my $is_dst;
3067 0 ▶ if( $dst_start < $dst_end )
Branch: 1 branch
BranchTrueFalseTotal
if ($dst_start < $dst_end) { } 0 0 0
3068 {
3069 # Northern hemisphere: DST is active between start and end
3070 0 ▶ $is_dst = ( $unix_secs >= $dst_start && $unix_secs < $dst_end ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$unix_secs >= $dst_start && $unix_secs < $dst_end ? : 0 0 0
Condition0%0/3
$unix_secs >= $dst_start and $unix_secs < $dst_end
!ll&&!rl&&r
000
MC/DC0%0/2
$unix_secs >= $dst_start and $unix_secs < $dst_end
$unix_secs >= $dst_start $unix_secs < $dst_end
Truth table0%0/3
A and B
A= $unix_secs >= $dst_startB= $unix_secs < $dst_end
ABresult
0X0
100
111
3071 }
3072 else
3073 {
3074 # Southern hemisphere: DST is active outside the start..end range
3075 0 ▶ $is_dst = ( $unix_secs >= $dst_start || $unix_secs < $dst_end ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$unix_secs >= $dst_start || $unix_secs < $dst_end ? : 0 0 0
Condition0%0/3
$unix_secs >= $dst_start or $unix_secs < $dst_end
l!l&&r!l&&!r
000
MC/DC0%0/2
$unix_secs >= $dst_start or $unix_secs < $dst_end
$unix_secs >= $dst_start $unix_secs < $dst_end
Truth table0%0/3
A or B
A= $unix_secs >= $dst_startB= $unix_secs < $dst_end
ABresult
1X1
011
000
3076 }
3077  
3078 return({
3079 0 ▶ offset => ( $is_dst ? $dst_offset : $std_offset ),
Branch: 2 branches
BranchTrueFalseTotal
$is_dst ? : 0 0 0
$is_dst ? : 0 0 0
3080 is_dst => $is_dst,
3081 short_name => ( $is_dst ? $dst_name : $std_name ),
3082 });
3083 }
3084  
3085 # Resolve an alias (such as "US/Eastern") to its canonical zone name.
3086 # Queries aliases JOIN zones so the canonical name is returned directly.
3087 #
3088 # DateTime::Lite::TimeZone->_resolve_alias( $name );
3089 # $tz->_resolve_alias( $name );
3090 sub _resolve_alias
3091 63 ▶{
Subroutine _resolve_alias: called CC=12 SCAR=29.7
3092 63 my $self = shift( @_ );
3093 63 ▶ my $name = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No timezone alias was provided.'))
l!l
630
MC/DC0%0/1
shift @_ || (return $self->error('No timezone alias was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3094 return( $self->error( "No timezone alias was provided." ) );
3095 63 local $@;
3096 63 my $sth;
3097 63 ▶ unless( $sth = $self->_get_cached_statement( 'resolve_alias' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->_get_cached_statement("resolve_alias")) 12 51 63
3098 {
3099 12 my $query = <<'SQL';
3100 SELECT z.name
3101 FROM aliases a
3102 JOIN zones z ON z.zone_id = a.zone_id
3103 WHERE a.alias = ?
3104 SQL
3105 12 ▶ my $dbh = $self->_dbh || return( $self->pass_error );
Condition50%1/2
$self->_dbh || (return $self->pass_error)
l!l
120
MC/DC0%0/1
$self->_dbh || (return $self->pass_error)
$self->_dbh
Truth table50%1/2
A
A= $self->_dbh
Aresult
11
00
3106 12 local $@;
3107 $sth = eval
3108 12 ▶ {
Condition50%1/2
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare resolve_alias: ', $@ || $dbh->errstr, "\nSQL query was $query"))
l!l
120
MC/DC0%0/1
eval { do { $dbh->prepare($query) } } || (return $self->error('Cannot prepare resolve_alias: ', $@ || $dbh->errstr, "\nSQL query was $query"))
eval { do { $dbh->prepare($query) } }
Truth table50%1/2
A
A= eval { do { $dbh->prepare($query) } }
Aresult
11
00
3109 12 ▶ $dbh->prepare( $query );
Condition0%0/3
$@ || $dbh->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $dbh->errstr
$@ $dbh->errstr
Truth table0%0/3
A || B
A= $@B= $dbh->errstr
ABresult
1X1
011
000
3110 } || return( $self->error( "Cannot prepare resolve_alias: ", ( $@ || $dbh->errstr ), "\nSQL query was $query" ) );
3111 12 $self->_set_cached_statement( resolve_alias => $sth );
3112 }
3113  
3114 63 my $rv = eval{ $sth->execute( $name ) };
3115 63 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 63 63
elsif (not defined $rv) { } 0 63 63
3116 {
3117 0 $sth->finish;
3118 0 return( $self->error( "Error executing the query to get the canonical zone name for alias '$name': $@", "\nSQL query was ", $sth->{Statement} ) );
3119 }
3120 elsif( !defined( $rv ) )
3121 {
3122 0 $sth->finish;
3123 0 return( $self->error( "Error executing the query to get the canonical zone name for alias '$name': ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
3124 }
3125  
3126 63 my $row = eval{ $sth->fetchrow_arrayref };
3127 63 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 63 63
elsif (not defined $row and $sth->errstr) { } 0 67 67
3128 {
3129 0 $sth->finish;
3130 0 return( $self->error( "Error retrieving the canonical zone name for alias '$name': $@", "\nSQL query was ", $sth->{Statement} ) );
3131 }
3132 # We check for definedness, which means an error in DBI
3133 ▶ elsif( !defined( $row ) && $sth->errstr )
Condition66%2/3
not defined $row and $sth->errstr
!ll&&!rl&&r
4590
MC/DC0%0/2
not defined $row and $sth->errstr
not defined $row $sth->errstr
Truth table66%2/3
not(A) and B
A= not defined $rowB= $sth->errstr
ABresult
0X0
100
111
3134 {
3135 0 $sth->finish;
3136 0 return( $self->error( "Error retrieving the canonical zone name for alias '$name': ", $sth->errstr, "\nSQL query was ", $sth->{Statement} ) );
3137 }
3138 63 $sth->finish;
3139 # Not found in aliases: the name is assumed to be a canonical zone name
3140 63 ▶ return( $row ? $row->[0] : $name );
Branch: 1 branch
BranchTrueFalseTotal
$row ? : 4 59 63
3141 }
3142  
3143 sub _resolve_local_tz_name
3144 2 ▶{
Subroutine _resolve_local_tz_name: called CC=2 SCAR=7.4
3145 2 my $class = shift( @_ );
3146 # Dispatch to an OS-specific method if one exists, otherwise fall back
3147 # to the Unix implementation (covers Linux, macOS via alias, BSDs, etc.)
3148 # However, we do not support macOS since this means any version of MacOS 9 and earlier.
3149 # MacOSX is $^O code with 'darwin'
3150 2 my $meth = '_local_tz_' . lc( $^O );
3151 2 ▶ if( my $code = $class->can( $meth ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $class->can($meth)) 0 2 2
3152 {
3153 0 return( $code->( $class ) );
3154 }
3155 2 return( $class->_local_tz_unix );
3156 }
3157  
3158 # DateTime::Lite::TimeZone->_set_cached_statement( $id => $sth );
3159 # $tz->_set_cached_statement( $id => $sth );
3160 sub _set_cached_statement
3161 56 ▶{
Subroutine _set_cached_statement: called CC=10 SCAR=28.2
3162 56 my $self = shift( @_ );
3163 56 ▶ my $id = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No statement cache ID was provided.'))
l!l
560
MC/DC0%0/1
shift @_ || (return $self->error('No statement cache ID was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3164 return( $self->error( "No statement cache ID was provided." ) );
3165 56 ▶ my $sth = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No statement object was provided.'))
l!l
560
MC/DC0%0/1
shift @_ || (return $self->error('No statement object was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3166 return( $self->error( "No statement object was provided." ) );
3167 56 ▶ unless( Scalar::Util::blessed( $sth ) && $sth->isa( 'DBI::st' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($sth) and $sth->isa("DBI::st")) 0 56 56
Condition33%1/3
builtin::blessed($sth) and $sth->isa("DBI::st")
!ll&&!rl&&r
0056
MC/DC0%0/2
builtin::blessed($sth) and $sth->isa("DBI::st")
builtin::blessed($sth) $sth->isa("DBI::st")
Truth table33%1/3
A and B
A= builtin::blessed($sth)B= $sth->isa("DBI::st")
ABresult
0X0
100
111
3168 {
3169 0 return( $self->error( "Statement object provided (", overload::StrVal( $sth ), ") is not a DBI statement object." ) );
3170 }
3171 ;
3172 56 my $file = $DB_FILE;
3173 56 ▶ my $tid = ( $Config{useithreads} && $INC{'threads.pm'} && threads->can('tid') ) ? threads->tid() : $$;
Branch: 1 branch
BranchTrueFalseTotal
$DateTime::Lite::TimeZone::Config{'useithreads'} && $INC{'threads.pm'} && 'threads'->can('tid') ? : 0 56 56
Condition33%2/6
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"} and "threads"->can("tid")
!ll&&!rl&&r
5600
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
5600
MC/DC0%0/3
$DateTime::Lite::TimeZone::Config{"useithreads"} and $INC{"threads.pm"} and "threads"->can("tid")
$DateTime::Lite::TimeZone::Config{"useithreads"} $INC{"threads.pm"} "threads"->can("tid")
Truth table25%1/4
A and B and C
A= $DateTime::Lite::TimeZone::Config{"useithreads"}B= $INC{"threads.pm"}C= "threads"->can("tid")
ABCresult
0XX0
10X0
1100
1111
3174 56 ▶ $STHS->{ $tid } //= {};
Condition50%1/2
$DateTime::Lite::TimeZone::STHS->{$tid} //= {}
l!l
560
MC/DC0%0/1
$DateTime::Lite::TimeZone::STHS->{$tid} //= {}
$DateTime::Lite::TimeZone::STHS->{$tid}
Truth table50%1/2
A
A= $DateTime::Lite::TimeZone::STHS->{$tid}
Aresult
11
00
3175 56 ▶ $STHS->{ $tid }->{ $file } //= {};
Condition50%1/2
$DateTime::Lite::TimeZone::STHS->{$tid}{$file} //= {}
l!l
560
MC/DC0%0/1
$DateTime::Lite::TimeZone::STHS->{$tid}{$file} //= {}
$DateTime::Lite::TimeZone::STHS->{$tid}{$file}
Truth table50%1/2
A
A= $DateTime::Lite::TimeZone::STHS->{$tid}{$file}
Aresult
11
00
3176 56 $STHS->{ $tid }->{ $file }->{ $id } = $sth;
3177 56 return( $sth );
3178 }
3179  
3180 sub _set_get_prop
3181 2 ▶{
Subroutine _set_get_prop: called CC=5 SCAR=18.9
3182 2 my $self = shift( @_ );
3183 2 ▶ my $prop = shift( @_ ) || die( "No object property was provided." );
Condition50%1/2
shift @_ || die('No object property was provided.')
l!l
20
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3184 2 ▶ unless( defined( $self ) && ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self) 0 2 2
Condition33%1/3
defined $self and ref $self
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self and ref $self
defined $self ref $self
Truth table33%1/3
A and B
A= defined $selfB= ref $self
ABresult
0X0
100
111
3185 {
3186 0 die( "_set_get_prop() must be called on a class instance." );
3187 }
3188 2 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
3189 2 return( $self->{ $prop } );
3190 }
3191  
3192 sub _win32_tz_from_registry
3193 0 ▶{
Subroutine _win32_tz_from_registry: not called CC=13 SCAR=50.3
3194 0 my $class = shift( @_ );
3195 0 local $@;
3196 my $reg = eval
3197 0 {
3198 20 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
3199 0 Win32::TieRegistry->import( 'KEY_READ', Delimiter => '/' );
3200 0 my $lm = $Win32::TieRegistry::Registry->Open(
3201 'LMachine/', { Access => Win32::TieRegistry::KEY_READ() }
3202 );
3203 0 $lm;
3204 };
3205 0 ▶ return if( $@ || !defined( $reg ) );
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not defined $reg 0 0 0
Condition0%0/3
$@ or not defined $reg
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not defined $reg
$@ not defined $reg
Truth table0%0/3
A or not(B)
A= $@B= not defined $reg
ABresult
1X1
011
000
3206  
3207 0 ▶ if( ref( $reg ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $reg ne "HASH") 0 0 0
3208 {
3209 0 return( $class->error( "I was expecting an hash reference to be returned from Win32::TieRegistry::Registry->Open, but instead I got '", overload::StrVal( $reg ), "'" ) );
3210 }
3211  
3212 0 my $tzi = $reg->{'SYSTEM/CurrentControlSet/Control/TimeZoneInformation/'};
3213 0 ▶ return unless( defined( $tzi ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tzi 0 0 0
3214  
3215 # Windows Vista and newer
3216 0 ▶ if( defined( $tzi->{'/TimeZoneKeyName'} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tzi->{"/TimeZoneKeyName"} and $tzi->{"/TimeZoneKeyName"} ne "") 0 0 0
Condition0%0/3
defined $tzi->{"/TimeZoneKeyName"} and $tzi->{"/TimeZoneKeyName"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tzi->{"/TimeZoneKeyName"} and $tzi->{"/TimeZoneKeyName"} ne ""
defined $tzi->{"/TimeZoneKeyName"} $tzi->{"/TimeZoneKeyName"} ne ""
Truth table0%0/3
A and B
A= defined $tzi->{"/TimeZoneKeyName"}B= $tzi->{"/TimeZoneKeyName"} ne ""
ABresult
0X0
100
111
3217 $tzi->{'/TimeZoneKeyName'} ne '' )
3218 {
3219 0 my $n = $tzi->{'/TimeZoneKeyName'};
3220 # Strip trailing null garbage (Windows 2008 Server)
3221 0 $n =~ s/\0.*$//s;
3222 0 return( $n );
3223 }
3224  
3225 # Windows NT/2000/XP/2003: match StandardName against zone sub-keys
3226 0 foreach my $key (
3227 'SOFTWARE/Microsoft/Windows NT/CurrentVersion/Time Zones/',
3228 'SOFTWARE/Microsoft/Windows/CurrentVersion/Time Zones/',
3229 )
3230 {
3231 0 my $zones = $reg->{ $key };
3232 0 ▶ next unless( defined( $zones ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zones 0 0 0
3233 0 my $std = $tzi->{'/StandardName'};
3234 0 ▶ next unless( defined( $std ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $std 0 0 0
3235 0 for my $zone ( $zones->SubKeyNames )
3236 {
3237 0 ▶ if( defined( $zones->{ $zone . '/Std' } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$zones{$zone . '/Std'} and $$zones{$zone . '/Std'} eq $std) 0 0 0
Condition0%0/3
defined $$zones{$zone . '/Std'} and $$zones{$zone . '/Std'} eq $std
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$zones{$zone . '/Std'} and $$zones{$zone . '/Std'} eq $std
defined $$zones{$zone . '/Std'} $$zones{$zone . '/Std'} eq $std
Truth table0%0/3
A and B
A= defined $$zones{$zone . '/Std'}B= $$zones{$zone . '/Std'} eq $std
ABresult
0X0
100
111
3238 $zones->{ $zone . '/Std' } eq $std )
3239 {
3240 0 return( $zone );
3241 }
3242 }
3243 }
3244  
3245 0 return;
3246 }
3247  
3248 # NOTE: END
3249 # Cleanup of the DBI handles upon end of process
3250 END
3251 20 ▶{
Subroutine END: called CC=16 SCAR=31.0
3252 20 CORE::local( $., $@, $!, $^E, $? );
3253 # Finish all cached statement handles first
3254 20 ▶ if( ref( $STHS ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $DateTime::Lite::TimeZone::STHS eq "HASH") 20 0 20
3255 {
3256 20 foreach my $tid ( keys( %$STHS ) )
3257 {
3258 14 ▶ next unless( defined( $STHS->{ $tid } ) && ref( $STHS->{ $tid } ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $DateTime::Lite::TimeZone::STHS->{$tid} and ref $DateTime::Lite::TimeZone::STHS->{$tid} eq "HASH" 0 14 14
Condition33%1/3
defined $DateTime::Lite::TimeZone::STHS->{$tid} and ref $DateTime::Lite::TimeZone::STHS->{$tid} eq "HASH"
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $DateTime::Lite::TimeZone::STHS->{$tid} and ref $DateTime::Lite::TimeZone::STHS->{$tid} eq "HASH"
defined $DateTime::Lite::TimeZone::STHS->{$tid} ref $DateTime::Lite::TimeZone::STHS->{$tid} eq "HASH"
Truth table33%1/3
A and B
A= defined $DateTime::Lite::TimeZone::STHS->{$tid}B= ref $DateTime::Lite::TimeZone::STHS->{$tid} eq "HASH"
ABresult
0X0
100
111
3259 14 foreach my $file ( keys( %{$STHS->{ $tid }} ) )
3260 {
3261 14 ▶ next unless( defined( $STHS->{ $tid }->{ $file } ) && ref( $STHS->{ $tid }->{ $file } ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $DateTime::Lite::TimeZone::STHS->{$tid}{$file} and ref $DateTime::Lite::TimeZone::STHS->{$tid}{$file} eq "HASH" 0 14 14
Condition33%1/3
defined $DateTime::Lite::TimeZone::STHS->{$tid}{$file} and ref $DateTime::Lite::TimeZone::STHS->{$tid}{$file} eq "HASH"
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $DateTime::Lite::TimeZone::STHS->{$tid}{$file} and ref $DateTime::Lite::TimeZone::STHS->{$tid}{$file} eq "HASH"
defined $DateTime::Lite::TimeZone::STHS->{$tid}{$file} ref $DateTime::Lite::TimeZone::STHS->{$tid}{$file} eq "HASH"
Truth table33%1/3
A and B
A= defined $DateTime::Lite::TimeZone::STHS->{$tid}{$file}B= ref $DateTime::Lite::TimeZone::STHS->{$tid}{$file} eq "HASH"
ABresult
0X0
100
111
3262 14 foreach my $id ( keys( %{$STHS->{ $tid }->{ $file }} ) )
3263 {
3264 56 my $sth = $STHS->{ $tid }->{ $file }->{ $id };
3265 56 ▶ eval{ $sth->finish } if( ref( $sth ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $sth 56 0 56
3266 }
3267 }
3268 }
3269 }
3270 # Then disconnect all database handles
3271 20 ▶ if( ref( $DBH ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $DateTime::Lite::TimeZone::DBH eq "HASH") 20 0 20
3272 {
3273 20 foreach my $tid ( keys( %$DBH ) )
3274 {
3275 14 ▶ next unless( defined( $DBH->{ $tid } ) && ref( $DBH->{ $tid } ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH" 0 14 14
Condition33%1/3
defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH"
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $DateTime::Lite::TimeZone::DBH->{$tid} and ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH"
defined $DateTime::Lite::TimeZone::DBH->{$tid} ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH"
Truth table33%1/3
A and B
A= defined $DateTime::Lite::TimeZone::DBH->{$tid}B= ref $DateTime::Lite::TimeZone::DBH->{$tid} eq "HASH"
ABresult
0X0
100
111
3276 14 foreach my $file ( keys( %{$DBH->{ $tid }} ) )
3277 {
3278 14 my $dbh = $DBH->{ $tid }->{ $file };
3279 14 ▶ eval{ $dbh->disconnect } if( ref( $dbh ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $dbh 14 0 14
3280 }
3281 }
3282 }
3283 20 $STHS = {};
3284 20 $DBH = {};
3285 }
3286  
3287 sub DESTROY
3288 272 ▶{
Subroutine DESTROY: called CC=3 SCAR=13.1
3289 # See https://perldoc.perl.org/perlobj#Destructors
3290 272 CORE::local( $., $@, $!, $^E, $? );
3291 272 ▶ CORE::return if( defined( ${^GLOBAL_PHASE} ) && ${^GLOBAL_PHASE} eq 'DESTRUCT' );
Branch: 1 branch
BranchTrueFalseTotal
if defined ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT" 0 272 272
Condition33%1/3
defined ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
!ll&&!rl&&r
02720
MC/DC0%0/2
defined ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
defined ${^GLOBAL_PHASE} ${^GLOBAL_PHASE} eq "DESTRUCT"
Truth table33%1/3
A and B
A= defined ${^GLOBAL_PHASE}B= ${^GLOBAL_PHASE} eq "DESTRUCT"
ABresult
0X0
100
111
3292 }
3293  
3294 20 1;
3295 # NOTE: POD
3296 __END__
« lib/DateTime/Lite/PP.pm ↑ Summary lib/DateTime/Lite.pm »