lib/DateTime/Lite.pm

filter: Statementstmt 78.5% 944 / 1202 Branchbran 54.8% 342 / 624 Conditioncond 43.2% 251 / 581 MC/DCmcdc 15.4% 47 / 304 Subroutinesub 81.4% 211 / 259 Podpod 81.9% 86 / 105 totaltotal 61.1% 1881 / 3075 CC 614 SCAR 36.5
CC
614
Cov
64%
pass_error
457.3
from_object
131.9
THAW
110.0
CRAP 38.6
« lib/DateTime/Lite/TimeZone.pm ↑ Summary lib/DateTime/Lite/Exception.pm »
1 ##----------------------------------------------------------------------------
2 ## Lightweight DateTime Alternative - ~/lib/DateTime/Lite.pm
3 ## Version v0.11.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/04/03
7 ## Modified 2026/10/28
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package DateTime::Lite;
14 BEGIN
15 16 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶ use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 16 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 16 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 16 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $VERSION $AUTOLOAD $AUTOLOAD_SUBS $ERROR $FATAL_EXCEPTIONS $IsPurePerl
22 @MonthLengths @LeapYearMonthLengths
23 @QuarterLengths @LeapYearQuarterLengths
24 16 );
25 16 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 16 ▶ use DateTime::Locale::FromCLDR;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 16 ▶ use POSIX qw( floor fmod );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 16 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 16 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 16 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
31 fallback => 1,
32 '<=>' => '_compare_overload',
33 'cmp' => '_string_compare_overload',
34 q{""} => 'stringify',
35 247 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
36 16 '-' => '_subtract_overload',
37 '+' => '_add_overload',
38 'eq' => '_string_equals_overload',
39 'ne' => '_string_not_equals_overload',
40 16 );
41 16 our $VERSION = 'v0.11.0';
42  
43 16 @MonthLengths = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
44 16 @LeapYearMonthLengths = @MonthLengths;
45 16 $LeapYearMonthLengths[1]++;
46  
47 16 @QuarterLengths = ( 90, 91, 92, 92 );
48 16 @LeapYearQuarterLengths = @QuarterLengths;
49 16 $LeapYearQuarterLengths[0]++;
50 };
51  
52 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 # NOTE: Load XS; fall back to pure-Perl implementations if unavailable.
56 {
57 16 my $loaded = 0;
58 16 ▶ unless( $ENV{PERL_DATETIME_LITE_PP} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PERL_DATETIME_LITE_PP"}) 16 0 16
59 {
60 16 local $@;
61 eval
62 16 {
63 16 require XSLoader;
64 XSLoader::load(
65 __PACKAGE__,
66 16 exists( $DateTime::Lite::{VERSION} ) && ${ $DateTime::Lite::{VERSION} }
67 16 ▶ ? ${ $DateTime::Lite::{VERSION} }
Branch: 1 branch
BranchTrueFalseTotal
exists $DateTime::Lite::{'VERSION'} && ${$DateTime::Lite::{'VERSION'};} ? : 16 0 16
Condition33%1/3
exists $DateTime::Lite::{"VERSION"} and ${$DateTime::Lite::{"VERSION"};}
!ll&&!rl&&r
0016
MC/DC0%0/2
exists $DateTime::Lite::{"VERSION"} and ${$DateTime::Lite::{"VERSION"};}
exists $DateTime::Lite::{"VERSION"} ${$DateTime::Lite::{"VERSION"};}
Truth table33%1/3
A and B
A= exists $DateTime::Lite::{"VERSION"}B= ${$DateTime::Lite::{"VERSION"};}
ABresult
0X0
100
111
68 : 42
69 );
70 16 $loaded = 1;
71 16 $IsPurePerl = 0;
72 };
73 16 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 16 16
74 {
75 # Fall back to pure-Perl silently on:
76 # - version mismatch ("object version")
77 # - not a shared lib ("loadable object")
78 # - missing compiler builtin not available on old GCC/platforms
79 # ("Undefined symbol" covers __builtin_unreachable on GCC < 4.5)
80 0 ▶ die( $@ ) if( $@ && $@ !~ /object version|loadable object|Undefined symbol/i );
Branch: 1 branch
BranchTrueFalseTotal
if $@ and not $@ =~ /object version|loadable object|Undefined symbol/i 0 0 0
Condition0%0/3
$@ and not $@ =~ /object version|loadable object|Undefined symbol/i
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and not $@ =~ /object version|loadable object|Undefined symbol/i
$@ not $@ =~ /object version|loadable object|Undefined symbol/i
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ /object version|loadable object|Undefined symbol/i
ABresult
0X0
100
111
81 }
82 }
83 16 ▶ unless( $loaded )
Branch: 1 branch
BranchTrueFalseTotal
unless ($loaded) 0 16 16
84 {
85 0 require DateTime::Lite::PP;
86 0 $IsPurePerl = 1;
87 }
88 }
89  
90 16 require DateTime::Lite::Duration;
91 16 require DateTime::Lite::TimeZone;
92  
93 # NOTE: Constants
94 sub INFINITY () { 100**100**100**100 }
95 sub MAX_NANOSECONDS () { 1_000_000_000 }
96 sub NEG_INFINITY () { -1 * ( 100**100**100**100 ) }
97 sub NAN () { INFINITY - INFINITY }
98 sub SECONDS_PER_DAY () { 86400 }
99  
100 # NOTE: subroutine pre-declaration
101 # for sub in `perl -ln -E 'say "$1" if( /^sub (\w+)[[:blank:]\v]*(?:\{|\Z|[[:blank:]\v]*:[[:blank:]\v]*lvalue)/ )' ./lib/DateTime/Lite.pm | LC_COLLATE=C sort -uV`; do echo "sub $sub;"; done
102 sub AUTOLOAD;
103 sub DESTROY;
104 sub FREEZE;
105 sub STORABLE_freeze;
106 sub STORABLE_thaw;
107 sub THAW;
108 sub TO_JSON;
109 sub add;
110 sub add_duration;
111 sub am_or_pm;
112 sub ce_year;
113 sub christian_era;
114 sub compare;
115 sub compare_ignore_floating;
116 sub datetime;
117 sub day;
118 sub day_abbr;
119 sub day_name;
120 sub day_of_month_0;
121 sub day_of_quarter;
122 sub day_of_quarter_0;
123 sub day_of_week;
124 sub day_of_week_0;
125 sub day_of_year;
126 sub day_of_year_0;
127 sub delta_days;
128 sub delta_md;
129 sub delta_ms;
130 sub dmy;
131 sub end_of;
132 sub epoch;
133 sub era_abbr;
134 sub era_name;
135 sub error;
136 sub fatal;
137 sub formatter;
138 sub fractional_second;
139 sub from_day_of_year;
140 sub from_epoch;
141 sub from_object;
142 sub hires_epoch;
143 sub hms;
144 sub hour;
145 sub hour_1;
146 sub hour_12;
147 sub hour_12_0;
148 sub iso8601;
149 sub is_between;
150 sub is_dst;
151 sub is_finite;
152 sub is_infinite;
153 sub is_last_day_of_month;
154 sub is_last_day_of_quarter;
155 sub is_last_day_of_year;
156 sub is_leap_year;
157 sub jd;
158 sub last_day_of_month;
159 sub leap_seconds;
160 sub locale;
161 sub local_day_of_week;
162 sub local_rd_as_seconds;
163 sub local_rd_values;
164 sub mdy;
165 sub microsecond;
166 sub millisecond;
167 sub minute;
168 sub mjd;
169 sub month;
170 sub month_0;
171 sub month_abbr;
172 sub month_length;
173 sub month_name;
174 sub nanosecond;
175 sub new;
176 sub now;
177 sub offset;
178 sub pass_error;
179 sub quarter;
180 sub quarter_0;
181 sub quarter_abbr;
182 sub quarter_length;
183 sub quarter_name;
184 sub rfc3339;
185 sub second;
186 sub secular_era;
187 sub set;
188 sub set_day;
189 sub set_formatter;
190 sub set_hour;
191 sub set_locale;
192 sub set_minute;
193 sub set_month;
194 sub set_nanosecond;
195 sub set_second;
196 sub set_time_zone;
197 sub set_year;
198 sub start_of;
199 sub stringify;
200 sub subtract;
201 sub subtract_datetime;
202 sub subtract_datetime_absolute;
203 sub subtract_duration;
204 sub time_zone;
205 sub time_zone_long_name;
206 sub time_zone_short_name;
207 sub today;
208 sub truncate;
209 sub utc_rd_as_seconds;
210 sub utc_rd_values;
211 sub utc_year;
212 sub week;
213 sub weekday_of_month;
214 sub week_number;
215 sub week_of_month;
216 sub week_year;
217 sub year;
218 sub year_length;
219 sub year_with_christian_era;
220 sub year_with_era;
221 sub year_with_secular_era;
222 sub ymd;
223 sub _add_duration;
224 sub _add_overload;
225 sub _adjust_for_positive_difference;
226 sub _autoload_subs;
227 sub _calc_local_components;
228 sub _calc_local_rd;
229 sub _calc_utc_rd;
230 sub _compare;
231 sub _compare_overload;
232 sub _core_time;
233 sub _default_time_zone;
234 sub _duration_object_from_args;
235 sub _era_index;
236 sub _format_nanosecs;
237 sub _handle_offset_modifier;
238 sub _is_integer;
239 sub _maybe_future_dst_warning;
240 sub _month_length;
241 sub _new;
242 sub _new_from_self;
243 sub _normalize_seconds;
244 sub _offset_for_local_datetime;
245 sub _resolve_time_zone;
246 sub _set_get_prop;
247 sub _set_locale;
248 sub _string_compare_overload;
249 sub _string_equals_overload;
250 sub _string_not_equals_overload;
251 sub _subtract_overload;
252 sub _weeks_in_year;
253 sub _week_values;
254  
255 # NOTE: Class-level default locale management
256 {
257 16 my $DefaultLocale;
258  
259 sub DefaultLocale
260 128 ▶ {
Subroutine DefaultLocale: called CC=3 SCAR=11.0
Pod documented
261 128 my $class = shift( @_ );
262 128 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 112 128
263 {
264 16 my $lang = shift( @_ );
265 16 ▶ $DefaultLocale = DateTime::Locale::FromCLDR->new( $lang ) ||
Condition50%1/2
'DateTime::Locale::FromCLDR'->new($lang) || die('DateTime::Locale::FromCLDR'->error)
l!l
160
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new($lang) || die('DateTime::Locale::FromCLDR'->error)
'DateTime::Locale::FromCLDR'->new($lang)
Truth table50%1/2
A
A= 'DateTime::Locale::FromCLDR'->new($lang)
Aresult
11
00
266 die( DateTime::Locale::FromCLDR->error );
267 }
268 128 return( $DefaultLocale );
269 }
270 }
271  
272 16 __PACKAGE__->DefaultLocale( 'en-US' );
273  
274 # NOTE: Constructor
275 sub new
276 165 ▶{
Subroutine new: called CC=29 SCAR=42.0
Pod documented
277 165 my $this = shift( @_ );
278 165 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
01650
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
279 165 my %p = @_;
280  
281 # Required
282 165 ▶ unless( exists( $p{year} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $p{"year"}) 2 163 165
283 {
284 2 return( $class->error( "Parameter 'year' is required." ) );
285 }
286 # Validate and apply defaults
287 163 ▶ $p{month} //= 1;
Condition100%2/2
$p{"month"} //= 1
l!l
1558
MC/DC100%1/1
$p{"month"} //= 1
$p{"month"}
Truth table100%2/2
A
A= $p{"month"}
Aresult
11
00
288 163 ▶ $p{day} //= 1;
Condition100%2/2
$p{"day"} //= 1
l!l
1558
MC/DC100%1/1
$p{"day"} //= 1
$p{"day"}
Truth table100%2/2
A
A= $p{"day"}
Aresult
11
00
289 163 ▶ $p{hour} //= 0;
Condition100%2/2
$p{"hour"} //= 0
l!l
10261
MC/DC100%1/1
$p{"hour"} //= 0
$p{"hour"}
Truth table100%2/2
A
A= $p{"hour"}
Aresult
11
00
290 163 ▶ $p{minute} //= 0;
Condition100%2/2
$p{"minute"} //= 0
l!l
8578
MC/DC100%1/1
$p{"minute"} //= 0
$p{"minute"}
Truth table100%2/2
A
A= $p{"minute"}
Aresult
11
00
291 163 ▶ $p{second} //= 0;
Condition100%2/2
$p{"second"} //= 0
l!l
8578
MC/DC100%1/1
$p{"second"} //= 0
$p{"second"}
Truth table100%2/2
A
A= $p{"second"}
Aresult
11
00
292 163 ▶ $p{nanosecond} //= 0;
Condition100%2/2
$p{"nanosecond"} //= 0
l!l
61102
MC/DC100%1/1
$p{"nanosecond"} //= 0
$p{"nanosecond"}
Truth table100%2/2
A
A= $p{"nanosecond"}
Aresult
11
00
293  
294 return( $class->error( sprintf( "Invalid month value (%s).", $p{month} ) ) )
295 163 ▶ unless( _is_integer( $p{month} ) && $p{month} >= 1 && $p{month} <= 12 );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_integer($p{"month"}) and $p{"month"} >= 1 and $p{"month"} <= 12 0 163 163
Condition33%2/6
_is_integer($p{"month"}) and $p{"month"} >= 1 and $p{"month"} <= 12
!ll&&!rl&&r
00163
_is_integer($p{"month"}) and $p{"month"} >= 1
!ll&&!rl&&r
00163
MC/DC0%0/3
_is_integer($p{"month"}) and $p{"month"} >= 1 and $p{"month"} <= 12
_is_integer($p{"month"}) $p{"month"} >= 1 $p{"month"} <= 12
Truth table25%1/4
A and B and C
A= _is_integer($p{"month"})B= $p{"month"} >= 1C= $p{"month"} <= 12
ABCresult
0XX0
10X0
1100
1111
296  
297 return( $class->error( sprintf( "Invalid day value (%s).", $p{day} ) ) )
298 163 ▶ unless( _is_integer( $p{day} ) && $p{day} >= 1 && $p{day} <= 31 );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_integer($p{"day"}) and $p{"day"} >= 1 and $p{"day"} <= 31 0 163 163
Condition33%2/6
_is_integer($p{"day"}) and $p{"day"} >= 1 and $p{"day"} <= 31
!ll&&!rl&&r
00163
_is_integer($p{"day"}) and $p{"day"} >= 1
!ll&&!rl&&r
00163
MC/DC0%0/3
_is_integer($p{"day"}) and $p{"day"} >= 1 and $p{"day"} <= 31
_is_integer($p{"day"}) $p{"day"} >= 1 $p{"day"} <= 31
Truth table25%1/4
A and B and C
A= _is_integer($p{"day"})B= $p{"day"} >= 1C= $p{"day"} <= 31
ABCresult
0XX0
10X0
1100
1111
299  
300 return( $class->error( sprintf( "Invalid hour value (%s).", $p{hour} ) ) )
301 163 ▶ unless( _is_integer( $p{hour} ) && $p{hour} >= 0 && $p{hour} <= 23 );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_integer($p{"hour"}) and $p{"hour"} >= 0 and $p{"hour"} <= 23 0 163 163
Condition33%2/6
_is_integer($p{"hour"}) and $p{"hour"} >= 0 and $p{"hour"} <= 23
!ll&&!rl&&r
00163
_is_integer($p{"hour"}) and $p{"hour"} >= 0
!ll&&!rl&&r
00163
MC/DC0%0/3
_is_integer($p{"hour"}) and $p{"hour"} >= 0 and $p{"hour"} <= 23
_is_integer($p{"hour"}) $p{"hour"} >= 0 $p{"hour"} <= 23
Truth table25%1/4
A and B and C
A= _is_integer($p{"hour"})B= $p{"hour"} >= 0C= $p{"hour"} <= 23
ABCresult
0XX0
10X0
1100
1111
302  
303 return( $class->error( sprintf( "Invalid minute value (%s).", $p{minute} ) ) )
304 163 ▶ unless( _is_integer( $p{minute} ) && $p{minute} >= 0 && $p{minute} <= 59 );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_integer($p{"minute"}) and $p{"minute"} >= 0 and $p{"minute"} <= 59 0 163 163
Condition33%2/6
_is_integer($p{"minute"}) and $p{"minute"} >= 0 and $p{"minute"} <= 59
!ll&&!rl&&r
00163
_is_integer($p{"minute"}) and $p{"minute"} >= 0
!ll&&!rl&&r
00163
MC/DC0%0/3
_is_integer($p{"minute"}) and $p{"minute"} >= 0 and $p{"minute"} <= 59
_is_integer($p{"minute"}) $p{"minute"} >= 0 $p{"minute"} <= 59
Truth table25%1/4
A and B and C
A= _is_integer($p{"minute"})B= $p{"minute"} >= 0C= $p{"minute"} <= 59
ABCresult
0XX0
10X0
1100
1111
305  
306 return( $class->error( sprintf( "Invalid second value (%s).", $p{second} ) ) )
307 163 ▶ unless( _is_integer( $p{second} ) && $p{second} >= 0 && $p{second} <= 61 );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_integer($p{"second"}) and $p{"second"} >= 0 and $p{"second"} <= 61 0 163 163
Condition33%2/6
_is_integer($p{"second"}) and $p{"second"} >= 0 and $p{"second"} <= 61
!ll&&!rl&&r
00163
_is_integer($p{"second"}) and $p{"second"} >= 0
!ll&&!rl&&r
00163
MC/DC0%0/3
_is_integer($p{"second"}) and $p{"second"} >= 0 and $p{"second"} <= 61
_is_integer($p{"second"}) $p{"second"} >= 0 $p{"second"} <= 61
Truth table25%1/4
A and B and C
A= _is_integer($p{"second"})B= $p{"second"} >= 0C= $p{"second"} <= 61
ABCresult
0XX0
10X0
1100
1111
308  
309 return( $class->error( sprintf( "Invalid nanosecond value (%s).", $p{nanosecond} ) ) )
310 163 ▶ unless( _is_integer( $p{nanosecond} ) && $p{nanosecond} >= 0 && $p{nanosecond} < MAX_NANOSECONDS );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_integer($p{"nanosecond"}) and $p{"nanosecond"} >= 0 and $p{"nanosecond"} < 1000000000 0 163 163
Condition33%2/6
_is_integer($p{"nanosecond"}) and $p{"nanosecond"} >= 0 and $p{"nanosecond"} < 1000000000
!ll&&!rl&&r
00163
_is_integer($p{"nanosecond"}) and $p{"nanosecond"} >= 0
!ll&&!rl&&r
00163
MC/DC0%0/3
_is_integer($p{"nanosecond"}) and $p{"nanosecond"} >= 0 and $p{"nanosecond"} < 1000000000
_is_integer($p{"nanosecond"}) $p{"nanosecond"} >= 0 $p{"nanosecond"} < 1000000000
Truth table25%1/4
A and B and C
A= _is_integer($p{"nanosecond"})B= $p{"nanosecond"} >= 0C= $p{"nanosecond"} < 1000000000
ABCresult
0XX0
10X0
1100
1111
311  
312 163 ▶ if( $p{day} > 28 )
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"day"} > 28) 16 147 163
313 {
314 16 my $max_day = $class->_month_length( $p{year}, $p{month} );
315 return( $class->error(
316 sprintf( "Invalid day of month (day = %d, month = %d, year = %d).", $p{day}, $p{month}, $p{year} )
317 16 ▶ ) ) if( $p{day} > $max_day );
Branch: 1 branch
BranchTrueFalseTotal
if $p{"day"} > $max_day 1 15 16
318 }
319  
320 162 return( $class->_new( %p ) );
321 }
322  
323 16 my %valid_new = map{ $_ => 1 } qw( year month day hour minute second nanosecond time_zone locale formatter fatal );
324 sub _new
325 213 ▶{
Subroutine _new: called CC=26 SCAR=37.6
326 213 my $this = shift( @_ );
327 213 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
02130
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
328 213 my %p = @_;
329  
330 213 ▶ return( $class->error( "Constructor called with reference, expected a package name." ) ) if( ref( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this 0 213 213
331  
332 213 my @unknown = sort( grep{ !exists( $valid_new{ $_ } ) } keys( %p ) );
333 213 ▶ if( @unknown )
Branch: 1 branch
BranchTrueFalseTotal
if (@unknown) 3 210 213
334 {
335 3 my $sub = (caller(1))[3];
336 return( $class->error( sprintf(
337 "Unknown argument%s passed to %s->%s: %s",
338 @unknown > 1 ? 's' : '',
339 $class,
340 $sub,
341 3 ▶ join( ', ', map{ qq{'$_'} } @unknown ),
Branch: 1 branch
BranchTrueFalseTotal
@unknown > 1 ? : 0 3 3
342 ) ) );
343 }
344  
345 210 ▶ $p{month} //= 1;
Condition50%1/2
$p{"month"} //= 1
l!l
2100
MC/DC0%0/1
$p{"month"} //= 1
$p{"month"}
Truth table50%1/2
A
A= $p{"month"}
Aresult
11
00
346 210 ▶ $p{day} //= 1;
Condition50%1/2
$p{"day"} //= 1
l!l
2100
MC/DC0%0/1
$p{"day"} //= 1
$p{"day"}
Truth table50%1/2
A
A= $p{"day"}
Aresult
11
00
347 210 ▶ $p{hour} //= 0;
Condition100%2/2
$p{"hour"} //= 0
l!l
2046
MC/DC100%1/1
$p{"hour"} //= 0
$p{"hour"}
Truth table100%2/2
A
A= $p{"hour"}
Aresult
11
00
348 210 ▶ $p{minute} //= 0;
Condition100%2/2
$p{"minute"} //= 0
l!l
2046
MC/DC100%1/1
$p{"minute"} //= 0
$p{"minute"}
Truth table100%2/2
A
A= $p{"minute"}
Aresult
11
00
349 210 ▶ $p{second} //= 0;
Condition100%2/2
$p{"second"} //= 0
l!l
2046
MC/DC100%1/1
$p{"second"} //= 0
$p{"second"}
Truth table100%2/2
A
A= $p{"second"}
Aresult
11
00
350 210 ▶ $p{nanosecond} //= 0;
Condition100%2/2
$p{"nanosecond"} //= 0
l!l
19119
MC/DC100%1/1
$p{"nanosecond"} //= 0
$p{"nanosecond"}
Truth table100%2/2
A
A= $p{"nanosecond"}
Aresult
11
00
351 # NOTE: time_zone is intentionally NOT defaulted here anymore; we need to
352 # resolve any BCP47 -u-tz- extension from the locale first.
353 # $p{time_zone} //= $class->_default_time_zone;
354 # Should errors be fatal?
355 210 ▶ $p{fatal} //= ( $FATAL_EXCEPTIONS // 0 );
Condition50%2/4
$p{"fatal"} //= $DateTime::Lite::FATAL_EXCEPTIONS // 0
l!l
0210
$DateTime::Lite::FATAL_EXCEPTIONS // 0
l!l
0210
MC/DC0%0/1
$p{"fatal"} //= $DateTime::Lite::FATAL_EXCEPTIONS // 0
$p{"fatal"}
Truth table50%1/2
A
A= $p{"fatal"}
Aresult
11
00
356  
357 210 my $self = bless( {}, $class );
358  
359 # If time_zone is a hash reference, resolve it to a TimeZone object now, before
360 # _resolve_time_zone() sees it. This allows callers to pass options such as
361 # extended set to true or latitude/longitude without constructing the
362 # DateTime::Lite::TimeZone object themselves first.
363 210 ▶ if( defined( $p{time_zone} ) && ref( $p{time_zone} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"time_zone"} and ref $p{"time_zone"} eq "HASH") 0 210 210
Condition66%2/3
defined $p{"time_zone"} and ref $p{"time_zone"} eq "HASH"
!ll&&!rl&&r
181920
MC/DC0%0/2
defined $p{"time_zone"} and ref $p{"time_zone"} eq "HASH"
defined $p{"time_zone"} ref $p{"time_zone"} eq "HASH"
Truth table66%2/3
A and B
A= defined $p{"time_zone"}B= ref $p{"time_zone"} eq "HASH"
ABresult
0X0
100
111
364 {
365 0 ▶ $p{time_zone} = DateTime::Lite::TimeZone->new( %{ $p{time_zone} } ) ||
Condition0%0/2
'DateTime::Lite::TimeZone'->new(%{$p{'time_zone'};}) || (return $class->pass_error('DateTime::Lite::TimeZone'->error))
l!l
00
MC/DC0%0/1
'DateTime::Lite::TimeZone'->new(%{$p{'time_zone'};}) || (return $class->pass_error('DateTime::Lite::TimeZone'->error))
'DateTime::Lite::TimeZone'->new(%{$p{'time_zone'};})
Truth table0%0/2
A
A= 'DateTime::Lite::TimeZone'->new(%{$p{'time_zone'};})
Aresult
11
00
366 return( $class->pass_error( DateTime::Lite::TimeZone->error ) );
367 }
368  
369 210 ▶ $p{time_zone} = $class->_resolve_time_zone( $p{locale}, $p{time_zone} ) //
Condition66%2/3
$class->_resolve_time_zone($p{"locale"}, $p{"time_zone"}) // $class->_default_time_zone
l!l&&r!l&&!r
198120
MC/DC0%0/2
$class->_resolve_time_zone($p{"locale"}, $p{"time_zone"}) // $class->_default_time_zone
$class->_resolve_time_zone($p{"locale"}, $p{"time_zone"}) $class->_default_time_zone
Truth table66%2/3
A // B
A= $class->_resolve_time_zone($p{"locale"}, $p{"time_zone"})B= $class->_default_time_zone
ABresult
1X1
011
000
370 $class->_default_time_zone;
371  
372 # _set_locale now returns the DateTime::Locale::FromCLDR object
373 210 ▶ my $cldr = $self->_set_locale( $p{locale} ) || return( $class->pass_error );
Condition100%2/2
$self->_set_locale($p{'locale'}) || (return $class->pass_error)
l!l
2091
MC/DC100%1/1
$self->_set_locale($p{'locale'}) || (return $class->pass_error)
$self->_set_locale($p{'locale'})
Truth table100%2/2
A
A= $self->_set_locale($p{'locale'})
Aresult
11
00
374  
375 # Validate that a ref is actually a DateTime::Lite::TimeZone object before
376 # using it. A plain string goes through TimeZone->new as usual.
377 209 ▶ if( defined( $p{time_zone} ) && ref( $p{time_zone} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{'time_zone'} and ref $p{'time_zone'}) { } 55 154 209
Condition66%2/3
defined $p{"time_zone"} and ref $p{"time_zone"}
!ll&&!rl&&r
015455
MC/DC50%1/2
defined $p{"time_zone"} and ref $p{"time_zone"}
defined $p{"time_zone"} ref $p{"time_zone"}
Truth table66%2/3
A and B
A= defined $p{"time_zone"}B= ref $p{"time_zone"}
ABresult
0X0
100
111
378 {
379 55 ▶ unless( Scalar::Util::blessed( $p{time_zone} ) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($p{"time_zone"}) and $p{"time_zone"}->isa("DateTime::Lite::TimeZone")) 0 55 55
Condition33%1/3
builtin::blessed($p{"time_zone"}) and $p{"time_zone"}->isa("DateTime::Lite::TimeZone")
!ll&&!rl&&r
0055
MC/DC0%0/2
builtin::blessed($p{"time_zone"}) and $p{"time_zone"}->isa("DateTime::Lite::TimeZone")
builtin::blessed($p{"time_zone"}) $p{"time_zone"}->isa("DateTime::Lite::TimeZone")
Truth table33%1/3
A and B
A= builtin::blessed($p{"time_zone"})B= $p{"time_zone"}->isa("DateTime::Lite::TimeZone")
ABresult
0X0
100
111
380 $p{time_zone}->isa( 'DateTime::Lite::TimeZone' ) )
381 {
382 0 return( $class->error( "time_zone option must be a DateTime::Lite::TimeZone object, got " . ref( $p{time_zone} ) ) );
383 }
384 55 $self->{tz} = $p{time_zone};
385 }
386 else
387 {
388 154 ▶ $self->{tz} = DateTime::Lite::TimeZone->new( name => $p{time_zone} ) ||
Condition50%1/2
'DateTime::Lite::TimeZone'->new('name', $p{'time_zone'}) || (return $class->pass_error('DateTime::Lite::TimeZone'->error))
l!l
1540
MC/DC0%0/1
'DateTime::Lite::TimeZone'->new('name', $p{'time_zone'}) || (return $class->pass_error('DateTime::Lite::TimeZone'->error))
'DateTime::Lite::TimeZone'->new('name', $p{'time_zone'})
Truth table50%1/2
A
A= 'DateTime::Lite::TimeZone'->new('name', $p{'time_zone'})
Aresult
11
00
389 return( $class->pass_error( DateTime::Lite::TimeZone->error ) );
390 }
391  
392 209 $self->{local_rd_days} = $class->_ymd2rd( @p{ qw( year month day ) } );
393 209 $self->{local_rd_secs} = $class->_time_as_seconds( @p{ qw( hour minute second ) } );
394 209 $self->{offset_modifier} = 0;
395 209 $self->{rd_nanosecs} = $p{nanosecond};
396 209 $self->{formatter} = $p{formatter};
397  
398 $self->_normalize_nanoseconds(
399 $self->{local_rd_secs},
400 $self->{rd_nanosecs},
401 209 );
402  
403 # Bootstrap utc_year so TZ offset calculation has a rough year to work with.
404 209 $self->{utc_year} = $p{year} + 1;
405  
406 209 $self->_maybe_future_dst_warning( $p{year}, $p{time_zone} );
407 209 $self->_calc_utc_rd;
408 209 $self->_handle_offset_modifier( $p{second} );
409 209 $self->_calc_local_rd;
410  
411 209 ▶ if( $p{second} > 59 )
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"second"} > 59) 0 209 209
412 {
413 0 ▶ if( $self->{tz}->is_floating ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tz"}->is_floating or $self->{"utc_rd_secs"} - 86399 < $p{"second"} - 59) 0 0 0
Condition0%0/3
$self->{"tz"}->is_floating or $self->{"utc_rd_secs"} - 86399 < $p{"second"} - 59
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"tz"}->is_floating or $self->{"utc_rd_secs"} - 86399 < $p{"second"} - 59
$self->{"tz"}->is_floating $self->{"utc_rd_secs"} - 86399 < $p{"second"} - 59
Truth table0%0/3
A or B
A= $self->{"tz"}->is_floatingB= $self->{"utc_rd_secs"} - 86399 < $p{"second"} - 59
ABresult
1X1
011
000
414 ( $self->{utc_rd_secs} - 86399 < $p{second} - 59 ) )
415 {
416 0 return( $self->error( "Invalid second value ($p{second})." ) );
417 }
418 }
419  
420 209 return( $self );
421 }
422  
423 # NOTE: Arithmetic
424 sub add
425 24 ▶{
Subroutine add: called CC=1 SCAR=0.0
Pod documented
426 24 my $self = shift( @_ );
427 24 return( $self->add_duration( $self->_duration_object_from_args( @_ ) ) );
428 }
429  
430 sub add_duration
431 42 ▶{
Subroutine add_duration: called CC=10 SCAR=25.2
Pod documented
432 42 my $self = shift( @_ );
433 42 my $dur = shift( @_ );
434  
435 42 ▶ unless( Scalar::Util::blessed( $dur ) && $dur->isa( $self->duration_class ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($dur) and $dur->isa($self->duration_class)) 0 42 42
Condition33%1/3
builtin::blessed($dur) and $dur->isa($self->duration_class)
!ll&&!rl&&r
0042
MC/DC0%0/2
builtin::blessed($dur) and $dur->isa($self->duration_class)
builtin::blessed($dur) $dur->isa($self->duration_class)
Truth table33%1/3
A and B
A= builtin::blessed($dur)B= $dur->isa($self->duration_class)
ABresult
0X0
100
111
436 {
437 0 return( $self->error( "Argument to add_duration() must be a " . $self->duration_class . " object." ) );
438 }
439  
440 42 ▶ return( $self ) if( $dur->is_zero );
Branch: 1 branch
BranchTrueFalseTotal
if $dur->is_zero 0 42 42
441  
442 42 my %deltas = $dur->deltas;
443  
444 # Handle infinite durations
445 42 foreach my $val ( values( %deltas ) )
446 {
447 210 my $inf;
448 210 ▶ if( $val == INFINITY )
Branch: 2 branches
BranchTrueFalseTotal
if ($val == 9**9**9) { } 1 209 210
elsif ($val == -9**9**9) { } 0 209 209
449 {
450 1 require DateTime::Lite::Infinite;
451 1 $inf = DateTime::Lite::Infinite::Future->new;
452 }
453 elsif( $val == NEG_INFINITY )
454 {
455 0 require DateTime::Lite::Infinite;
456 0 $inf = DateTime::Lite::Infinite::Past->new;
457 }
458 210 ▶ if( $inf )
Branch: 1 branch
BranchTrueFalseTotal
if ($inf) 1 209 210
459 {
460 1 %$self = %$inf;
461 1 bless( $self, ref( $inf ) );
462 1 return( $self );
463 }
464 }
465  
466 41 ▶ return( $self ) if( $self->is_infinite );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_infinite 0 41 41
467  
468 41 local $@;
469 41 my %orig = %$self;
470 41 my $ok = eval{ $self->_add_duration( $dur ); 1 };
471 41 ▶ unless( $ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 41 41
472 {
473 0 my $err = $@;
474 0 %$self = %orig;
475 0 die( $err );
476 }
477 41 return( $self );
478 }
479  
480 # NOTE: sub am_or_pm is autoloaded
481  
482 # NOTE: sub ce_year is autoloaded
483  
484 # NOTE: sub christian_era is autoloaded
485  
486 # NOTE: sub clone is implemented in the XS code in DateTime-Lite.xs
487 # Pure-Perl fallback: used when XS is not available (PERL_DATETIME_LITE_PP=1 or on
488 # platforms where the .so fails to load such as old GCC on FreeBSD).
489 # Mirrors the XS implementation: scalar values are copied, nested blessed hashrefs are
490 # shallow-cloned one level deep and re-blessed.
491 16 ▶if( $IsPurePerl )
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::IsPurePerl) 0 16 16
492 {
493 16 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
494 *clone = sub
495 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
496 0 my $self = shift( @_ );
497 0 my $class = ref( $self );
498 0 my %copy;
499 0 foreach my $key ( keys( %$self ) )
500 {
501 0 my $val = $self->{ $key };
502 # Use reftype() to detect underlying HASH regardless of blessing
503 0 ▶ if( defined( $val ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and (builtin::reftype($val) // '') eq 'HASH') { } 0 0 0
Condition0%0/5
defined $val and (builtin::reftype($val) // "") eq "HASH"
!ll&&!rl&&r
000
builtin::reftype($val) // ""
l!l
00
MC/DC0%0/2
defined $val and (builtin::reftype($val) // "") eq "HASH"
defined $val builtin::reftype($val)
Truth table0%0/3
A and B
A= defined $valB= builtin::reftype($val)
ABresult
0X0
100
111
504 ( Scalar::Util::reftype( $val ) // '' ) eq 'HASH' )
505 {
506 0 my $inner = { %$val };
507 0 ▶ if( Scalar::Util::blessed( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($val)) 0 0 0
508 {
509 0 bless( $inner, ref( $val ) );
510 }
511 0 $copy{ $key } = $inner;
512 }
513 else
514 {
515 0 $copy{ $key } = $val;
516 }
517 }
518 0 return( bless( \%copy, $class ) );
519 0 };
520 }
521  
522 # NOTE: Comparison
523 36 ▶sub compare { return( shift->_compare( @_, 0 ) ); }
Subroutine compare: called CC=1 SCAR=0.0
Pod documented
524  
525 # NOTE: To compare an object to an integer representing a timestamp.
526 sub compare_epoch
527 0 ▶{
Subroutine compare_epoch: not called CC=4 SCAR=30.0
Pod documented
528 0 my $self = shift( @_ );
529 0 my $epoch = shift( @_ );
530 0 ▶ unless( defined( $epoch ) && Scalar::Util::looks_like_number( $epoch ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $epoch and &Scalar::Util::looks_like_number($epoch)) 0 0 0
Condition0%0/3
defined $epoch and &Scalar::Util::looks_like_number($epoch)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $epoch and &Scalar::Util::looks_like_number($epoch)
defined $epoch &Scalar::Util::looks_like_number($epoch)
Truth table0%0/3
A and B
A= defined $epochB= &Scalar::Util::looks_like_number($epoch)
ABresult
0X0
100
111
531 {
532 0 return( $self->error( "compare_epoch() expects a Unix epoch number." ) );
533 }
534 0 ▶ my $other = DateTime::Lite->from_epoch( epoch => $epoch ) ||
Condition0%0/2
'DateTime::Lite'->from_epoch('epoch', $epoch) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
'DateTime::Lite'->from_epoch('epoch', $epoch) || (return $self->pass_error)
'DateTime::Lite'->from_epoch('epoch', $epoch)
Truth table0%0/2
A
A= 'DateTime::Lite'->from_epoch('epoch', $epoch)
Aresult
11
00
535 return( $self->pass_error );
536 0 return( $self->compare( $other ) );
537 }
538  
539 sub compare_ignore_floating
540 1 ▶{
Subroutine compare_ignore_floating: called CC=2 SCAR=7.2
Pod documented
541 1 ▶ my $class = ref( $_[0] ) ? undef : shift( @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
542 1 shift->_compare( @_, 1 );
543 }
544  
545 sub datetime
546 15 ▶{
Subroutine datetime: called CC=2 SCAR=6.9
Pod documented
547 15 my $self = shift( @_ );
548 15 ▶ my $sep = shift( @_ ) // 'T';
Condition100%2/2
shift @_ // "T"
l!l
132
MC/DC100%1/1
shift @_ // "T"
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
549 15 return( join( $sep, $self->ymd( '-' ), $self->hms( ':' ) ) );
550 }
551  
552 142 ▶sub day { return( $_[0]->{local_c}->{day} ) }
Subroutine day: called CC=1 SCAR=0.0
Pod documented
553  
554 {
555 16 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
556 16 *day_of_month = \&day;
557 }
558  
559 sub day_abbr
560 4 ▶{
Subroutine day_abbr: called CC=1 SCAR=0.0
Pod documented
561 4 my $self = shift( @_ );
562 4 return( $self->{locale}->day_format_abbreviated->[ $self->day_of_week_0 ] );
563 }
564  
565 sub day_name
566 5 ▶{
Subroutine day_name: called CC=1 SCAR=0.0
Pod documented
567 5 my $self = shift( @_ );
568 5 return( $self->{locale}->day_format_wide->[ $self->day_of_week_0 ] );
569 }
570  
571 # NOTE: sub day_of_month_0 is autoloaded
572  
573 # NOTE: sub day_of_quarter is autoloaded
574  
575 # NOTE: sub day_of_quarter_0 is autoloaded
576  
577 14 ▶sub day_of_week { return( shift->{local_c}->{day_of_week} ); }
Subroutine day_of_week: called CC=1 SCAR=0.0
Pod documented
578  
579 # NOTE: sub day_of_week_0 is autoloaded
580  
581 13 ▶sub day_of_year { return( shift->{local_c}->{day_of_year} ); }
Subroutine day_of_year: called CC=1 SCAR=0.0
Pod documented
582  
583 # NOTE: sub day_of_year_0 is autoloaded
584  
585 sub delta_days
586 1 ▶{
Subroutine delta_days: called CC=1 SCAR=0.0
Pod documented
587 1 my $self = shift( @_ );
588 1 my $dt = shift( @_ );
589 1 my $days = abs( ( $self->local_rd_values )[0] - ( $dt->local_rd_values )[0] );
590 1 return( $self->duration_class->new( days => $days ) );
591 }
592  
593 sub delta_md
594 1 ▶{
Subroutine delta_md: called CC=1 SCAR=0.0
Pod documented
595 1 my $self = shift( @_ );
596 1 my $dt = shift( @_ );
597  
598 1 my( $smaller, $bigger ) = sort( $self, $dt );
599  
600 1 my( $months, $days ) = $dt->_adjust_for_positive_difference(
601 $bigger->year * 12 + $bigger->month,
602 $smaller->year * 12 + $smaller->month,
603 $bigger->day, $smaller->day,
604 0, 0,
605 0, 0,
606 0, 0,
607 60,
608 $smaller->_month_length( $smaller->year, $smaller->month ),
609 );
610  
611 1 return( $self->duration_class->new( months => $months, days => $days ) );
612 }
613  
614 sub delta_ms
615 1 ▶{
Subroutine delta_ms: called CC=1 SCAR=0.0
Pod documented
616 1 my $self = shift( @_ );
617 1 my $dt = shift( @_ );
618 1 my( $smaller, $greater ) = sort( $self, $dt );
619  
620 1 my $days = int( $greater->jd - $smaller->jd );
621 1 my $dur = $greater->subtract_datetime( $smaller );
622  
623 1 return( $self->duration_class->new(
624 hours => $dur->hours + ( $days * 24 ),
625 minutes => $dur->minutes,
626 seconds => $dur->seconds,
627 ) );
628 }
629  
630 # NOTE: sub dmy is autoloaded
631  
632 sub duration_class () { 'DateTime::Lite::Duration' }
633  
634 # See also start_of()
635 sub end_of
636 13 ▶{
Subroutine end_of: called CC=7 SCAR=19.9
Pod documented
637 13 my $self = shift( @_ );
638 13 ▶ my $unit = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error(q[Parameter 'unit' is required for end_of().]))
l!l
130
MC/DC0%0/1
shift @_ || (return $self->error(q[Parameter 'unit' is required for end_of().]))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
639 return( $self->error( "Parameter 'unit' is required for end_of()." ) );
640  
641 13 my %valid = map{ $_ => 1 } qw(
642 year decade century quarter month week local_week day hour minute second
643 );
644 13 ▶ unless( $valid{ $unit } )
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid{$unit}) 1 12 13
645 {
646 1 return( $self->error( "Invalid unit '$unit' for end_of()." ) );
647 }
648  
649 # Strategy: move to start_of the next unit, then subtract 1 nanosecond.
650 # This correctly handles variable-length units (months, years, etc.)
651 # without hardcoding boundary values.
652 12 my %next_unit = (
653 second => [ second => 1 ],
654 minute => [ minute => 1 ],
655 hour => [ hour => 1 ],
656 day => [ day => 1 ],
657 week => [ week => 1 ],
658 local_week => [ week => 1 ],
659 month => [ month => 1 ],
660 quarter => [ month => 3 ],
661 year => [ year => 1 ],
662 decade => [ year => 10 ],
663 century => [ year => 100],
664 );
665  
666 # Clone internally, compute, then overwrite self
667 12 ▶ my $copy = $self->clone || return( $self->pass_error );
Condition50%1/2
$self->clone || (return $self->pass_error)
l!l
120
MC/DC0%0/1
$self->clone || (return $self->pass_error)
$self->clone
Truth table50%1/2
A
A= $self->clone
Aresult
11
00
668 12 ▶ $copy->start_of( $unit ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$copy->start_of($unit) or return $self->pass_error 12 0 12
669 12 my( $add_unit, $add_val ) = @{$next_unit{ $unit }};
670 12 ▶ $copy->add( "${add_unit}s" => $add_val ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$copy->add("${add_unit}s", $add_val) or return $self->pass_error 12 0 12
671 12 ▶ $copy->subtract( nanoseconds => 1 ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$copy->subtract("nanoseconds", 1) or return $self->pass_error 12 0 12
672  
673 12 %$self = %$copy;
674 12 return( $self );
675 }
676  
677 # NOTE: epoch
678 sub epoch
679 21 ▶{
Subroutine epoch: called CC=3 SCAR=11.3
Pod documented
680 21 my $self = shift( @_ );
681 21 ▶ return( $self->{utc_c}->{epoch} ) if( exists( $self->{utc_c}->{epoch} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"utc_c"}{"epoch"} 3 18 21
682  
683 18 ▶ if( $IsPurePerl )
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::IsPurePerl) { } 0 18 18
684 {
685 return( $self->{utc_c}->{epoch}
686 = ( $self->{utc_rd_days} - 719163 ) * SECONDS_PER_DAY
687 0 + $self->{utc_rd_secs} );
688 }
689 else
690 {
691 return( $self->{utc_c}->{epoch}
692 18 = $self->_rd_to_epoch( $self->{utc_rd_days}, $self->{utc_rd_secs} ) );
693 }
694 }
695  
696 # NOTE: sub era_abbr is autoloaded
697  
698 # NOTE: sub era_name is autoloaded
699  
700 # NOTE: Error handling
701 sub error
702 18 ▶{
Subroutine error: called CC=8 SCAR=21.3
Pod documented
703 18 my $self = shift( @_ );
704 18 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 9 9 18
705 {
706 9 require DateTime::Lite::Exception;
707 9 ▶ my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 11 11
708 9 my $e = DateTime::Lite::Exception->new({
709 skip_frames => 1,
710 message => $msg,
711 });
712 9 $ERROR = $e;
713 9 ▶ $self->{error} = $e if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 3 6 9
714 9 ▶ if( $self->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 9 9
715 {
716 0 die( $self->{error} );
717 }
718 else
719 {
720 9 ▶ warn( $msg ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 4 5 9
721 9 ▶ rreturn( DateTime::Lite::NullObject->new ) if( want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("OBJECT") 0 9 9
722 9 return;
723 }
724 }
725 9 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 9 9
726 }
727  
728 sub fatal
729 10 ▶{
Subroutine fatal: called CC=5 SCAR=22.7
Pod documented
730 10 my $this = shift( @_ );
731 10 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 10 10
732 {
733 0 ▶ if( ref( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this) { } 0 0 0
734 {
735 0 return( $this->_set_get_prop( 'fatal', @_ ) );
736 }
737 else
738 {
739 0 ▶ warn( "Cannot call fatal in mutator mode as a class method." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
740 }
741 }
742 10 ▶ return( ref( $this ) ? $this->_set_get_prop( 'fatal' ) : $FATAL_EXCEPTIONS );
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 4 6 10
743 }
744  
745 # NOTE: format_cldr
746 # TODO: If the user wants to do CLDR formatting, we should instead load DateTime::Format::Unicode, which does a much better job, because CLDR formatting is not easy. So, we should lazy-load DateTime::Format::Unicode instead
747 {
748 my @cldr_patterns = (
749 0 ▶ qr/GGGGG/ => sub{ $_[0]->{locale}->era_narrow->[ $_[0]->_era_index ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
750 qr/GGGG/ => 'era_name',
751 qr/G{1,3}/ => 'era_abbr',
752  
753 3 ▶ qr/(y{3,5})/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->year ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
754 0 ▶ qr/yy/ => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
755 0 my $year = $_[0]->year;
756 0 ▶ my $y2 = length( $year ) > 2 ? substr( $year, -2, 2 ) : $year;
Branch: 1 branch
BranchTrueFalseTotal
length $year > 2 ? : 0 0 0
757 0 ▶ $y2 *= -1 if( $year < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $year < 0 0 0 0
758 0 $_[0]->_zero_padded_number( 'yy', $y2 );
759 },
760 qr/y/ => 'year',
761 0 ▶ qr/(u+)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->year ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
762 0 ▶ qr/(Y+)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->week_year ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
763  
764 qr/QQQQ/ => 'quarter_name',
765 qr/QQQ/ => 'quarter_abbr',
766 0 ▶ qr/(QQ?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->quarter ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
767  
768 0 ▶ qr/qqqq/ => sub{ $_[0]->{locale}->quarter_stand_alone_wide->[ $_[0]->quarter_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
769 0 ▶ qr/qqq/ => sub{ $_[0]->{locale}->quarter_stand_alone_abbreviated->[ $_[0]->quarter_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
770 0 ▶ qr/(qq?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->quarter ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
771  
772 0 ▶ qr/MMMMM/ => sub{ $_[0]->{locale}->month_format_narrow->[ $_[0]->month_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
773 qr/MMMM/ => 'month_name',
774 qr/MMM/ => 'month_abbr',
775 3 ▶ qr/(MM?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->month ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
776  
777 0 ▶ qr/LLLLL/ => sub{ $_[0]->{locale}->month_stand_alone_narrow->[ $_[0]->month_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
778 0 ▶ qr/LLLL/ => sub{ $_[0]->{locale}->month_stand_alone_wide->[ $_[0]->month_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
779 0 ▶ qr/LLL/ => sub{ $_[0]->{locale}->month_stand_alone_abbreviated->[ $_[0]->month_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
780 0 ▶ qr/(LL?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->month ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
781  
782 0 ▶ qr/(ww?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->week_number ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
783 qr/W/ => 'week_of_month',
784  
785 3 ▶ qr/(dd?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->day_of_month ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
786 0 ▶ qr/(D{1,3})/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->day_of_year ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
787  
788 qr/F/ => 'weekday_of_month',
789 0 ▶ qr/(g+)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->mjd ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
790  
791 0 ▶ qr/EEEEE/ => sub{ $_[0]->{locale}->day_format_narrow->[ $_[0]->day_of_week_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
792 qr/EEEE/ => 'day_name',
793 qr/E{1,3}/ => 'day_abbr',
794  
795 0 ▶ qr/eeeee/ => sub{ $_[0]->{locale}->day_format_narrow->[ $_[0]->day_of_week_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
796 qr/eeee/ => 'day_name',
797 qr/eee/ => 'day_abbr',
798 0 ▶ qr/(ee?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->local_day_of_week ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
799  
800 0 ▶ qr/ccccc/ => sub{ $_[0]->{locale}->day_stand_alone_narrow->[ $_[0]->day_of_week_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
801 0 ▶ qr/cccc/ => sub{ $_[0]->{locale}->day_stand_alone_wide->[ $_[0]->day_of_week_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
802 0 ▶ qr/ccc/ => sub{ $_[0]->{locale}->day_stand_alone_abbreviated->[ $_[0]->day_of_week_0 ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
803 0 ▶ qr/(cc?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->day_of_week ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
804  
805 qr/a/ => 'am_or_pm',
806  
807 0 ▶ qr/(hh?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->hour_12 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
808 2 ▶ qr/(HH?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->hour ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
809 0 ▶ qr/(KK?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->hour_12_0 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
810 0 ▶ qr/(kk?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->hour_1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
811 0 ▶ qr/(jj?)/ => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
812 my $h = $_[0]->{locale}->prefers_24_hour_time
813 0 ▶ ? $_[0]->hour
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'locale'}->prefers_24_hour_time ? : 0 0 0
814 : $_[0]->hour_12;
815 0 $_[0]->_zero_padded_number( $1, $h );
816 },
817  
818 2 ▶ qr/(mm?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->minute ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
819 2 ▶ qr/(ss?)/ => sub{ $_[0]->_zero_padded_number( $1, $_[0]->second ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
820 0 ▶ qr/(S+)/ => sub{ $_[0]->_format_nanosecs( length( $1 ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
821 0 ▶ qr/A+/ => sub{ ( $_[0]->{local_rd_secs} * 1000 ) + $_[0]->millisecond },
Subroutine __ANON__: not called CC=1 SCAR=6.9
822  
823 qr/zzzz/ => 'time_zone_long_name',
824 qr/z{1,3}/ => 'time_zone_short_name',
825 0 ▶ qr/ZZZZZ/ => sub{ DateTime::Lite::TimeZone->offset_as_string( $_[0]->offset, ':' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
826 0 ▶ qr/ZZZZ/ => sub{ $_[0]->time_zone_short_name . DateTime::Lite::TimeZone->offset_as_string( $_[0]->offset ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
827 0 ▶ qr/Z{1,3}/ => sub{ DateTime::Lite::TimeZone->offset_as_string( $_[0]->offset ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
828 16 qr/vvvv/ => 'time_zone_long_name',
829 qr/v{1,3}/ => 'time_zone_short_name',
830 qr/VVVV/ => 'time_zone_long_name',
831 qr/V{1,3}/ => 'time_zone_short_name',
832 );
833  
834 # NOTE: format_cldr()
835 sub format_cldr
836 8 ▶ {
Subroutine format_cldr: called CC=10 SCAR=26.7
Pod documented
837 8 ▶ if( !scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @_) 0 8 8
838 {
839 0 die( 'Usage: $dt->format_cldr( $format )' );
840 }
841 8 my $self = shift( @_ );
842 8 ▶ if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and builtin::blessed($self // "")) 0 8 8
Condition40%2/5
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
008
$self // ""
l!l
80
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
843 {
844 0 die( 'Usage: $dt->format_cldr( $format )' );
845 }
846 8 my @p = @_;
847  
848 8 my @r;
849 8 foreach my $p ( @p )
850 {
851 8 $p =~ s/\G
852 (?:
853 '((?:[^']|'')*)' # quote-escaped text
854 |
855 (([a-zA-Z])\3*) # pattern token
856 |
857 (.) # literal character
858 )
859 /
860 24 ▶ defined( $1 )
Branch: 3 branches
BranchTrueFalseTotal
defined $1 ? : 2 22 24
defined $2 ? : 15 7 22
defined $4 ? : 7 0 7
861 ? $1
862 : defined( $2 )
863 ? $self->_cldr_pattern( $2 )
864 : defined( $4 )
865 ? $4
866 : undef
867 /sgex;
868  
869 8 $p =~ s/''/'/g;
870  
871 8 ▶ return( $p ) unless( wantarray );
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 8 0 8
872 0 push( @r, $p );
873 }
874 0 return( @r );
875 }
876  
877 # NOTE: _cldr_pattern()
878 sub _cldr_pattern
879 15 ▶ {
Subroutine _cldr_pattern: called CC=4 SCAR=14.3
880 15 my $self = shift( @_ );
881 15 my $pattern = shift( @_ );
882  
883 15 ▶ for( my $i = 0; $i < @cldr_patterns; $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @cldr_patterns) 411 0 411
884 {
885 411 ▶ if( $pattern =~ /$cldr_patterns[$i]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern =~ /$cldr_patterns[$i]/) 15 396 411
886 {
887 15 my $sub = $cldr_patterns[ $i + 1 ];
888 15 ▶ return( ref( $sub ) eq 'CODE' ? $sub->( $self ) : $self->$sub() );
Branch: 1 branch
BranchTrueFalseTotal
ref $sub eq 'CODE' ? : 15 0 15
889 }
890 }
891 0 return( $pattern );
892 }
893  
894 # NOTE: _zero_padded_number()
895 sub _zero_padded_number
896 15 ▶ {
Subroutine _zero_padded_number: called CC=1 SCAR=0.0
897 15 my $self = shift( @_ );
898 15 my $size = length( shift( @_ ) );
899 15 my $val = shift( @_ );
900 15 return( sprintf( "%0${size}d", $val ) );
901 }
902 }
903  
904 85 ▶sub formatter { return( shift->{formatter} ); }
Subroutine formatter: called CC=1 SCAR=0.0
Pod documented
905  
906 # NOTE: sub fractional_second is autoloaded
907  
908 # NOTE: Alternative constructors
909 sub from_day_of_year
910 2 ▶{
Subroutine from_day_of_year: called CC=8 SCAR=22.4
Pod documented
911 2 my $this = shift( @_ );
912 2 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
913 2 my %p = @_;
914  
915 return( $class->error( "Parameter 'year' is required." ) )
916 2 ▶ unless( exists( $p{year} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"year"} 0 2 2
917 return( $class->error( "Parameter 'day_of_year' is required." ) )
918 2 ▶ unless( exists( $p{day_of_year} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"day_of_year"} 0 2 2
919  
920 2 ▶ if( $p{day_of_year} == 366 && !$class->_is_leap_year( $p{year} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"day_of_year"} == 366 and not $class->_is_leap_year($p{"year"})) 0 2 2
Condition33%1/3
$p{"day_of_year"} == 366 and not $class->_is_leap_year($p{"year"})
!ll&&!rl&&r
200
MC/DC0%0/2
$p{"day_of_year"} == 366 and not $class->_is_leap_year($p{"year"})
$p{"day_of_year"} == 366 not $class->_is_leap_year($p{"year"})
Truth table33%1/3
A and not(B)
A= $p{"day_of_year"} == 366B= not $class->_is_leap_year($p{"year"})
ABresult
0X0
100
111
921 {
922 0 return( $class->error( "$p{year} is not a leap year." ) );
923 }
924  
925 2 my $month = 1;
926 2 my $day = delete( $p{day_of_year} );
927  
928 2 ▶ if( $day > 31 )
Branch: 1 branch
BranchTrueFalseTotal
if ($day > 31) 2 0 2
929 {
930 2 my $length = $class->_month_length( $p{year}, $month );
931 2 ▶ while( $day > $length )
Branch: 1 branch
BranchTrueFalseTotal
if ($day > $length) 6 2 8
932 {
933 6 $day -= $length;
934 6 $month++;
935 6 $length = $class->_month_length( $p{year}, $month );
936 }
937 }
938  
939 2 return( $class->_new( %p, month => $month, day => $day ) );
940 }
941  
942 sub from_epoch
943 15 ▶{
Subroutine from_epoch: called CC=11 SCAR=25.6
Pod documented
944 15 my $this = shift( @_ );
945 15 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0150
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
946 15 my %p;
947  
948 15 ▶ if( @_ == 1 && !ref( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 0 15 15
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
1500
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
949 {
950 0 $p{epoch} = shift( @_ );
951 }
952 else
953 {
954 15 %p = @_;
955 }
956  
957 return( $class->error( "Parameter 'epoch' is required." ) )
958 15 ▶ unless( exists( $p{epoch} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"epoch"} 0 15 15
959  
960 return( $class->error( "Parameter 'epoch' must be a number." ) )
961 15 ▶ unless( defined( $p{epoch} ) && Scalar::Util::looks_like_number( $p{epoch} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"epoch"} and &Scalar::Util::looks_like_number($p{"epoch"}) 0 15 15
Condition33%1/3
defined $p{"epoch"} and &Scalar::Util::looks_like_number($p{"epoch"})
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $p{"epoch"} and &Scalar::Util::looks_like_number($p{"epoch"})
defined $p{"epoch"} &Scalar::Util::looks_like_number($p{"epoch"})
Truth table33%1/3
A and B
A= defined $p{"epoch"}B= &Scalar::Util::looks_like_number($p{"epoch"})
ABresult
0X0
100
111
962  
963 15 my %args;
964 # Handle non-integer epochs - round to microsecond to avoid NV precision loss
965 15 ▶ if( int( $p{epoch} ) != $p{epoch} )
Branch: 1 branch
BranchTrueFalseTotal
if (int $p{"epoch"} != $p{"epoch"}) 1 14 15
966 {
967 1 my $floor = my $nano = fmod( $p{epoch}, 1.0 );
968 1 my $second = floor( $p{epoch} - $floor );
969 1 ▶ if( $nano < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($nano < 0) 0 1 1
970 {
971 0 $nano += 1;
972 }
973 1 $p{epoch} = $second + floor( $floor - $nano );
974 1 $args{nanosecond} = floor( $nano * 1E6 + 0.5 ) * 1E3;
975 }
976  
977 @args{ qw( second minute hour day month year ) }
978 15 = ( gmtime( $p{epoch} ) )[0 .. 5];
979 15 $args{year} += 1900;
980 15 $args{month} += 1;
981 # We do not need 'epoch' argument anymore
982 15 delete( $p{epoch} );
983  
984 15 ▶ my $self = $class->_new( %p, %args, time_zone => 'UTC' ) || return( $class->pass_error );
Condition100%2/2
$class->_new(%p, %args, 'time_zone', 'UTC') || (return $class->pass_error)
l!l
141
MC/DC100%1/1
$class->_new(%p, %args, 'time_zone', 'UTC') || (return $class->pass_error)
$class->_new(%p, %args, 'time_zone', 'UTC')
Truth table100%2/2
A
A= $class->_new(%p, %args, 'time_zone', 'UTC')
Aresult
11
00
985  
986 14 my $target_tz = $class->_resolve_time_zone( $p{locale}, $p{time_zone} );
987 14 $self->_maybe_future_dst_warning( $self->year, $target_tz );
988 14 ▶ $self->set_time_zone( $target_tz ) if( defined( $target_tz ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $target_tz 13 1 14
989 # $self->set_time_zone( $target_tz )
990 # unless( !defined( $target_tz ) || $target_tz eq 'floating' );
991  
992 14 return( $self );
993 }
994  
995 sub from_object
996 48 ▶{
Subroutine from_object: called CC=31 SCAR=48.8
Pod documented
997 48 my $this = shift( @_ );
998 48 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0480
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
999 48 my %p = @_;
1000  
1001 48 my $object = delete( $p{object} );
1002 48 ▶ return( $class->error( "Parameter 'object' is required." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object 0 48 48
1003 unless( defined( $object ) );
1004 48 ▶ return( $class->error( "Parameter 'object' must be a blessed reference." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($object) 0 48 48
1005 unless( Scalar::Util::blessed( $object ) );
1006  
1007 # Pass through Infinite objects unchanged.
1008 # Accept both our own and the original DateTime::Infinite hierarchy.
1009 48 ▶ if( $object->isa( 'DateTime::Lite::Infinite' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($object->isa("DateTime::Lite::Infinite") or $object->can("is_infinite") and $object->is_infinite) 0 48 48
Condition50%3/6
$object->isa("DateTime::Lite::Infinite") or $object->can("is_infinite") and $object->is_infinite
l!l&&r!l&&!r
0048
$object->can("is_infinite") and $object->is_infinite
!ll&&!rl&&r
2460
MC/DC0%0/3
$object->isa("DateTime::Lite::Infinite") or $object->can("is_infinite") and $object->is_infinite
$object->isa("DateTime::Lite::Infinite") $object->can("is_infinite") $object->is_infinite
Truth table50%2/4
A or B and C
A= $object->isa("DateTime::Lite::Infinite")B= $object->can("is_infinite")C= $object->is_infinite
ABCresult
1XX1
0111
00X0
0100
1010 ( $object->can( 'is_infinite' ) && $object->is_infinite ) )
1011 {
1012 0 return( $object->clone );
1013 }
1014  
1015 48 my( $rd_days, $rd_secs, $rd_nanosecs ) = $object->utc_rd_values;
1016 48 ▶ $rd_nanosecs //= 0;
Condition50%1/2
$rd_nanosecs //= 0
l!l
480
MC/DC0%0/1
$rd_nanosecs //= 0
$rd_nanosecs
Truth table50%1/2
A
A= $rd_nanosecs
Aresult
11
00
1017  
1018 # Handle objects that happen to sit on a leap second
1019 48 my $leap_seconds = 0;
1020 48 ▶ if( $object->can( 'time_zone' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("time_zone") and not $object->time_zone->is_floating and $rd_secs > 86399 and $rd_secs <= $class->_day_length($rd_days)) 0 48 48
Condition55%5/9
$object->can("time_zone") and not $object->time_zone->is_floating and $rd_secs > 86399 and $rd_secs <= $class->_day_length($rd_days)
!ll&&!rl&&r
4800
$object->can("time_zone") and not $object->time_zone->is_floating and $rd_secs > 86399
!ll&&!rl&&r
1470
$object->can("time_zone") and not $object->time_zone->is_floating
!ll&&!rl&&r
0147
MC/DC0%0/4
$object->can("time_zone") and not $object->time_zone->is_floating and $rd_secs > 86399 and $rd_secs <= $class->_day_length($rd_days)
$object->can("time_zone") not $object->time_zone->is_floating $rd_secs > 86399 $rd_secs <= $class->_day_length($rd_days)
Truth table40%2/5
A and not(B) and C and D
A= $object->can("time_zone")B= not $object->time_zone->is_floatingC= $rd_secs > 86399D= $rd_secs <= $class->_day_length($rd_days)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1021 !$object->time_zone->is_floating &&
1022 $rd_secs > 86399 &&
1023 $rd_secs <= $class->_day_length( $rd_days ) )
1024 {
1025 0 $leap_seconds = $rd_secs - 86399;
1026 0 $rd_secs -= $leap_seconds;
1027 }
1028  
1029 48 my %args;
1030 48 @args{ qw( year month day ) } = $class->_rd2ymd( $rd_days );
1031 48 @args{ qw( hour minute second ) } = $class->_seconds_as_components( $rd_secs );
1032 48 $args{nanosecond} = $rd_nanosecs;
1033 48 $args{second} += $leap_seconds;
1034  
1035 # Build in UTC first (the RD values we extracted are UTC-based).
1036 # Strip any time_zone from %p here. We apply it explicitly below.
1037 48 my $target_tz = delete( $p{time_zone} );
1038  
1039 48 ▶ my $new = $class->new( %p, %args, time_zone => 'UTC' ) ||
Condition100%2/2
$class->new(%p, %args, 'time_zone', 'UTC') || (return $class->pass_error)
l!l
471
MC/DC100%1/1
$class->new(%p, %args, 'time_zone', 'UTC') || (return $class->pass_error)
$class->new(%p, %args, 'time_zone', 'UTC')
Truth table100%2/2
A
A= $class->new(%p, %args, 'time_zone', 'UTC')
Aresult
11
00
1040 return( $class->pass_error );
1041  
1042 # Apply timezone in priority order:
1043 # 1. Caller-supplied time_zone (from %p), or BCP47 -u-tz- from locale
1044 # 2. Source object's time_zone (if it has one)
1045 # 3. Default floating timezone
1046 47 my $resolved_tz = $class->_resolve_time_zone( $p{locale}, $target_tz );
1047 47 ▶ if( defined( $resolved_tz ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $resolved_tz) { } 3 44 47
elsif ($object->can('time_zone')) { } 44 0 44
1048 {
1049 3 ▶ $new->set_time_zone( $resolved_tz ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_time_zone($resolved_tz) or return $this->pass_error 3 0 3
1050 return( $this->pass_error );
1051 }
1052 elsif( $object->can( 'time_zone' ) )
1053 {
1054 44 my $tz = $object->time_zone;
1055 44 ▶ if( $tz )
Branch: 1 branch
BranchTrueFalseTotal
if ($tz) 44 0 44
1056 {
1057 44 ▶ if( Scalar::Util::blessed( $tz ) && $tz->isa( 'DateTime::Lite::TimeZone' ) )
Branch: 4 branches
BranchTrueFalseTotal
if (builtin::blessed($tz) and $tz->isa('DateTime::Lite::TimeZone')) { } 44 0 44
elsif (builtin::blessed($tz) and $tz->can('name')) { } 0 0 0
elsif (builtin::blessed($tz) and overload::Method($tz, '""')) { } 0 0 0
elsif (ref $tz) { } 0 0 0
Condition33%1/3
builtin::blessed($tz) and $tz->isa("DateTime::Lite::TimeZone")
!ll&&!rl&&r
0044
MC/DC0%0/2
builtin::blessed($tz) and $tz->isa("DateTime::Lite::TimeZone")
builtin::blessed($tz) $tz->isa("DateTime::Lite::TimeZone")
Truth table33%1/3
A and B
A= builtin::blessed($tz)B= $tz->isa("DateTime::Lite::TimeZone")
ABresult
0X0
100
111
1058 {
1059 44 ▶ $new->set_time_zone( $object->time_zone ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_time_zone($object->time_zone) or return $this->pass_error($new->error) 44 0 44
1060 return( $this->pass_error( $new->error ) );
1061 }
1062 ▶ elsif( Scalar::Util::blessed( $tz ) && $tz->can( 'name' ) )
Condition0%0/3
builtin::blessed($tz) and $tz->can("name")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($tz) and $tz->can("name")
builtin::blessed($tz) $tz->can("name")
Truth table0%0/3
A and B
A= builtin::blessed($tz)B= $tz->can("name")
ABresult
0X0
100
111
1063 {
1064 0 ▶ $new->set_time_zone( $tz->name ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_time_zone($tz->name) or return $this->pass_error($new->error) 0 0 0
1065 return( $this->pass_error( $new->error ) );
1066 }
1067 ▶ elsif( Scalar::Util::blessed( $tz ) && overload::Method( $tz => '""' ) )
Condition0%0/3
builtin::blessed($tz) and overload::Method($tz, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($tz) and overload::Method($tz, "\"\"")
builtin::blessed($tz) overload::Method($tz, "\"\"")
Truth table0%0/3
A and B
A= builtin::blessed($tz)B= overload::Method($tz, "\"\"")
ABresult
0X0
100
111
1068 {
1069 0 ▶ $new->set_time_zone( "$tz" ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_time_zone("$tz") or return $this->pass_error($new->error) 0 0 0
1070 return( $this->pass_error( $new->error ) );
1071 }
1072 elsif( ref( $tz ) )
1073 {
1074 0 return( $this->error( "Unsupported value for time_zone: $tz" ) );
1075 }
1076 else
1077 {
1078 0 ▶ $new->set_time_zone( "$tz" ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_time_zone("$tz") or return $this->pass_error($new->error) 0 0 0
1079 return( $this->pass_error( $new->error ) );
1080 }
1081 }
1082 }
1083 else
1084 {
1085 0 ▶ $new->set_time_zone( $class->_default_time_zone ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_time_zone($class->_default_time_zone) or return $this->pass_error($new->error) 0 0 0
1086 return( $this->pass_error( $new->error ) );
1087 }
1088  
1089 47 ▶ if( $object->can( 'formatter' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("formatter")) 45 2 47
1090 {
1091 45 my $formatter = $object->formatter;
1092 45 ▶ $new->set_formatter( $formatter ) ||
Branch: 1 branch
BranchTrueFalseTotal
$new->set_formatter($formatter) or return $this->pass_error($new->error) 45 0 45
1093 return( $this->pass_error( $new->error ) );
1094 }
1095  
1096 47 return( $new );
1097 }
1098  
1099 sub hires_epoch
1100 1 ▶{
Subroutine hires_epoch: called CC=2 SCAR=7.0
Pod documented
1101 1 my $self = shift( @_ );
1102 1 my $epoch = $self->epoch;
1103 1 ▶ return( undef ) unless( defined( $epoch ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $epoch 0 1 1
1104 1 return( $epoch + $self->{rd_nanosecs} / MAX_NANOSECONDS );
1105 }
1106  
1107 sub hms
1108 21 ▶{
Subroutine hms: called CC=2 SCAR=6.9
Pod documented
1109 21 my $self = shift( @_ );
1110 21 ▶ my $sep = defined( $_[0] ) ? shift( @_ ) : ':';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 17 4 21
1111 21 return( sprintf( "%02d%s%02d%s%02d",
1112 $self->hour, $sep, $self->minute, $sep, $self->second ) );
1113 }
1114  
1115 130 ▶sub hour { return( shift->{local_c}->{hour} ); }
Subroutine hour: called CC=1 SCAR=0.0
Pod documented
1116  
1117 # NOTE: hour_1 is autoloaded
1118  
1119 # NOTE: hour_12 is autoloaded
1120  
1121 # NOTE: hour_12_0 is autoloaded
1122  
1123 sub is_between
1124 2 ▶{
Subroutine is_between: called CC=2 SCAR=7.0
Pod documented
1125 2 my $self = shift( @_ );
1126 2 my $lower = shift( @_ );
1127 2 my $upper = shift( @_ );
1128 2 ▶ return( $self->compare( $lower ) > 0 && $self->compare( $upper ) < 0 );
Condition66%2/3
$self->compare($lower) > 0 && $self->compare($upper) < 0
!ll&&!rl&&r
101
MC/DC50%1/2
$self->compare($lower) > 0 && $self->compare($upper) < 0
$self->compare($lower) > 0 $self->compare($upper) < 0
Truth table66%2/3
A && B
A= $self->compare($lower) > 0B= $self->compare($upper) < 0
ABresult
0X0
100
111
1129 }
1130  
1131 sub is_dst
1132 2 ▶{
Subroutine is_dst: called CC=5 SCAR=20.2
Pod documented
1133 2 ▶ if( !scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @_) 0 2 2
1134 {
1135 0 die( 'Usage: $dt->is_dst' );
1136 }
1137 2 my $self = shift( @_ );
1138 2 ▶ if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and builtin::blessed($self // "")) 0 2 2
Condition40%2/5
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
002
$self // ""
l!l
20
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
1139 {
1140 0 die( 'Usage: $dt->is_dst' );
1141 }
1142 2 return( $self->{tz}->is_dst_for_datetime( $self ) );
1143 }
1144  
1145 2 ▶sub is_finite {1}
Subroutine is_finite: called CC=1 SCAR=0.0
Pod documented
1146  
1147 sub is_future
1148 0 ▶{
Subroutine is_future: not called CC=1 SCAR=6.9
Pod documented
1149 0 my $self = shift( @_ );
1150 0 return( $self->compare( DateTime::Lite->now ) > 0 );
1151 }
1152  
1153 137 ▶sub is_infinite {0}
Subroutine is_infinite: called CC=1 SCAR=0.0
Pod documented
1154  
1155 # NOTE: sub is_last_day_of_month is autoloaded
1156  
1157 # NOTE: sub is_last_day_of_quarter is autoloaded
1158  
1159 # NOTE: sub is_last_day_of_year is autoloaded
1160  
1161 sub is_leap_year
1162 6 ▶{
Subroutine is_leap_year: called CC=5 SCAR=20.2
Pod documented
1163 6 ▶ if( !scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @_) 0 6 6
1164 {
1165 0 die( 'Usage: $dt->is_dst' );
1166 }
1167 6 my $self = shift( @_ );
1168 6 ▶ if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and builtin::blessed($self // "")) 0 6 6
Condition40%2/5
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
006
$self // ""
l!l
60
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
1169 {
1170 0 die( 'Usage: $dt->is_dst' );
1171 }
1172 6 return( $self->_is_leap_year( $self->year ) );
1173 }
1174  
1175 sub is_past
1176 0 ▶{
Subroutine is_past: not called CC=1 SCAR=6.9
Pod documented
1177 0 my $self = shift( @_ );
1178 0 return( $self->compare( DateTime::Lite->now ) < 0 );
1179 }
1180  
1181 11 ▶sub iso8601 { $_[0]->datetime( 'T' ) }
Subroutine iso8601: called CC=1 SCAR=0.0
Pod documented
1182  
1183 # NOTE: sub jd is autoloaded
1184  
1185 sub last_day_of_month
1186 4 ▶{
Subroutine last_day_of_month: called CC=4 SCAR=14.8
Pod documented
1187 4 my $this = shift( @_ );
1188 4 ▶ my $class = ref( $this ) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1189 4 my %p = @_;
1190  
1191 return( $class->error( "Parameter 'year' is required." ) )
1192 4 ▶ unless( exists( $p{year} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"year"} 0 4 4
1193 return( $class->error( "Parameter 'month' is required." ) )
1194 4 ▶ unless( exists( $p{month} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"month"} 0 4 4
1195  
1196 4 my $day = $class->_month_length( $p{year}, $p{month} );
1197 4 return( $class->_new( %p, day => $day ) );
1198 }
1199  
1200 # NOTE: sub leap_seconds is autoloaded
1201  
1202 # NOTE: sub local_day_of_week is autoloaded
1203  
1204 sub local_rd_as_seconds
1205 74 ▶{
Subroutine local_rd_as_seconds: called CC=1 SCAR=0.0
Pod documented
1206 74 my $self = shift( @_ );
1207 74 return( $self->{local_rd_days} * SECONDS_PER_DAY + $self->{local_rd_secs} );
1208 }
1209  
1210 sub local_rd_values
1211 3 ▶{
Subroutine local_rd_values: called CC=1 SCAR=0.0
Pod documented
1212 3 my $self = shift( @_ );
1213 3 return( $self->{local_rd_days}, $self->{local_rd_secs}, $self->{rd_nanosecs} );
1214 }
1215  
1216 41 ▶sub locale { return( shift->{locale} ) }
Subroutine locale: called CC=1 SCAR=0.0
Pod documented
1217  
1218 # NOTE: sub mdy is autoloaded
1219  
1220 # NOTE: sub microsecond is autoloaded
1221  
1222 # NOTE: sub millisecond is autoloaded
1223  
1224 107 ▶sub minute { return( shift->{local_c}->{minute} ) }
Subroutine minute: called CC=1 SCAR=0.0
Pod documented
1225  
1226 # NOTE: sub mjd is autoloaded
1227  
1228 143 ▶sub month { return( shift->{local_c}->{month} ) }
Subroutine month: called CC=1 SCAR=0.0
Pod documented
1229  
1230 {
1231 16 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1232 16 *mon = \&month;
1233 }
1234  
1235 # NOTE: sub month_0 is autoloaded
1236  
1237 {
1238 16 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1239 16 *mon_0 = \&month_0;
1240 }
1241  
1242 sub month_abbr
1243 4 ▶{
Subroutine month_abbr: called CC=1 SCAR=0.0
Pod documented
1244 4 my $self = shift( @_ );
1245 4 return( $self->{locale}->month_format_abbreviated->[ $self->month_0 ] );
1246 }
1247  
1248 # NOTE: month_length is autoloaded
1249  
1250 sub month_name
1251 5 ▶{
Subroutine month_name: called CC=1 SCAR=0.0
Pod documented
1252 5 my $self = shift( @_ );
1253 5 return( $self->{locale}->month_format_wide->[ $self->month_0 ] );
1254 }
1255  
1256 66 ▶sub nanosecond { return( $_[0]->{rd_nanosecs} ) }
Subroutine nanosecond: called CC=1 SCAR=0.0
Pod documented
1257  
1258 sub now
1259 9 ▶{
Subroutine now: called CC=1 SCAR=0.0
Pod documented
1260 9 my $class = shift( @_ );
1261 9 return( $class->from_epoch( epoch => $class->_core_time, @_ ) );
1262 }
1263  
1264 70 ▶sub offset { $_[0]->{tz}->offset_for_datetime( $_[0] ) }
Subroutine offset: called CC=1 SCAR=0.0
Pod documented
1265  
1266 sub pass_error
1267 3 ▶{
Subroutine pass_error: called CC=37 SCAR=61.3
Pod documented
1268 3 my $self = shift( @_ );
1269 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
1270 3 my $opts = {};
1271 3 my( $err, $class, $code );
1272 16 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1273 3 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 3 3
1274 {
1275 # Either an hash defining a new error and this will be passed along to error(); or
1276 # an hash with a single property: { class => 'Some::ExceptionClass' }
1277 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
1278 {
1279 0 $opts = $_[0];
1280 }
1281 else
1282 {
1283 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
1284 {
1285 0 $opts = pop( @_ );
1286 }
1287 0 $err = $_[0];
1288 }
1289 }
1290 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
1291 # We set $class only if the hash provided is a one-element hash and not an error-defining hash
1292 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
1293 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
1294  
1295 # called with no argument, most likely from the same class to pass on an error
1296 # set up earlier by another method; or
1297 # with an hash containing just one argument class => 'Some::ExceptionClass'
1298 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
1299 {
1300 # $error is a previous erro robject
1301 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
1302 3 ▶ if( !defined( $error ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $error) { } 0 3 3
1303 {
1304 0 warn( "No error object provided and no previous error set either! It seems the previous method call returned a simple undef" );
1305 }
1306 else
1307 {
1308 3 ▶ $err = ( defined( $class ) ? bless( $error => $class ) : $error );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 3 3
1309 3 ▶ $err->code( $code ) if( defined( $code ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 0 3 3
1310 }
1311 }
1312 ▶ 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
1313 Scalar::Util::blessed( $err ) &&
1314 ( scalar( @_ ) == 1 ||
1315 ( scalar( @_ ) == 2 && defined( $class ) )
1316 ) )
1317 {
1318 0 ▶ $self->{error} = ${ $pack . '::ERROR' } = ( defined( $class ) ? bless( $err => $class ) : $err );
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 0 0 0
1319 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
1320  
1321 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
1322 {
1323 0 die( $self->{error} );
1324 }
1325 }
1326 # If the error provided is not an object, we call error to create one
1327 else
1328 {
1329 0 return( $self->error( @_ ) );
1330 }
1331  
1332 3 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 3 3
1333 {
1334 0 rreturn( DateTime::Lite::NullObject->new );
1335 }
1336 3 return;
1337 }
1338  
1339 3 ▶sub quarter { $_[0]->{local_c}->{quarter} }
Subroutine quarter: called CC=1 SCAR=0.0
Pod documented
1340  
1341 # NOTE: quarter_0 is autoloaded
1342  
1343 # NOTE: quarter_abbr is autoloaded
1344  
1345 # NOTE: quarter_length is autoloaded
1346  
1347 # NOTE: quarter_name is autoloaded
1348  
1349 sub rfc3339
1350 1 ▶{
Subroutine rfc3339: called CC=2 SCAR=7.2
Pod documented
1351 1 my $self = shift( @_ );
1352 1 my $str = $self->datetime( 'T' );
1353 1 ▶ if( $self->{tz}->is_utc )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tz'}->is_utc) { } 1 0 1
1354 {
1355 1 $str .= 'Z';
1356 }
1357 else
1358 {
1359 0 $str .= DateTime::Lite::TimeZone->offset_as_string( $self->offset, ':' );
1360 }
1361 1 return( $str );
1362 }
1363  
1364 # NOTE: secular_era is autoloaded
1365  
1366 157 ▶sub second { return( shift->{local_c}->{second} ) }
Subroutine second: called CC=1 SCAR=0.0
Pod documented
1367  
1368 # NOTE: Setters
1369 sub set
1370 8 ▶{
Subroutine set: called CC=4 SCAR=15.9
Pod documented
1371 8 my $self = shift( @_ );
1372 8 my %p = @_;
1373  
1374 8 ▶ if( $p{locale} )
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"locale"}) 0 8 8
1375 {
1376 0 ▶ warn( 'You passed a locale to the set() method. Use set_locale() instead.' )
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
1377 if( warnings::enabled() );
1378 }
1379  
1380 8 ▶ my $new_dt = $self->_new_from_self( %p ) ||
Condition50%1/2
$self->_new_from_self(%p) || (return $self->pass_error)
l!l
80
MC/DC0%0/1
$self->_new_from_self(%p) || (return $self->pass_error)
$self->_new_from_self(%p)
Truth table50%1/2
A
A= $self->_new_from_self(%p)
Aresult
11
00
1381 return( $self->pass_error );
1382 8 %$self = %$new_dt;
1383 8 return( $self );
1384 }
1385  
1386 1 ▶sub set_day { return( shift->set( day => @_ ) ); }
Subroutine set_day: called CC=1 SCAR=0.0
Pod documented
1387  
1388 sub set_formatter
1389 48 ▶{
Subroutine set_formatter: called CC=5 SCAR=19.1
Pod documented
1390 48 my $self = shift( @_ );
1391 48 my $formatter = shift( @_ );
1392 #
1393 48 ▶ if( defined( $formatter ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $formatter) 2 46 48
1394 {
1395 2 ▶ if( !Scalar::Util::blessed( $formatter ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($formatter)) { } 0 2 2
elsif (not $formatter->can('format_datetime')) { } 0 2 2
1396 {
1397 0 return( $self->error( "Formatter must be a blessed object." ) );
1398 }
1399 elsif( !$formatter->can( 'format_datetime' ) )
1400 {
1401 0 ▶ return( $self->error( "Formatter provided (", ( ref( $formatter ) || $formatter ), ") does not support the format_datetime() method." ) )
Condition0%0/3
ref $formatter || $formatter
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $formatter || $formatter
ref $formatter $formatter
Truth table0%0/3
A || B
A= ref $formatterB= $formatter
ABresult
1X1
011
000
1402 }
1403 }
1404 48 $self->{formatter} = $formatter;
1405 48 return( $self );
1406 }
1407  
1408 1 ▶sub set_hour { return( shift->set( hour => @_ ) ); }
Subroutine set_hour: called CC=1 SCAR=0.0
Pod documented
1409  
1410 sub set_locale
1411 3 ▶{
Subroutine set_locale: called CC=4 SCAR=14.0
Pod documented
1412 3 my $self = shift( @_ );
1413 3 my $locale = shift( @_ );
1414 3 ▶ $self->_set_locale( $locale ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_set_locale($locale) or return $self->pass_error 3 0 3
1415 # If the new locale carries a BCP47 -u-tz- extension and the object is
1416 # currently in the floating timezone (i.e. no explicit timezone was ever
1417 # set), infer the timezone from the locale extension.
1418 3 ▶ if( $self->{tz}->is_floating )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tz"}->is_floating) 1 2 3
1419 {
1420 1 my $resolved = $self->_resolve_time_zone( $locale, undef );
1421 1 ▶ $self->set_time_zone( $resolved ) if( defined( $resolved ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $resolved 1 0 1
1422 }
1423 3 return( $self );
1424 }
1425  
1426 1 ▶sub set_minute { return( shift->set( minute => @_ ) ); }
Subroutine set_minute: called CC=1 SCAR=0.0
Pod documented
1427 1 ▶sub set_month { return( shift->set( month => @_ ) ); }
Subroutine set_month: called CC=1 SCAR=0.0
Pod documented
1428 1 ▶sub set_nanosecond { return( shift->set( nanosecond => @_ ) ); }
Subroutine set_nanosecond: called CC=1 SCAR=0.0
Pod documented
1429 1 ▶sub set_second { return( shift->set( second => @_ ) ); }
Subroutine set_second: called CC=1 SCAR=0.0
Pod documented
1430  
1431 sub set_time_zone
1432 64 ▶{
Subroutine set_time_zone: called CC=16 SCAR=31.3
Pod documented
1433 64 my( $self, $tz ) = @_;
1434  
1435 # If a hash reference is passed, resolve it to a DateTime::Lite::TimeZone object
1436 # first, allowing options such as 'extended' set to true or latitude/longitude.
1437 64 ▶ if( defined( $tz ) && ref( $tz ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz and ref $tz eq "HASH") 0 64 64
Condition33%1/3
defined $tz and ref $tz eq "HASH"
!ll&&!rl&&r
0640
MC/DC0%0/2
defined $tz and ref $tz eq "HASH"
defined $tz ref $tz eq "HASH"
Truth table33%1/3
A and B
A= defined $tzB= ref $tz eq "HASH"
ABresult
0X0
100
111
1438 {
1439 0 ▶ $tz = DateTime::Lite::TimeZone->new( %$tz ) ||
Condition0%0/2
'DateTime::Lite::TimeZone'->new(%$tz) || (return $self->pass_error('DateTime::Lite::TimeZone'->error))
l!l
00
MC/DC0%0/1
'DateTime::Lite::TimeZone'->new(%$tz) || (return $self->pass_error('DateTime::Lite::TimeZone'->error))
'DateTime::Lite::TimeZone'->new(%$tz)
Truth table0%0/2
A
A= 'DateTime::Lite::TimeZone'->new(%$tz)
Aresult
11
00
1440 return( $self->pass_error( DateTime::Lite::TimeZone->error ) );
1441 }
1442  
1443 64 ▶ if( Scalar::Util::blessed( $tz ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($tz) and $tz->isa('DateTime::Lite::TimeZone')) { } 46 18 64
elsif (not ref $tz) { } 18 0 18
Condition66%2/3
builtin::blessed($tz) and $tz->isa("DateTime::Lite::TimeZone")
!ll&&!rl&&r
18046
MC/DC50%1/2
builtin::blessed($tz) and $tz->isa("DateTime::Lite::TimeZone")
builtin::blessed($tz) $tz->isa("DateTime::Lite::TimeZone")
Truth table66%2/3
A and B
A= builtin::blessed($tz)B= $tz->isa("DateTime::Lite::TimeZone")
ABresult
0X0
100
111
1444 $tz->isa( 'DateTime::Lite::TimeZone' ) )
1445 {
1446 46 ▶ return( $self ) if( $self->{tz} eq $tz );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tz"} eq $tz 39 7 46
1447 }
1448 elsif( !ref( $tz ) )
1449 {
1450 18 ▶ return( $self ) if( $self->{tz}->name eq $tz );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tz"}->name eq $tz 8 10 18
1451 }
1452 else
1453 {
1454 0 return( $self->error( "time_zone must be a string, a hash reference, or a DateTime::Lite::TimeZone object, got " . ref( $tz ) ) );
1455 }
1456  
1457 17 my $was_floating = $self->{tz}->is_floating;
1458 17 my $old_tz = $self->{tz};
1459 17 ▶ if( Scalar::Util::blessed( $tz ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($tz) and $tz->isa('DateTime::Lite::TimeZone')) { } 7 10 17
Condition66%2/3
builtin::blessed($tz) and $tz->isa("DateTime::Lite::TimeZone")
!ll&&!rl&&r
1007
MC/DC50%1/2
builtin::blessed($tz) and $tz->isa("DateTime::Lite::TimeZone")
builtin::blessed($tz) $tz->isa("DateTime::Lite::TimeZone")
Truth table66%2/3
A and B
A= builtin::blessed($tz)B= $tz->isa("DateTime::Lite::TimeZone")
ABresult
0X0
100
111
1460 $tz->isa( 'DateTime::Lite::TimeZone' ) )
1461 {
1462 7 $self->{tz} = $tz;
1463 }
1464 else
1465 {
1466 10 $self->{tz} = DateTime::Lite::TimeZone->new( name => $tz );
1467 10 ▶ unless( $self->{tz} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tz"}) 0 10 10
1468 {
1469 0 $self->{tz} = $old_tz;
1470 0 return( $self->pass_error( DateTime::Lite::TimeZone->error ) );
1471 }
1472 }
1473  
1474 17 $self->_handle_offset_modifier( $self->second, 1 );
1475  
1476 eval
1477 17 {
1478 17 ▶ if( $self->{tz}->is_floating xor $was_floating )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'tz'}->is_floating xor $was_floating) { } 2 15 17
elsif (not $was_floating) { } 15 0 15
Condition75%3/4
$self->{"tz"}->is_floating xor $was_floating
l&&rl&&!r!l&&r!l&&!r
01115
MC/DC100%2/2
$self->{"tz"}->is_floating xor $was_floating
$self->{"tz"}->is_floating $was_floating
Truth table75%3/4
A xor B
A= $self->{"tz"}->is_floatingB= $was_floating
ABresult
110
101
011
000
1479 {
1480 2 $self->_calc_utc_rd;
1481 }
1482 elsif( !$was_floating )
1483 {
1484 15 $self->_calc_local_rd;
1485 }
1486 };
1487 17 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 17 17
1488 {
1489 # Restore old timezone and re-throw; RT #83940
1490 0 $self->{tz} = $old_tz;
1491 0 die( $@ );
1492 }
1493  
1494 # Invalidate memoised values that depend on local time or epoch
1495 17 delete( $self->{utc_c} );
1496  
1497 17 return( $self );
1498 }
1499  
1500 1 ▶sub set_year { $_[0]->set( year => $_[1] ) }
Subroutine set_year: called CC=1 SCAR=0.0
Pod documented
1501  
1502 # See also end_of()
1503 sub start_of
1504 24 ▶{
Subroutine start_of: called CC=7 SCAR=19.5
Pod documented
1505 24 my $self = shift( @_ );
1506 24 ▶ my $unit = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error(q[Parameter 'unit' is required for start_of().]))
l!l
240
MC/DC0%0/1
shift @_ || (return $self->error(q[Parameter 'unit' is required for start_of().]))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1507 return( $self->error( "Parameter 'unit' is required for start_of()." ) );
1508  
1509 # Most units map directly to truncate(), which already handles
1510 # year, quarter, month, week, local_week, day, hour, minute, second.
1511 # We handle decade and century ourselves.
1512 24 ▶ if( $unit eq 'decade' )
Branch: 2 branches
BranchTrueFalseTotal
if ($unit eq 'decade') { } 2 22 24
elsif ($unit eq 'century') { } 2 20 22
1513 {
1514 2 my $decade_year = int( $self->year / 10 ) * 10;
1515 2 ▶ my $new_dt = $self->_new_from_self(
Condition50%1/2
$self->_new_from_self('year', $decade_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->_new_from_self('year', $decade_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1) || (return $self->pass_error)
$self->_new_from_self('year', $decade_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1)
Truth table50%1/2
A
A= $self->_new_from_self('year', $decade_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1)
Aresult
11
00
1516 year => $decade_year,
1517 month => 1,
1518 day => 1,
1519 hour => 0,
1520 minute => 0,
1521 second => 0,
1522 nanosecond => 0,
1523 _skip_validation => 1,
1524 ) || return( $self->pass_error );
1525 2 %$self = %$new_dt;
1526 2 return( $self );
1527 }
1528 elsif( $unit eq 'century' )
1529 {
1530 # Century: year 1-100 -> year 1, year 101-200 -> year 101, etc.
1531 2 my $century_year = ( int( ( $self->year - 1 ) / 100 ) * 100 ) + 1;
1532 2 ▶ my $new_dt = $self->_new_from_self(
Condition50%1/2
$self->_new_from_self('year', $century_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->_new_from_self('year', $century_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1) || (return $self->pass_error)
$self->_new_from_self('year', $century_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1)
Truth table50%1/2
A
A= $self->_new_from_self('year', $century_year, 'month', 1, 'day', 1, 'hour', 0, 'minute', 0, 'second', 0, 'nanosecond', 0, '_skip_validation', 1)
Aresult
11
00
1533 year => $century_year,
1534 month => 1,
1535 day => 1,
1536 hour => 0,
1537 minute => 0,
1538 second => 0,
1539 nanosecond => 0,
1540 _skip_validation => 1,
1541 ) || return( $self->pass_error );
1542 2 %$self = %$new_dt;
1543 2 return( $self );
1544 }
1545 else
1546 {
1547 20 my %valid = map{ $_ => 1 } qw(
1548 year quarter month week local_week day hour minute second
1549 );
1550 20 ▶ unless( $valid{ $unit } )
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid{$unit}) 1 19 20
1551 {
1552 1 return( $self->error( "Invalid unit '$unit' for start_of()." ) );
1553 }
1554 19 return( $self->truncate( to => $unit ) );
1555 }
1556 }
1557  
1558 # NOTE: strftime
1559 {
1560 16 my %strftime_patterns;
1561  
1562 %strftime_patterns = (
1563 1 ▶ 'a' => sub{ $_[0]->day_abbr },
Subroutine __ANON__: called CC=1 SCAR=0.0
1564 3 ▶ 'A' => sub{ $_[0]->day_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
1565 1 ▶ 'b' => sub{ $_[0]->month_abbr },
Subroutine __ANON__: called CC=1 SCAR=0.0
1566 3 ▶ 'B' => sub{ $_[0]->month_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
1567 0 ▶ 'c' => sub{ $_[0]->strftime( '%a %b %e %H:%M:%S %Y' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1568 1 ▶ 'C' => sub{ int( $_[0]->year / 100 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1569 5 ▶ 'd' => sub{ sprintf( '%02d', $_[0]->day ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1570 1 ▶ 'D' => sub{ $_[0]->strftime( '%m/%d/%y' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1571 1 ▶ 'E' => sub{ $_[0]->day_abbr },
Subroutine __ANON__: called CC=1 SCAR=0.0
1572 1 ▶ 'e' => sub{ sprintf( '%2d', $_[0]->day ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1573 3 ▶ 'F' => sub{ $_[0]->ymd( '-' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1574 1 ▶ 'G' => sub{ $_[0]->week_year },
Subroutine __ANON__: called CC=1 SCAR=0.0
1575 1 ▶ 'g' => sub{ sprintf( '%02d', $_[0]->week_year % 100 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1576 8 ▶ 'H' => sub{ sprintf( '%02d', $_[0]->hour ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1577 1 ▶ 'h' => sub{ $_[0]->month_abbr },
Subroutine __ANON__: called CC=1 SCAR=0.0
1578 4 ▶ 'I' => sub{ sprintf( '%02d', $_[0]->hour_12 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1579 2 ▶ 'j' => sub{ sprintf( '%03d', $_[0]->day_of_year ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1580 1 ▶ 'k' => sub{ sprintf( '%2d', $_[0]->hour ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1581 1 ▶ 'l' => sub{ sprintf( '%2d', $_[0]->hour_12 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1582 4 ▶ 'm' => sub{ sprintf( '%02d', $_[0]->month ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1583 9 ▶ 'M' => sub{ sprintf( '%02d', $_[0]->minute ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1584 2 ▶ 'n' => sub{ "\n" },
Subroutine __ANON__: called CC=1 SCAR=0.0
1585 5 ▶ 'N' => sub{ $_[0]->_format_nanosecs( defined( $_[1] ) ? $_[1] : 9 ) },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 4 1 5
1586 1 ▶ 'O' => sub{ $_[0]->time_zone->name },
Subroutine __ANON__: called CC=1 SCAR=0.0
1587 4 ▶ 'p' => sub{ $_[0]->am_or_pm },
Subroutine __ANON__: called CC=1 SCAR=0.0
1588 1 ▶ 'P' => sub{ lc( $_[0]->am_or_pm ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1589 1 ▶ 'r' => sub{ $_[0]->strftime( '%I:%M:%S %p' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1590 1 ▶ 'R' => sub{ $_[0]->strftime( '%H:%M' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1591 2 ▶ 's' => sub{ $_[0]->epoch },
Subroutine __ANON__: called CC=1 SCAR=0.0
1592 8 ▶ 'S' => sub{ sprintf( '%02d', $_[0]->second ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1593 2 ▶ 't' => sub{ "\t" },
Subroutine __ANON__: called CC=1 SCAR=0.0
1594 4 ▶ 'T' => sub{ $_[0]->strftime( '%H:%M:%S' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1595 2 ▶ 'u' => sub{ $_[0]->day_of_week },
Subroutine __ANON__: called CC=1 SCAR=0.0
1596 1 ▶ 'U' => sub{ sprintf( '%02d', int( ( $_[0]->day_of_year - $_[0]->day_of_week_0 + 6 ) / 7 ) ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1597 2 ▶ 'V' => sub{ sprintf( '%02d', $_[0]->week_number ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1598 1 ▶ 'w' => sub{ $_[0]->day_of_week % 7 },
Subroutine __ANON__: called CC=1 SCAR=0.0
1599 1 ▶ 'W' => sub{ sprintf( '%02d', int( ( $_[0]->day_of_year - ( $_[0]->day_of_week - 1 ) + 6 ) / 7 ) ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1600 0 ▶ 'x' => sub{ $_[0]->strftime( '%m/%d/%y' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1601 0 ▶ 'X' => sub{ $_[0]->strftime( '%H:%M:%S' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1602 2 ▶ 'y' => sub{ sprintf( '%02d', $_[0]->year % 100 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1603 4 ▶ 'Y' => sub{ sprintf( '%04d', $_[0]->year ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1604 1 ▶ 'z' => sub{ DateTime::Lite::TimeZone->offset_as_string( $_[0]->offset ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1605 3 ▶ ':z' => sub{ DateTime::Lite::TimeZone->offset_as_string( $_[0]->offset, ':' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1606 3 ▶ 'Z' => sub{ $_[0]->time_zone_short_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
1607 2 ▶ '%' => sub{ '%' },
Subroutine __ANON__: called CC=1 SCAR=0.0
1608 16 );
1609  
1610 sub strftime
1611 79 ▶ {
Subroutine strftime: called CC=10 SCAR=25.0
Pod documented
1612 79 my $self = shift( @_ );
1613 79 my @patterns = @_;
1614  
1615 79 my @r;
1616 79 foreach my $p ( @patterns )
1617 {
1618 79 $p =~ s/
1619 (?:
1620 %\{(\w+)\} # method name like %{day_name}
1621 |
1622 %([%a-zA-Z]) # single character specifier like %d
1623 |
1624 %(\d+)N # special case for %N
1625 |
1626 %(:z) # extended specifier like %:z
1627 )
1628 /
1629 ( $1
1630 ? ( $self->can($1) ? $self->$1() : "\%{$1}" )
1631 : $2
1632 ? ( $strftime_patterns{$2} ? $strftime_patterns{$2}->($self) : "\%$2" )
1633 : $3
1634 ? $strftime_patterns{N}->($self, $3)
1635 : $4
1636 108 ▶ ? ( $strftime_patterns{$4} ? $strftime_patterns{$4}->($self) : "\%$4" )
Branch: 7 branches
BranchTrueFalseTotal
$1 ? : 3 105 108
$self->can($1) ? : 3 0 3
$2 ? : 98 7 105
$strftime_patterns{$2} ? : 98 0 98
$3 ? : 4 3 7
$4 ? : 3 0 3
$strftime_patterns{$4} ? : 3 0 3
1637 : ''
1638 )
1639 /sgex;
1640  
1641 79 ▶ return( $p ) unless( wantarray );
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 79 0 79
1642 0 push( @r, $p );
1643 }
1644 0 return( @r );
1645 }
1646 }
1647  
1648 sub stringify
1649 16 ▶{
Subroutine stringify: called CC=2 SCAR=6.9
Pod documented
1650 11 my $self = shift( @_ );
1651 return( $self->{formatter}->format_datetime( $self ) )
1652 11 ▶ if( defined( $self->{formatter} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"formatter"} 2 9 11
1653 9 return( $self->iso8601 );
1654 }
1655  
1656 sub subtract
1657 13 ▶{
Subroutine subtract: called CC=3 SCAR=11.2
Pod documented
1658 13 my $self = shift( @_ );
1659 13 my %eom;
1660 13 ▶ if( @_ % 2 == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 0) 13 0 13
1661 {
1662 13 my %p = @_;
1663 13 ▶ $eom{end_of_month} = delete( $p{end_of_month} ) if( exists( $p{end_of_month} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $p{"end_of_month"} 0 13 13
1664 }
1665 13 my $dur = $self->_duration_object_from_args( @_ )->inverse( %eom );
1666 13 return( $self->add_duration( $dur ) );
1667 }
1668  
1669 1 ▶sub subtract_duration { return( $_[0]->add_duration( $_[1]->inverse ) ) }
Subroutine subtract_duration: called CC=1 SCAR=0.0
Pod documented
1670  
1671 sub subtract_datetime
1672 3 ▶{
Subroutine subtract_datetime: called CC=16 SCAR=42.9
Pod documented
1673 3 my $dt1 = shift( @_ );
1674 3 my $dt2 = shift( @_ );
1675  
1676 3 ▶ $dt2 = $dt2->clone->set_time_zone( $dt1->time_zone )
Branch: 1 branch
BranchTrueFalseTotal
unless $dt1->time_zone eq $dt2->time_zone 0 3 3
1677 unless( $dt1->time_zone eq $dt2->time_zone );
1678  
1679 3 ▶ my( $bigger, $smaller, $negative ) = (
Branch: 1 branch
BranchTrueFalseTotal
$dt1 >= $dt2 ? : 3 0 3
1680 $dt1 >= $dt2
1681 ? ( $dt1, $dt2, 0 )
1682 : ( $dt2, $dt1, 1 )
1683 );
1684  
1685 3 ▶ my $is_floating = $dt1->time_zone->is_floating &&
Condition33%1/3
$dt1->time_zone->is_floating && $dt2->time_zone->is_floating
!ll&&!rl&&r
300
MC/DC0%0/2
$dt1->time_zone->is_floating && $dt2->time_zone->is_floating
$dt1->time_zone->is_floating $dt2->time_zone->is_floating
Truth table33%1/3
A && B
A= $dt1->time_zone->is_floatingB= $dt2->time_zone->is_floating
ABresult
0X0
100
111
1686 $dt2->time_zone->is_floating;
1687  
1688 3 my $minute_length = 60;
1689 3 ▶ unless( $is_floating )
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_floating) 3 0 3
1690 {
1691 3 my( $utc_rd_days, $utc_rd_secs ) = $smaller->utc_rd_values;
1692 3 ▶ if( $utc_rd_secs >= 86340 )
Branch: 1 branch
BranchTrueFalseTotal
if ($utc_rd_secs >= 86340) 0 3 3
1693 {
1694 0 $minute_length = $dt1->_day_length( $utc_rd_days ) - 86340;
1695 }
1696 }
1697  
1698 # Adjust for DST crossings (23h / 25h days)
1699 3 my $bigger_min = $bigger->hour * 60 + $bigger->minute;
1700 3 ▶ if( $bigger->time_zone->has_dst_changes &&
Branch: 1 branch
BranchTrueFalseTotal
if ($bigger->time_zone->has_dst_changes and $bigger->is_dst != $smaller->is_dst) 0 3 3
Condition33%1/3
$bigger->time_zone->has_dst_changes and $bigger->is_dst != $smaller->is_dst
!ll&&!rl&&r
300
MC/DC0%0/2
$bigger->time_zone->has_dst_changes and $bigger->is_dst != $smaller->is_dst
$bigger->time_zone->has_dst_changes $bigger->is_dst != $smaller->is_dst
Truth table33%1/3
A and B
A= $bigger->time_zone->has_dst_changesB= $bigger->is_dst != $smaller->is_dst
ABresult
0X0
100
111
1701 $bigger->is_dst != $smaller->is_dst )
1702 {
1703 0 ▶ if( $bigger->is_dst )
Branch: 1 branch
BranchTrueFalseTotal
if ($bigger->is_dst) { } 0 0 0
1704 {
1705 0 my $prev = eval { $bigger->clone->subtract( days => 1 ) };
1706 0 ▶ $bigger_min -= 60 if( $prev && !$prev->is_dst );
Branch: 1 branch
BranchTrueFalseTotal
if $prev and not $prev->is_dst 0 0 0
Condition0%0/3
$prev and not $prev->is_dst
!ll&&!rl&&r
000
MC/DC0%0/2
$prev and not $prev->is_dst
$prev not $prev->is_dst
Truth table0%0/3
A and not(B)
A= $prevB= not $prev->is_dst
ABresult
0X0
100
111
1707 }
1708 else
1709 {
1710 0 my $prev = eval { $bigger->clone->subtract( days => 1 ) };
1711 0 ▶ $bigger_min += 60 if( $prev && $prev->is_dst );
Branch: 1 branch
BranchTrueFalseTotal
if $prev and $prev->is_dst 0 0 0
Condition0%0/3
$prev and $prev->is_dst
!ll&&!rl&&r
000
MC/DC0%0/2
$prev and $prev->is_dst
$prev $prev->is_dst
Truth table0%0/3
A and B
A= $prevB= $prev->is_dst
ABresult
0X0
100
111
1712 }
1713 }
1714  
1715 3 my( $months, $days, $minutes, $seconds, $nanoseconds )
1716 = $dt1->_adjust_for_positive_difference(
1717 $bigger->year * 12 + $bigger->month,
1718 $smaller->year * 12 + $smaller->month,
1719 $bigger->day, $smaller->day,
1720 $bigger_min, $smaller->hour * 60 + $smaller->minute,
1721 $bigger->second, $smaller->second,
1722 $bigger->nanosecond, $smaller->nanosecond,
1723 $minute_length,
1724 $dt1->_month_length( $smaller->year, $smaller->month ),
1725 );
1726  
1727 3 ▶ if( $negative )
Branch: 1 branch
BranchTrueFalseTotal
if ($negative) 0 3 3
1728 {
1729 0 foreach( $months, $days, $minutes, $seconds, $nanoseconds )
1730 {
1731 0 ▶ $_ *= -1 if( $_ );
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 0 0
1732 }
1733 }
1734  
1735 3 return( $dt1->duration_class->new(
1736 months => $months,
1737 days => $days,
1738 minutes => $minutes,
1739 seconds => $seconds,
1740 nanoseconds => $nanoseconds,
1741 ) );
1742 }
1743  
1744 sub subtract_datetime_absolute
1745 1 ▶{
Subroutine subtract_datetime_absolute: called CC=4 SCAR=14.7
Pod documented
1746 1 my $self = shift( @_ );
1747 1 my $dt = shift( @_ );
1748  
1749 1 my $utc_rd_secs1 = $self->utc_rd_as_seconds;
1750 $utc_rd_secs1 += $self->_accumulated_leap_seconds( $self->{utc_rd_days} )
1751 1 ▶ if( !$self->time_zone->is_floating );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->time_zone->is_floating 1 0 1
1752  
1753 1 my $utc_rd_secs2 = $dt->utc_rd_as_seconds;
1754 $utc_rd_secs2 += $self->_accumulated_leap_seconds( $dt->{utc_rd_days} )
1755 1 ▶ if( !$dt->time_zone->is_floating );
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->time_zone->is_floating 1 0 1
1756  
1757 1 my $seconds = $utc_rd_secs1 - $utc_rd_secs2;
1758 1 my $nanoseconds = $self->nanosecond - $dt->nanosecond;
1759  
1760 1 ▶ if( $nanoseconds < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($nanoseconds < 0) 0 1 1
1761 {
1762 0 $seconds--;
1763 0 $nanoseconds += MAX_NANOSECONDS;
1764 }
1765  
1766 1 return( $self->duration_class->new(
1767 seconds => $seconds,
1768 nanoseconds => $nanoseconds,
1769 ) );
1770 }
1771  
1772 234 ▶sub time_zone { return( $_[0]->{tz} ) }
Subroutine time_zone: called CC=1 SCAR=0.0
Pod documented
1773 23 ▶sub time_zone_long_name { $_[0]->{tz}->name }
Subroutine time_zone_long_name: called CC=1 SCAR=0.0
Pod documented
1774 5 ▶sub time_zone_short_name { $_[0]->{tz}->short_name_for_datetime( $_[0] ) }
Subroutine time_zone_short_name: called CC=1 SCAR=0.0
Pod documented
1775  
1776 1 ▶sub today { shift->now( @_ )->truncate( to => 'day' ) }
Subroutine today: called CC=1 SCAR=0.0
Pod documented
1777  
1778 sub truncate
1779 26 ▶{
Subroutine truncate: called CC=14 SCAR=33.6
Pod documented
1780 26 my $self = shift( @_ );
1781 26 my %p = @_;
1782  
1783 return( $self->error( "Parameter 'to' is required for truncate()." ) )
1784 26 ▶ unless( exists( $p{to} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"to"} 0 26 26
1785  
1786 26 my %TruncateDefault = (
1787 month => 1,
1788 day => 1,
1789 hour => 0,
1790 minute => 0,
1791 second => 0,
1792 nanosecond => 0,
1793 );
1794  
1795 my $valid_levels = join( '|', 'year', 'week', 'local_week', 'quarter',
1796 26 grep { $_ ne 'nanosecond' } keys( %TruncateDefault ) );
1797 return( $self->error( "Invalid truncation level '$p{to}'." ) )
1798 26 ▶ unless( $p{to} =~ /^(?:$valid_levels)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $p{"to"} =~ /^(?:$valid_levels)$/ 0 26 26
1799  
1800 26 my %new;
1801 26 ▶ if( $p{to} eq 'week' || $p{to} eq 'local_week' )
Branch: 2 branches
BranchTrueFalseTotal
if ($p{'to'} eq 'week' or $p{'to'} eq 'local_week') { } 0 26 26
elsif ($p{'to'} eq 'quarter') { } 3 23 26
Condition33%1/3
$p{"to"} eq "week" or $p{"to"} eq "local_week"
l!l&&r!l&&!r
0026
MC/DC0%0/2
$p{"to"} eq "week" or $p{"to"} eq "local_week"
$p{"to"} eq "week" $p{"to"} eq "local_week"
Truth table33%1/3
A or B
A= $p{"to"} eq "week"B= $p{"to"} eq "local_week"
ABresult
1X1
011
000
1802 {
1803 my $first_dow = ( $p{to} eq 'local_week' )
1804 ? $self->{locale}->first_day_of_week
1805 0 ▶ : 1;
Branch: 1 branch
BranchTrueFalseTotal
$p{'to'} eq 'local_week' ? : 0 0 0
1806  
1807 0 my $day_diff = ( $self->day_of_week - $first_dow ) % 7;
1808 0 ▶ $self->add( days => -1 * $day_diff ) if( $day_diff );
Branch: 1 branch
BranchTrueFalseTotal
if $day_diff 0 0 0
1809  
1810 0 my $ok = eval { $self->truncate( to => 'day' ); 1 };
1811 0 ▶ unless( $ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
1812 {
1813 0 $self->add( days => $day_diff );
1814 0 die( $@ );
1815 }
1816 }
1817 elsif( $p{to} eq 'quarter' )
1818 {
1819 3 %new = (
1820 year => $self->year,
1821 month => int( ( $self->month - 1 ) / 3 ) * 3 + 1,
1822 day => 1,
1823 hour => 0,
1824 minute => 0,
1825 second => 0,
1826 nanosecond => 0,
1827 );
1828 }
1829 else
1830 {
1831 23 my $truncate = 0;
1832 23 foreach my $f ( qw( year month day hour minute second nanosecond ) )
1833 {
1834 161 ▶ $new{$f} = $truncate ? $TruncateDefault{$f} : $self->$f();
Branch: 1 branch
BranchTrueFalseTotal
$truncate ? : 90 71 161
1835 161 ▶ $truncate = 1 if( $p{to} eq $f );
Branch: 1 branch
BranchTrueFalseTotal
if $p{"to"} eq $f 23 138 161
1836 }
1837 }
1838  
1839 26 ▶ if( %new )
Branch: 1 branch
BranchTrueFalseTotal
if (%new) 26 0 26
1840 {
1841 26 ▶ my $new_dt = $self->_new_from_self( %new, _skip_validation => 1 ) || return( $self->pass_error );
Condition50%1/2
$self->_new_from_self(%new, '_skip_validation', 1) || (return $self->pass_error)
l!l
260
MC/DC0%0/1
$self->_new_from_self(%new, '_skip_validation', 1) || (return $self->pass_error)
$self->_new_from_self(%new, '_skip_validation', 1)
Truth table50%1/2
A
A= $self->_new_from_self(%new, '_skip_validation', 1)
Aresult
11
00
1842 26 %$self = %$new_dt;
1843 }
1844  
1845 26 return( $self );
1846 }
1847  
1848 sub utc_rd_as_seconds
1849 110 ▶{
Subroutine utc_rd_as_seconds: called CC=1 SCAR=0.0
Pod documented
1850 110 my $self = shift( @_ );
1851 110 return( $self->{utc_rd_days} * SECONDS_PER_DAY + $self->{utc_rd_secs} );
1852 }
1853  
1854 sub utc_rd_values
1855 126 ▶{
Subroutine utc_rd_values: called CC=1 SCAR=0.0
Pod documented
1856 126 my $self = shift( @_ );
1857 126 return( $self->{utc_rd_days}, $self->{utc_rd_secs}, $self->{rd_nanosecs} );
1858 }
1859  
1860 1 ▶sub utc_year { $_[0]->{utc_year} }
Subroutine utc_year: called CC=1 SCAR=0.0
Pod documented
1861  
1862 sub week
1863 9 ▶{
Subroutine week: called CC=2 SCAR=6.9
Pod documented
1864 9 my $self = shift( @_ );
1865  
1866 # Memoised: computing week values requires day_of_year and day_of_week
1867 # which are already in local_c, so this is cheap after the first call.
1868 9 ▶ unless( exists( $self->{utc_c}->{week_year} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"utc_c"}{"week_year"}) 4 5 9
1869 {
1870 4 $self->{utc_c}->{week_year} = $self->_week_values;
1871 }
1872 9 return( @{$self->{utc_c}->{week_year}}[0, 1] );
1873 }
1874  
1875 5 ▶sub week_number { ( $_[0]->week )[1] }
Subroutine week_number: called CC=1 SCAR=0.0
Pod documented
1876  
1877 # ISO: first week of the month is the first week containing a Thursday.
1878 # Direct formula - no clone, no add(), no recursion.
1879 # NOTE: week_of_month is autoloaded
1880  
1881 3 ▶sub week_year { ( $_[0]->week )[0] }
Subroutine week_year: called CC=1 SCAR=0.0
Pod documented
1882  
1883 # NOTE: weekday_of_month is autoloaded
1884  
1885 sub year
1886 177 ▶{
Subroutine year: called CC=1 SCAR=0.0
Pod documented
1887 177 my $self = shift( @_ );
1888 177 return( $self->{local_c}->{year} );
1889 }
1890  
1891 # NOTE: year_length is autoloaded
1892  
1893 # NOTE: year_with_christian_era is autoloaded
1894  
1895 # NOTE: year_with_era is autoloaded
1896  
1897 # NOTE: year_with_secular_era is autoloaded
1898  
1899 sub ymd
1900 24 ▶{
Subroutine ymd: called CC=2 SCAR=6.9
Pod documented
1901 24 my $self = shift( @_ );
1902 24 ▶ my $sep = defined( $_[0] ) ? shift( @_ ) : '-';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 20 4 24
1903 24 return( sprintf( "%04d%s%02d%s%02d",
1904 $self->year, $sep, $self->month, $sep, $self->day ) );
1905 }
1906  
1907 # NOTE:: AUTOLOAD
1908 sub AUTOLOAD
1909 55 ▶{
Subroutine AUTOLOAD: called CC=11 SCAR=27.0
1910 55 my $self;
1911 55 ▶ $self = shift( @_ ) if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'DateTime::Lite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa("DateTime::Lite") 55 0 55
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("DateTime::Lite")
!ll&&!rl&&r
0055
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("DateTime::Lite")
builtin::blessed($_[0]) $_[0]->isa("DateTime::Lite")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("DateTime::Lite")
ABresult
0X0
100
111
1912 55 my( $class, $meth );
1913 55 ▶ $class = ref( $self ) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
5500
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1914 16 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1915 16 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1916 55 $meth = $AUTOLOAD;
1917 55 ▶ if( CORE::index( $meth, '::' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($meth, "::") != -1) 55 0 55
1918 {
1919 55 my $idx = rindex( $meth, '::' );
1920 55 $class = substr( $meth, 0, $idx );
1921 55 $meth = substr( $meth, $idx + 2 );
1922 }
1923  
1924 55 ▶ unless( $AUTOLOAD_SUBS )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DateTime::Lite::AUTOLOAD_SUBS) 3 52 55
1925 {
1926 3 &_autoload_subs();
1927 }
1928 55 my $code;
1929 55 ▶ if( CORE::exists( $AUTOLOAD_SUBS->{ $meth } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DateTime::Lite::AUTOLOAD_SUBS->{$meth}) 55 0 55
1930 {
1931 55 $code = $AUTOLOAD_SUBS->{ $meth };
1932 55 my $saved = $@;
1933 55 local $@;
1934 {
1935 16 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1936 0 ▶ eval( $code );
Subroutine day_of_week_0: called CC=5 SCAR=17.6
Subroutine dmy: called CC=6 SCAR=19.7
Subroutine fractional_second: called CC=5 SCAR=17.6
Subroutine hour_1: called CC=6 SCAR=19.7
Subroutine hour_12: called CC=6 SCAR=19.7
Subroutine hour_12_0: called CC=5 SCAR=17.6
Subroutine is_last_day_of_month: called CC=5 SCAR=17.6
Subroutine mdy: called CC=6 SCAR=19.7
Subroutine microsecond: called CC=5 SCAR=17.6
Subroutine millisecond: called CC=5 SCAR=17.6
Subroutine month_0: called CC=5 SCAR=17.6
Subroutine quarter_0: called CC=5 SCAR=17.6
Subroutine week_of_month: called CC=5 SCAR=17.6
Subroutine am_or_pm: called CC=6 SCAR=19.7
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine ce_year: called CC=6 SCAR=19.7
Subroutine christian_era: called CC=6 SCAR=19.7
Subroutine day_of_month_0: called CC=5 SCAR=17.6
Pod undocumented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod undocumented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 39 branches
BranchTrueFalseTotal
unless (scalar @_) 0 20 20
unless (defined $self and builtin::blessed($self // "")) 0 20 20
unless (scalar @_) 2 10 12
unless (defined $self and builtin::blessed($self // "")) 0 15 15
unless (scalar @_) 0 15 15
unless (defined $self and builtin::blessed($self // "")) 3 12 15
unless (scalar @_) 0 7 7
unless (defined $self and builtin::blessed($self // "")) 0 7 7
$self->{'local_c'}{'hour'} == 0 ? : 3 3 6
unless (scalar @_) 0 9 9
unless (defined $self and builtin::blessed($self // "")) 0 9 9
$h ? : 7 4 11
unless (scalar @_) 0 6 6
unless (defined $self and builtin::blessed($self // "")) 0 4 4
unless (scalar @_) 0 5 5
unless (defined $self and builtin::blessed($self // "")) 0 4 4
unless (scalar @_) 0 5 5
unless (defined $self and builtin::blessed($self // "")) 0 5 5
unless (scalar @_) 0 4 4
unless (defined $self and builtin::blessed($self // "")) 0 4 4
unless (scalar @_) 0 5 5
unless (defined $self and builtin::blessed($self // "")) 0 5 5
unless (scalar @_) 0 16 16
unless (defined $self and builtin::blessed($self // "")) 0 16 16
unless (scalar @_) 0 9 9
unless (defined $self and builtin::blessed($self // "")) 0 9 9
unless (scalar @_) 0 5 5
unless (defined $self and builtin::blessed($self // "")) 0 4 4
unless (scalar @_) 0 4 4
unless (defined $self and builtin::blessed($self // "")) 0 4 4
$self->{'local_c'}{'hour'} < 12 ? : 0 7 7
unless (scalar @_) 0 5 5
unless (defined $self and builtin::blessed($self // "")) 1 4 5
$self->{'local_c'}{'year'} <= 0 ? : 0 4 4
unless (scalar @_) 0 4 4
unless (defined $self and builtin::blessed($self // "")) 2 2 4
$self->ce_year > 0 ? : 0 1 1
unless (scalar @_) 0 1 1
unless (defined $self and builtin::blessed($self // "")) 0 1 1
Condition54%56/102
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
0020
$self // ""
l!l
200
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
0015
$self // ""
l!l
150
$sep //= "-"
l!l
123
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
304
$self // ""
l!l
401
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
104
$self // ""
l!l
403
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
308
$self // ""
l!l
801
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
103
$self // ""
l!l
30
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
004
$self // ""
l!l
40
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
005
$self // ""
l!l
50
$sep //= "-"
l!l
122
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
202
$self // ""
l!l
203
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
302
$self // ""
l!l
201
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
1015
$self // ""
l!l
1501
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
108
$self // ""
l!l
80
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
004
$self // ""
l!l
40
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
004
$self // ""
l!l
40
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
005
$self // ""
l!l
50
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
004
$self // ""
l!l
40
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
001
$self // ""
l!l
10
defined $self and builtin::blessed($self // "")
!ll&&!rl&&r
001
$self // ""
l!l
10
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/1
$sep //= "-"
$sep
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/1
$sep //= "-"
$sep
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
MC/DC0%0/2
defined $self and builtin::blessed($self // "")
defined $self $self
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table50%1/2
A
A= $sep
Aresult
11
00
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table50%1/2
A
A= $sep
Aresult
11
00
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= $self
ABresult
0X0
100
111
1937 }
1938 55 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 55 55
1939 {
1940 0 $@ =~ s/ at .*\n//;
1941 0 die( $@ );
1942 }
1943 55 $@ = $saved;
1944 55 ▶ my $ref = $class->can( $meth ) || die( "AUTOLOAD inconsistency error for dynamic sub \"$meth\"." );
Condition50%1/2
$class->can($meth) || die(qq[AUTOLOAD inconsistency error for dynamic sub "$meth".])
l!l
550
MC/DC0%0/1
$class->can($meth) || die(qq[AUTOLOAD inconsistency error for dynamic sub "$meth".])
$class->can($meth)
Truth table50%1/2
A
A= $class->can($meth)
Aresult
11
00
1945 55 ▶ return( &$meth( $self, @_ ) ) if( $self );
Branch: 1 branch
BranchTrueFalseTotal
if $self 55 0 55
1946 }
1947 0 my( $pkg, $file, $line ) = caller();
1948 0 my $sub = ( caller(1) )[3];
1949 # NOTE: should we not die ?
1950 0 ▶ die( "Method $meth() is not defined in class $class and not autoloadable in package $pkg in file $file at line $line", ( defined( $sub ) ? " from within subroutine $sub" : '' ), "." );
Branch: 1 branch
BranchTrueFalseTotal
defined $sub ? : 0 0 0
1951 }
1952  
1953 # So AUTOLOAD does not catch it.
1954 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
1955  
1956 sub FREEZE
1957 0 ▶{
Subroutine FREEZE: not called CC=4 SCAR=30.0
Pod undocumented
1958 0 my $self = CORE::shift( @_ );
1959 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1960 0 my $class = CORE::ref( $self );
1961 0 my %hash = %$self;
1962 # Return an array reference rather than a list so this works with Sereal and CBOR
1963 # On or before Sereal version 4.023, Sereal did not support multiple values returned
1964 0 ▶ CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 0 0
Condition0%0/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
000
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table0%0/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
1965 # But Storable want a list with the first element being the serialised element
1966 0 CORE::return( $class, \%hash );
1967 }
1968  
1969 # NOTE: Serialisation
1970 sub STORABLE_freeze
1971 2 ▶{
Subroutine STORABLE_freeze: called CC=3 SCAR=11.0
Pod undocumented
1972 2 my $self = shift( @_ );
1973 2 my $serialized = '';
1974 2 foreach my $key ( qw( utc_rd_days utc_rd_secs rd_nanosecs ) )
1975 {
1976 6 $serialized .= "$key:$self->{$key}|";
1977 }
1978 2 ▶ $serialized .= 'version:' . ( $DateTime::Lite::VERSION || 'git' );
Condition50%1/2
$DateTime::Lite::VERSION || 'git'
l!l
20
MC/DC0%0/1
$DateTime::Lite::VERSION || 'git'
$DateTime::Lite::VERSION
Truth table50%1/2
A
A= $DateTime::Lite::VERSION
Aresult
11
00
1979 2 return( $serialized, $self->{locale}, $self->{tz}, \$self->{formatter} );
1980 }
1981  
1982 sub STORABLE_thaw
1983 2 ▶{
Subroutine STORABLE_thaw: called CC=8 SCAR=25.2
Pod undocumented
1984 2 my $self = shift( @_ );
1985 2 shift( @_ );
1986 2 my $serialized = shift( @_ );
1987  
1988 2 my %s = map { split( /:/, $_, 2 ) } split( /\|/, $serialized );
1989  
1990 2 my( $locale, $tz, $formatter );
1991  
1992 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 0 2
1993 {
1994 2 ( $locale, $tz, $formatter ) = @_;
1995 }
1996 else
1997 {
1998 0 ▶ $tz = DateTime::Lite::TimeZone->new( name => delete( $s{tz} ) ) ||
Condition0%0/2
'DateTime::Lite::TimeZone'->new('name', delete $s{'tz'}) || die('DateTime::Lite::TimeZone'->error)
l!l
00
MC/DC0%0/1
'DateTime::Lite::TimeZone'->new('name', delete $s{'tz'}) || die('DateTime::Lite::TimeZone'->error)
'DateTime::Lite::TimeZone'->new('name', delete $s{'tz'})
Truth table0%0/2
A
A= 'DateTime::Lite::TimeZone'->new('name', delete $s{'tz'})
Aresult
11
00
1999 die( DateTime::Lite::TimeZone->error );
2000 0 ▶ $locale = DateTime::Locale::FromCLDR->new( delete( $s{locale} ) ) ||
Condition0%0/2
'DateTime::Locale::FromCLDR'->new(delete $s{'locale'}) || die('DateTime::Locale::FromCLDR'->error)
l!l
00
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new(delete $s{'locale'}) || die('DateTime::Locale::FromCLDR'->error)
'DateTime::Locale::FromCLDR'->new(delete $s{'locale'})
Truth table0%0/2
A
A= 'DateTime::Locale::FromCLDR'->new(delete $s{'locale'})
Aresult
11
00
2001 die( DateTime::Locale::FromCLDR->error );
2002 }
2003  
2004 2 delete( $s{version} );
2005  
2006 my $object = bless(
2007 {
2008 utc_vals => [
2009 $s{utc_rd_days},
2010 $s{utc_rd_secs},
2011 $s{rd_nanosecs},
2012 2 ],
2013 tz => $tz,
2014 }, 'DateTime::Lite::_Thawed' );
2015  
2016 2 my %fmt;
2017 2 ▶ if( defined( $formatter ) && ref( $formatter ) && defined( $$formatter ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $formatter and ref $formatter and defined $$formatter) 0 2 2
Condition33%2/6
defined $formatter and ref $formatter and defined $$formatter
!ll&&!rl&&r
020
defined $formatter and ref $formatter
!ll&&!rl&&r
002
MC/DC0%0/3
defined $formatter and ref $formatter and defined $$formatter
defined $formatter ref $formatter defined $$formatter
Truth table25%1/4
A and B and C
A= defined $formatterB= ref $formatterC= defined $$formatter
ABCresult
0XX0
10X0
1100
1111
2018 {
2019 0 %fmt = ( formatter => $$formatter );
2020 }
2021 2 ▶ my $new = ( ref( $self ) )->from_object(
Condition50%1/2
ref($self)->from_object('object', $object, 'locale', $locale, %fmt) || die(ref($self)->error)
l!l
20
MC/DC0%0/1
ref($self)->from_object('object', $object, 'locale', $locale, %fmt) || die(ref($self)->error)
ref($self)->from_object('object', $object, 'locale', $locale, %fmt)
Truth table50%1/2
A
A= ref($self)->from_object('object', $object, 'locale', $locale, %fmt)
Aresult
11
00
2022 object => $object,
2023 locale => $locale,
2024 %fmt,
2025 ) || die( ref( $self )->error );
2026  
2027 2 %$self = %$new;
2028 2 return( $self );
2029 }
2030  
2031 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
2032 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
2033 sub THAW
2034 0 ▶{
Subroutine THAW: not called CC=10 SCAR=47.0
Pod undocumented
2035 0 my( $self, undef, @args ) = @_;
2036 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
2037 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
2038 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
2039 0 my $new;
2040 # Storable pattern requires to modify the object it created rather than returning a new one
2041 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
2042 {
2043 0 foreach( CORE::keys( %$hash ) )
2044 {
2045 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
2046 }
2047 0 $new = $self;
2048 }
2049 else
2050 {
2051 0 $new = CORE::bless( $hash => $class );
2052 }
2053 0 CORE::return( $new );
2054 }
2055  
2056 2 ▶sub TO_JSON { return( $_[0]->stringify ) }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
2057  
2058 # NOTE: Private methods (alphabetical)
2059 sub _add_duration
2060 41 ▶{
Subroutine _add_duration: called CC=15 SCAR=28.1
2061 41 my $self = shift( @_ );
2062 41 my $dur = shift( @_ );
2063  
2064 41 my %deltas = $dur->deltas;
2065  
2066 41 ▶ if( $deltas{days} )
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"days"}) 5 36 41
2067 {
2068 5 $self->{local_rd_days} += $deltas{days};
2069 5 $self->{utc_year} += int( $deltas{days} / 365 ) + 1;
2070 }
2071  
2072 41 ▶ if( $deltas{months} )
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"months"}) 11 30 41
2073 {
2074 my( $y, $m, $d ) = (
2075 $dur->is_preserve_mode
2076 ? $self->_rd2ymd( $self->{local_rd_days} + 1 )
2077 : $self->_rd2ymd( $self->{local_rd_days} )
2078 11 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$dur->is_preserve_mode ? : 0 11 11
2079  
2080 11 ▶ $d -= 1 if( $dur->is_preserve_mode );
Branch: 1 branch
BranchTrueFalseTotal
if $dur->is_preserve_mode 0 11 11
2081  
2082 11 ▶ if( !$dur->is_wrap_mode && $d > 28 )
Branch: 1 branch
BranchTrueFalseTotal
if (not $dur->is_wrap_mode and $d > 28) { } 0 11 11
Condition33%1/3
not $dur->is_wrap_mode and $d > 28
!ll&&!rl&&r
1100
MC/DC0%0/2
not $dur->is_wrap_mode and $d > 28
not $dur->is_wrap_mode $d > 28
Truth table33%1/3
not(A) and B
A= not $dur->is_wrap_modeB= $d > 28
ABresult
0X0
100
111
2083 {
2084 $self->{local_rd_days}
2085 0 = $self->_ymd2rd( $y, $m + $deltas{months} + 1, 0 );
2086 0 my $last_day = ( $self->_rd2ymd( $self->{local_rd_days} ) )[2];
2087 0 ▶ $self->{local_rd_days} -= $last_day - $d if( $last_day > $d );
Branch: 1 branch
BranchTrueFalseTotal
if $last_day > $d 0 0 0
2088 }
2089 else
2090 {
2091 $self->{local_rd_days}
2092 11 = $self->_ymd2rd( $y, $m + $deltas{months}, $d );
2093 }
2094  
2095 11 $self->{utc_year} += int( $deltas{months} / 12 ) + 1;
2096 }
2097  
2098 41 ▶ if( $deltas{days} || $deltas{months} )
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"days"} or $deltas{"months"}) 16 25 41
Condition100%3/3
$deltas{"days"} or $deltas{"months"}
l!l&&r!l&&!r
51125
MC/DC100%2/2
$deltas{"days"} or $deltas{"months"}
$deltas{"days"} $deltas{"months"}
Truth table100%3/3
A or B
A= $deltas{"days"}B= $deltas{"months"}
ABresult
1X1
011
000
2099 {
2100 16 $self->_calc_utc_rd;
2101 16 $self->_handle_offset_modifier( $self->second );
2102 }
2103  
2104 41 ▶ if( $deltas{minutes} )
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"minutes"}) 4 37 41
2105 {
2106 4 $self->{utc_rd_secs} += $deltas{minutes} * 60;
2107 $self->_normalize_tai_seconds(
2108 $self->{utc_rd_days},
2109 $self->{utc_rd_secs},
2110 4 );
2111 }
2112  
2113 41 ▶ if( $deltas{seconds} || $deltas{nanoseconds} )
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"seconds"} or $deltas{"nanoseconds"}) 21 20 41
Condition66%2/3
$deltas{"seconds"} or $deltas{"nanoseconds"}
l!l&&r!l&&!r
21020
MC/DC50%1/2
$deltas{"seconds"} or $deltas{"nanoseconds"}
$deltas{"seconds"} $deltas{"nanoseconds"}
Truth table66%2/3
A or B
A= $deltas{"seconds"}B= $deltas{"nanoseconds"}
ABresult
1X1
011
000
2114 {
2115 21 $self->{utc_rd_secs} += $deltas{seconds};
2116  
2117 21 ▶ if( $deltas{nanoseconds} )
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"nanoseconds"}) 12 9 21
2118 {
2119 12 $self->{rd_nanosecs} += $deltas{nanoseconds};
2120 $self->_normalize_nanoseconds(
2121 $self->{utc_rd_secs},
2122 $self->{rd_nanosecs},
2123 12 );
2124 }
2125  
2126 21 $self->_normalize_seconds;
2127 21 $self->_handle_offset_modifier( $self->second + $deltas{seconds} );
2128 }
2129  
2130 my $new = ( ref( $self ) )->from_object(
2131 object => $self,
2132 locale => $self->{locale},
2133 41 ▶ ( $self->{formatter} ? ( formatter => $self->{formatter} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'formatter'} ? : 0 41 41
2134 );
2135  
2136 41 %$self = %$new;
2137 41 return( $self );
2138 }
2139  
2140 sub _add_overload
2141 1 ▶{
Subroutine _add_overload: called CC=4 SCAR=17.9
2142 1 my( $dt, $dur, $reversed ) = @_;
2143 1 ▶ ( $dur, $dt ) = ( $dt, $dur ) if( $reversed );
Branch: 1 branch
BranchTrueFalseTotal
if $reversed 0 1 1
2144  
2145 1 ▶ unless( Scalar::Util::blessed( $dur ) && $dur->isa( 'DateTime::Lite::Duration' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($dur) and $dur->isa("DateTime::Lite::Duration")) 0 1 1
Condition33%1/3
builtin::blessed($dur) and $dur->isa("DateTime::Lite::Duration")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($dur) and $dur->isa("DateTime::Lite::Duration")
builtin::blessed($dur) $dur->isa("DateTime::Lite::Duration")
Truth table33%1/3
A and B
A= builtin::blessed($dur)B= $dur->isa("DateTime::Lite::Duration")
ABresult
0X0
100
111
2146 {
2147 0 my $class = ref( $dt );
2148 0 my $dt_string = overload::StrVal( $dt );
2149 0 die( "Cannot add $dur to a $class object ($dt_string). Only a DateTime::Lite::Duration can be added." );
2150 }
2151  
2152 1 return( $dt->clone->add_duration( $dur ) );
2153 }
2154  
2155 sub _adjust_for_positive_difference
2156 4 ▶{
Subroutine _adjust_for_positive_difference: called CC=5 SCAR=22.0
2157 my(
2158 4 $self,
2159 $month1, $month2,
2160 $day1, $day2,
2161 $min1, $min2,
2162 $sec1, $sec2,
2163 $nano1, $nano2,
2164 $minute_length,
2165 $month_length,
2166 ) = @_;
2167  
2168 4 ▶ if( $nano1 < $nano2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($nano1 < $nano2) 0 4 4
2169 {
2170 0 $sec1--;
2171 0 $nano1 += MAX_NANOSECONDS;
2172 }
2173  
2174 4 ▶ if( $sec1 < $sec2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($sec1 < $sec2) 0 4 4
2175 {
2176 0 $min1--;
2177 0 $sec1 += $minute_length;
2178 }
2179  
2180 4 ▶ if( $min1 < $min2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($min1 < $min2) 0 4 4
2181 {
2182 0 $day1--;
2183 0 $min1 += 24 * 60;
2184 }
2185  
2186 4 ▶ if( $day1 < $day2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($day1 < $day2) 0 4 4
2187 {
2188 0 $month1--;
2189 0 $day1 += $month_length;
2190 }
2191  
2192 return(
2193 4 $month1 - $month2,
2194 $day1 - $day2,
2195 $min1 - $min2,
2196 $sec1 - $sec2,
2197 $nano1 - $nano2,
2198 );
2199 }
2200  
2201 sub _autoload_subs
2202 3 ▶{
Subroutine _autoload_subs: called CC=7 SCAR=30.7
2203 # This is autogenerated; do not make modifications as they will be lost.
2204 3 my $subs =
2205 {
2206 # NOTE: am_or_pm()
2207 am_or_pm => <<'PERL',
2208 sub am_or_pm
2209 {
2210 if( !scalar( @_ ) )
2211 {
2212 die( 'Usage: $dt->am_or_pm' );
2213 }
2214 my $self = shift( @_ );
2215 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2216 {
2217 die( 'Usage: $dt->am_or_pm' );
2218 }
2219 return( $self->{locale}->am_pm_abbreviated->[ $self->{local_c}->{hour} < 12 ? 0 : 1 ] );
2220 }
2221 PERL
2222 # NOTE: ce_year()
2223 ce_year => <<'PERL',
2224 sub ce_year
2225 {
2226 if( !scalar( @_ ) )
2227 {
2228 die( 'Usage: $dt->ce_year' );
2229 }
2230 my $self = shift( @_ );
2231 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2232 {
2233 die( 'Usage: $dt->ce_year' );
2234 }
2235 return( $self->{local_c}->{year} <= 0
2236 ? $self->{local_c}->{year} - 1
2237 : $self->{local_c}->{year} );
2238 }
2239 PERL
2240 # NOTE: christian_era()
2241 christian_era => <<'PERL',
2242 sub christian_era
2243 {
2244 if( !scalar( @_ ) )
2245 {
2246 die( 'Usage: $dt->christian_era' );
2247 }
2248 my $self = shift( @_ );
2249 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2250 {
2251 die( 'Usage: $dt->christian_era' );
2252 }
2253 return( $self->ce_year > 0 ? 'AD' : 'BC' );
2254 }
2255 PERL
2256 # NOTE: day_of_month_0()
2257 day_of_month_0 => <<'PERL',
2258 sub day_of_month_0
2259 {
2260 if( !scalar( @_ ) )
2261 {
2262 die( 'Usage: $dt->day_of_month_0' );
2263 }
2264 my $self = shift( @_ );
2265 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2266 {
2267 die( 'Usage: $dt->day_of_month_0' );
2268 }
2269 return( $self->{local_c}->{day} - 1 );
2270 }
2271 PERL
2272 # NOTE: day_of_quarter()
2273 day_of_quarter => <<'PERL',
2274 sub day_of_quarter
2275 {
2276 if( !scalar( @_ ) )
2277 {
2278 die( 'Usage: $dt->day_of_quarter' );
2279 }
2280 my $self = shift( @_ );
2281 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2282 {
2283 die( 'Usage: $dt->day_of_quarter' );
2284 }
2285 return( $self->{local_c}->{day_of_quarter} );
2286 }
2287 PERL
2288 # NOTE: day_of_quarter_0()
2289 day_of_quarter_0 => <<'PERL',
2290 sub day_of_quarter_0
2291 {
2292 if( !scalar( @_ ) )
2293 {
2294 die( 'Usage: $dt->day_of_quarter_0' );
2295 }
2296 my $self = shift( @_ );
2297 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2298 {
2299 die( 'Usage: $dt->day_of_quarter_0' );
2300 }
2301 return( $self->{local_c}->{day_of_quarter} - 1 );
2302 }
2303 PERL
2304 # NOTE: day_of_week_0()
2305 day_of_week_0 => <<'PERL',
2306 sub day_of_week_0
2307 {
2308 if( !scalar( @_ ) )
2309 {
2310 die( 'Usage: $dt->day_of_week_0' );
2311 }
2312 my $self = shift( @_ );
2313 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2314 {
2315 die( 'Usage: $dt->day_of_week_0' );
2316 }
2317 return( $self->{local_c}->{day_of_week} - 1 );
2318 }
2319 PERL
2320 # NOTE: day_of_year_0()
2321 day_of_year_0 => <<'PERL',
2322 sub day_of_year_0
2323 {
2324 if( !scalar( @_ ) )
2325 {
2326 die( 'Usage: $dt->day_of_year_0' );
2327 }
2328 my $self = shift( @_ );
2329 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2330 {
2331 die( 'Usage: $dt->day_of_year_0' );
2332 }
2333 return( $self->{local_c}->{day_of_year} - 1 );
2334 }
2335 PERL
2336 # NOTE: dmy()
2337 dmy => <<'PERL',
2338 sub dmy
2339 {
2340 if( !scalar( @_ ) )
2341 {
2342 die( 'Usage: $dt->dmy or $dt->dmy( "-" )' );
2343 }
2344 my( $self, $sep ) = @_;
2345 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2346 {
2347 die( 'Usage: $dt->dmy or $dt->dmy( "-" )' );
2348 }
2349 $sep //= '-';
2350 return( sprintf( '%0.2d%s%0.2d%s%0.4d',
2351 $self->{local_c}->{day}, $sep,
2352 $self->{local_c}->{month}, $sep,
2353 $self->{local_c}->{year} ) );
2354 }
2355 PERL
2356 # NOTE: era_abbr()
2357 era_abbr => <<'PERL',
2358 sub era_abbr
2359 {
2360 if( !scalar( @_ ) )
2361 {
2362 die( 'Usage: $dt->era_abbr' );
2363 }
2364 my $self = shift( @_ );
2365 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2366 {
2367 die( 'Usage: $dt->era_abbr' );
2368 }
2369 return( $self->{locale}->era_abbreviated->[ $self->_era_index ] );
2370 }
2371 PERL
2372 # NOTE: era_name()
2373 era_name => <<'PERL',
2374 sub era_name
2375 {
2376 if( !scalar( @_ ) )
2377 {
2378 die( 'Usage: $dt->era_name' );
2379 }
2380 my $self = shift( @_ );
2381 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2382 {
2383 die( 'Usage: $dt->era_name' );
2384 }
2385 return( $self->{locale}->era_wide->[ $self->_era_index ] );
2386 }
2387 PERL
2388 # NOTE: fractional_second()
2389 fractional_second => <<'PERL',
2390 sub fractional_second
2391 {
2392 if( !scalar( @_ ) )
2393 {
2394 die( 'Usage: $dt->fractional_second' );
2395 }
2396 my $self = shift( @_ );
2397 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2398 {
2399 die( 'Usage: $dt->fractional_second' );
2400 }
2401 return( $self->second + $self->nanosecond / MAX_NANOSECONDS );
2402 }
2403 PERL
2404 # NOTE: hour_1()
2405 hour_1 => <<'PERL',
2406 sub hour_1
2407 {
2408 if( !scalar( @_ ) )
2409 {
2410 die( 'Usage: $dt->hour_1' );
2411 }
2412 my $self = shift( @_ );
2413 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2414 {
2415 die( 'Usage: $dt->hour_1' );
2416 }
2417 return( $self->{local_c}->{hour} == 0 ? 24 : $self->{local_c}->{hour} );
2418 }
2419 PERL
2420 # NOTE: hour_12()
2421 hour_12 => <<'PERL',
2422 sub hour_12
2423 {
2424 if( !scalar( @_ ) )
2425 {
2426 die( 'Usage: $dt->hour_12' );
2427 }
2428 my $self = shift( @_ );
2429 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2430 {
2431 die( 'Usage: $dt->hour_12' );
2432 }
2433 my $h = $self->hour % 12;
2434 return( $h ? $h : 12 );
2435 }
2436 PERL
2437 # NOTE: hour_12_0()
2438 hour_12_0 => <<'PERL',
2439 sub hour_12_0
2440 {
2441 if( !scalar( @_ ) )
2442 {
2443 die( 'Usage: $dt->hour_12_0' );
2444 }
2445 my $self = shift( @_ );
2446 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2447 {
2448 die( 'Usage: $dt->hour_12_0' );
2449 }
2450 return( $self->hour % 12 );
2451 }
2452 PERL
2453 # NOTE: is_last_day_of_month()
2454 is_last_day_of_month => <<'PERL',
2455 sub is_last_day_of_month
2456 {
2457 if( !scalar( @_ ) )
2458 {
2459 die( 'Usage: $dt->is_last_day_of_month' );
2460 }
2461 my $self = shift( @_ );
2462 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2463 {
2464 die( 'Usage: $dt->is_last_day_of_month' );
2465 }
2466 return( $self->day == $self->_month_length( $self->year, $self->month ) );
2467 }
2468 PERL
2469 # NOTE: is_last_day_of_quarter()
2470 is_last_day_of_quarter => <<'PERL',
2471 sub is_last_day_of_quarter
2472 {
2473 if( !scalar( @_ ) )
2474 {
2475 die( 'Usage: $dt->is_last_day_of_quarter' );
2476 }
2477 my $self = shift( @_ );
2478 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2479 {
2480 die( 'Usage: $dt->is_last_day_of_quarter' );
2481 }
2482 return( $self->day_of_quarter == $self->quarter_length );
2483 }
2484 PERL
2485 # NOTE: is_last_day_of_year()
2486 is_last_day_of_year => <<'PERL',
2487 sub is_last_day_of_year
2488 {
2489 if( !scalar( @_ ) )
2490 {
2491 die( 'Usage: $dt->is_last_day_of_year' );
2492 }
2493 my $self = shift( @_ );
2494 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2495 {
2496 die( 'Usage: $dt->is_last_day_of_year' );
2497 }
2498 return( $self->day_of_year == $self->year_length );
2499 }
2500 PERL
2501 # NOTE: jd()
2502 jd => <<'PERL',
2503 sub jd
2504 {
2505 if( !scalar( @_ ) )
2506 {
2507 die( 'Usage: $dt->jd' );
2508 }
2509 my $self = shift( @_ );
2510 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2511 {
2512 die( 'Usage: $dt->jd' );
2513 }
2514 return( $self->mjd + 2_400_000.5 );
2515 }
2516 PERL
2517 # NOTE: leap_seconds()
2518 leap_seconds => <<'PERL',
2519 sub leap_seconds
2520 {
2521 if( !scalar( @_ ) )
2522 {
2523 die( 'Usage: $dt->leap_seconds' );
2524 }
2525 my $self = shift( @_ );
2526 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2527 {
2528 die( 'Usage: $dt->leap_seconds' );
2529 }
2530 return(0) if( $self->{tz}->is_floating );
2531 return( $self->_accumulated_leap_seconds( $self->{utc_rd_days} ) );
2532 }
2533 PERL
2534 # NOTE: local_day_of_week()
2535 local_day_of_week => <<'PERL',
2536 sub local_day_of_week
2537 {
2538 if( !scalar( @_ ) )
2539 {
2540 die( 'Usage: $dt->local_day_of_week' );
2541 }
2542 my $self = shift( @_ );
2543 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2544 {
2545 die( 'Usage: $dt->local_day_of_week' );
2546 }
2547 return( 1 + ( ( $self->day_of_week - $self->{locale}->first_day_of_week ) % 7 ) );
2548 }
2549 PERL
2550 # NOTE: mdy()
2551 mdy => <<'PERL',
2552 sub mdy
2553 {
2554 if( !scalar( @_ ) )
2555 {
2556 die( 'Usage: $dt->mdy or $dt->mdy( "-" )' );
2557 }
2558 my( $self, $sep ) = @_;
2559 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2560 {
2561 die( 'Usage: $dt->mdy or $dt->mdy( "-" )' );
2562 }
2563 $sep //= '-';
2564 return( sprintf( "%02d%s%02d%s%04d",
2565 $self->month, $sep, $self->day, $sep, $self->year ) );
2566 }
2567 PERL
2568 # NOTE: microsecond()
2569 microsecond => <<'PERL',
2570 sub microsecond
2571 {
2572 if( !scalar( @_ ) )
2573 {
2574 die( 'Usage: $dt->microsecond' );
2575 }
2576 my $self = shift( @_ );
2577 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2578 {
2579 die( 'Usage: $dt->microsecond' );
2580 }
2581 return( POSIX::floor( $self->{rd_nanosecs} / 1000 ) );
2582 }
2583 PERL
2584 # NOTE: millisecond()
2585 millisecond => <<'PERL',
2586 sub millisecond
2587 {
2588 if( !scalar( @_ ) )
2589 {
2590 die( 'Usage: $dt->millisecond' );
2591 }
2592 my $self = shift( @_ );
2593 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2594 {
2595 die( 'Usage: $dt->millisecond' );
2596 }
2597 return( POSIX::floor( $self->{rd_nanosecs} / 1000000 ) );
2598 }
2599 PERL
2600 # NOTE: mjd()
2601 mjd => <<'PERL',
2602 sub mjd
2603 {
2604 if( !scalar( @_ ) )
2605 {
2606 die( 'Usage: $dt->mjd' );
2607 }
2608 my $self = shift( @_ );
2609 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2610 {
2611 die( 'Usage: $dt->mjd' );
2612 }
2613 my $mjd = $self->{utc_rd_days} - 678_576;
2614 my $day_length = $self->_day_length( $self->{utc_rd_days} );
2615 return( $mjd
2616 + ( $self->{utc_rd_secs} / $day_length )
2617 + ( $self->{rd_nanosecs} / $day_length / MAX_NANOSECONDS() ) );
2618 }
2619 PERL
2620 # NOTE: month_0()
2621 month_0 => <<'PERL',
2622 sub month_0
2623 {
2624 if( !scalar( @_ ) )
2625 {
2626 die( 'Usage: $dt->month_0' );
2627 }
2628 my $self = shift( @_ );
2629 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2630 {
2631 die( 'Usage: $dt->month_0' );
2632 }
2633 return( $self->{local_c}->{month} - 1 );
2634 }
2635 PERL
2636 # NOTE: month_length()
2637 month_length => <<'PERL',
2638 sub month_length
2639 {
2640 if( !scalar( @_ ) )
2641 {
2642 die( 'Usage: $dt->month_length' );
2643 }
2644 my $self = shift( @_ );
2645 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2646 {
2647 die( 'Usage: $dt->month_length' );
2648 }
2649 return( $self->_month_length( $self->year, $self->month ) );
2650 }
2651 PERL
2652 # NOTE: quarter_0()
2653 quarter_0 => <<'PERL',
2654 sub quarter_0
2655 {
2656 if( !scalar( @_ ) )
2657 {
2658 die( 'Usage: $dt->quarter_0' );
2659 }
2660 my $self = shift( @_ );
2661 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2662 {
2663 die( 'Usage: $dt->quarter_0' );
2664 }
2665 return( $self->{local_c}->{quarter} - 1 );
2666 }
2667 PERL
2668 # NOTE: quarter_abbr()
2669 quarter_abbr => <<'PERL',
2670 sub quarter_abbr
2671 {
2672 if( !scalar( @_ ) )
2673 {
2674 die( 'Usage: $dt->quarter_abbr' );
2675 }
2676 my $self = shift( @_ );
2677 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2678 {
2679 die( 'Usage: $dt->quarter_abbr' );
2680 }
2681 return( $self->{locale}->quarter_format_abbreviated->[ $self->quarter_0 ] );
2682 }
2683 PERL
2684 # NOTE: quarter_length()
2685 quarter_length => <<'PERL',
2686 sub quarter_length
2687 {
2688 if( !scalar( @_ ) )
2689 {
2690 die( 'Usage: $dt->quarter_length' );
2691 }
2692 my $self = shift( @_ );
2693 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2694 {
2695 die( 'Usage: $dt->quarter_length' );
2696 }
2697 return( $self->_is_leap_year( $self->year )
2698 ? $LeapYearQuarterLengths[ $self->quarter_0 ]
2699 : $QuarterLengths[ $self->quarter_0 ] );
2700 }
2701 PERL
2702 # NOTE: quarter_name()
2703 quarter_name => <<'PERL',
2704 sub quarter_name
2705 {
2706 if( !scalar( @_ ) )
2707 {
2708 die( 'Usage: $dt->quarter_name' );
2709 }
2710 my $self = shift( @_ );
2711 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2712 {
2713 die( 'Usage: $dt->quarter_name' );
2714 }
2715 return( $self->{locale}->quarter_format_wide->[ $self->quarter_0 ] );
2716 }
2717 PERL
2718 # NOTE: secular_era()
2719 secular_era => <<'PERL',
2720 sub secular_era
2721 {
2722 if( !scalar( @_ ) )
2723 {
2724 die( 'Usage: $dt->secular_era' );
2725 }
2726 my $self = shift( @_ );
2727 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2728 {
2729 die( 'Usage: $dt->secular_era' );
2730 }
2731 $self->ce_year > 0 ? 'CE' : 'BCE'
2732 }
2733 PERL
2734 # NOTE: week_of_month()
2735 week_of_month => <<'PERL',
2736 sub week_of_month
2737 {
2738 if( !scalar( @_ ) )
2739 {
2740 die( 'Usage: $dt->week_of_month' );
2741 }
2742 my $self = shift( @_ );
2743 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2744 {
2745 die( 'Usage: $dt->week_of_month' );
2746 }
2747 my $thu = $self->day + 4 - $self->day_of_week;
2748 return( int( ( $thu + 6 ) / 7 ) );
2749 }
2750 PERL
2751 # NOTE: weekday_of_month()
2752 weekday_of_month => <<'PERL',
2753 sub weekday_of_month
2754 {
2755 if( !scalar( @_ ) )
2756 {
2757 die( 'Usage: $dt->weekday_of_month' );
2758 }
2759 my $self = shift( @_ );
2760 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2761 {
2762 die( 'Usage: $dt->weekday_of_month' );
2763 }
2764 use integer;
2765 return( ( ( $self->day - 1 ) / 7 ) + 1 );
2766 }
2767 PERL
2768 # NOTE: year_length()
2769 year_length => <<'PERL',
2770 sub year_length
2771 {
2772 if( !scalar( @_ ) )
2773 {
2774 die( 'Usage: $dt->year_length' );
2775 }
2776 my $self = shift( @_ );
2777 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2778 {
2779 die( 'Usage: $dt->year_length' );
2780 }
2781 return( $self->_is_leap_year( $self->year ) ? 366 : 365 );
2782 }
2783 PERL
2784 # NOTE: year_with_christian_era()
2785 year_with_christian_era => <<'PERL',
2786 sub year_with_christian_era
2787 {
2788 if( !scalar( @_ ) )
2789 {
2790 die( 'Usage: $dt->year_with_christian_era' );
2791 }
2792 my $self = shift( @_ );
2793 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2794 {
2795 die( 'Usage: $dt->year_with_christian_era' );
2796 }
2797 return( ( abs $self->ce_year ) . $self->christian_era );
2798 }
2799 PERL
2800 # NOTE: year_with_era()
2801 year_with_era => <<'PERL',
2802 sub year_with_era
2803 {
2804 if( !scalar( @_ ) )
2805 {
2806 die( 'Usage: $dt->year_with_era' );
2807 }
2808 my $self = shift( @_ );
2809 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2810 {
2811 die( 'Usage: $dt->year_with_era' );
2812 }
2813 return( ( abs $self->ce_year ) . $self->era_abbr );
2814 }
2815 PERL
2816 # NOTE: year_with_secular_era()
2817 year_with_secular_era => <<'PERL',
2818 sub year_with_secular_era
2819 {
2820 if( !scalar( @_ ) )
2821 {
2822 die( 'Usage: $dt->year_with_secular_era' );
2823 }
2824 my $self = shift( @_ );
2825 if( !defined( $self ) || !Scalar::Util::blessed( $self // '' ) )
2826 {
2827 die( 'Usage: $dt->year_with_secular_era' );
2828 }
2829 return( ( abs $self->ce_year ) . $self->secular_era );
2830 }
2831 PERL
2832 };
2833  
2834 3 ▶ unless( $AUTOLOAD_SUBS && CORE::scalar( CORE::keys( %$AUTOLOAD_SUBS ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DateTime::Lite::AUTOLOAD_SUBS and scalar keys %$DateTime::Lite::AUTOLOAD_SUBS) 3 0 3
Condition50%1/2
$DateTime::Lite::AUTOLOAD_SUBS and scalar keys %$DateTime::Lite::AUTOLOAD_SUBS
!ll
30
MC/DC0%0/1
$DateTime::Lite::AUTOLOAD_SUBS and scalar keys %$DateTime::Lite::AUTOLOAD_SUBS
$DateTime::Lite::AUTOLOAD_SUBS
Truth table50%1/2
A
A= $DateTime::Lite::AUTOLOAD_SUBS
Aresult
00
11
2835 {
2836 # Avoid dependency on HAS_THREADS, and make it explicit
2837 # Maybe threads were loaded at runtime ?
2838 3 ▶ if( $Config{useithreads} && $INC{'threads.pm'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Lite::Config{'useithreads'} and $INC{'threads.pm'}) { } 0 3 3
Condition33%1/3
$DateTime::Lite::Config{"useithreads"} and $INC{"threads.pm"}
!ll&&!rl&&r
300
MC/DC0%0/2
$DateTime::Lite::Config{"useithreads"} and $INC{"threads.pm"}
$DateTime::Lite::Config{"useithreads"} $INC{"threads.pm"}
Truth table33%1/3
A and B
A= $DateTime::Lite::Config{"useithreads"}B= $INC{"threads.pm"}
ABresult
0X0
100
111
2839 {
2840 0 my %tmp :shared;
2841 # Make sure the value is not undefined, before locking it.
2842 0 $AUTOLOAD_SUBS = \%tmp;
2843  
2844 # We need to catch any possible error, or they may ripple in other parts of the code and wreak havoc
2845 # try-catch
2846 0 local $@;
2847 # Get the scoped returned value from lock so it works within our block
2848 eval
2849 0 {
2850 0 CORE::lock( $AUTOLOAD_SUBS );
2851 0 ▶ unless( CORE::scalar( CORE::keys( %$AUTOLOAD_SUBS ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %$DateTime::Lite::AUTOLOAD_SUBS) 0 0 0
2852 {
2853 0 %$AUTOLOAD_SUBS = %$subs;
2854 }
2855 };
2856 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2857 {
2858 0 warn( "Error: unable to get a lock on the shared \$AUTOLOAD_SUBS: $@" );
2859 }
2860 }
2861 else
2862 {
2863 3 $AUTOLOAD_SUBS = $subs;
2864 }
2865 }
2866 3 return(1);
2867 }
2868  
2869 sub _calc_local_components
2870 226 ▶{
Subroutine _calc_local_components: called CC=1 SCAR=0.0
2871 226 my $self = shift( @_ );
2872  
2873 226 @{$self->{local_c}}{ qw( year month day day_of_week day_of_year quarter day_of_quarter ) }
2874 226 = $self->_rd2ymd( $self->{local_rd_days}, 1 );
2875  
2876 226 @{$self->{local_c}}{ qw( hour minute second ) }
2877 = $self->_seconds_as_components(
2878 $self->{local_rd_secs},
2879 $self->{utc_rd_secs},
2880 $self->{offset_modifier},
2881 226 );
2882 }
2883  
2884 sub _calc_local_rd
2885 226 ▶{
Subroutine _calc_local_rd: called CC=3 SCAR=11.0
2886 226 my $self = shift( @_ );
2887 226 delete( $self->{local_c} );
2888  
2889 226 ▶ if( $self->{tz}->is_utc || $self->{tz}->is_floating )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tz'}->is_utc or $self->{'tz'}->is_floating) { } 179 47 226
Condition100%3/3
$self->{"tz"}->is_utc or $self->{"tz"}->is_floating
l!l&&r!l&&!r
1601947
MC/DC100%2/2
$self->{"tz"}->is_utc or $self->{"tz"}->is_floating
$self->{"tz"}->is_utc $self->{"tz"}->is_floating
Truth table100%3/3
A or B
A= $self->{"tz"}->is_utcB= $self->{"tz"}->is_floating
ABresult
1X1
011
000
2890 {
2891 179 $self->{local_rd_days} = $self->{utc_rd_days};
2892 179 $self->{local_rd_secs} = $self->{utc_rd_secs};
2893 }
2894 else
2895 {
2896 47 my $offset = $self->offset;
2897 47 $self->{local_rd_days} = $self->{utc_rd_days};
2898 47 $self->{local_rd_secs} = $self->{utc_rd_secs} + $offset;
2899  
2900 $self->_normalize_tai_seconds(
2901 $self->{local_rd_days},
2902 $self->{local_rd_secs},
2903 47 );
2904 47 $self->{local_rd_secs} += $self->{offset_modifier};
2905 }
2906  
2907 226 $self->_calc_local_components;
2908 }
2909  
2910 sub _calc_utc_rd
2911 229 ▶{
Subroutine _calc_utc_rd: called CC=3 SCAR=11.0
2912 229 my $self = shift( @_ );
2913 229 delete( $self->{utc_c} );
2914  
2915 229 ▶ if( $self->{tz}->is_utc || $self->{tz}->is_floating )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tz'}->is_utc or $self->{'tz'}->is_floating) { } 195 34 229
Condition100%3/3
$self->{"tz"}->is_utc or $self->{"tz"}->is_floating
l!l&&r!l&&!r
1752034
MC/DC100%2/2
$self->{"tz"}->is_utc or $self->{"tz"}->is_floating
$self->{"tz"}->is_utc $self->{"tz"}->is_floating
Truth table100%3/3
A or B
A= $self->{"tz"}->is_utcB= $self->{"tz"}->is_floating
ABresult
1X1
011
000
2916 {
2917 195 $self->{utc_rd_days} = $self->{local_rd_days};
2918 195 $self->{utc_rd_secs} = $self->{local_rd_secs};
2919 }
2920 else
2921 {
2922 34 my $offset = $self->_offset_for_local_datetime;
2923 34 $offset += $self->{offset_modifier};
2924 34 $self->{utc_rd_days} = $self->{local_rd_days};
2925 34 $self->{utc_rd_secs} = $self->{local_rd_secs} - $offset;
2926 }
2927  
2928 $self->_normalize_tai_seconds(
2929 $self->{utc_rd_days},
2930 $self->{utc_rd_secs},
2931 229 );
2932 }
2933  
2934 sub _compare
2935 37 ▶{
Subroutine _compare: called CC=22 SCAR=40.9
2936 37 ▶ my( undef, $dt1, $dt2, $consistent ) = ref( $_[0] ) ? ( undef, @_ ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 26 11 37
2937  
2938 37 ▶ return unless( defined( $dt2 ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt2 0 37 37
2939  
2940 37 ▶ if( !ref( $dt2 ) && ( $dt2 == INFINITY || $dt2 == NEG_INFINITY ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $dt2 and $dt2 == "Inf" || $dt2 == "-Inf") 0 37 37
Condition16%1/6
not ref $dt2 and $dt2 == "Inf" || $dt2 == "-Inf"
!ll&&!rl&&r
3700
$dt2 == "Inf" or $dt2 == "-Inf"
l!l&&r!l&&!r
000
MC/DC0%0/3
not ref $dt2 and $dt2 == "Inf" || $dt2 == "-Inf"
not ref $dt2 $dt2 == "Inf" $dt2 == "-Inf"
Truth table25%1/4
not(A) and B or C
A= not ref $dt2B= $dt2 == "Inf"C= $dt2 == "-Inf"
ABCresult
0XX0
1000
11X1
1011
2941 {
2942 0 return( $dt1->{utc_rd_days} <=> $dt2 );
2943 }
2944  
2945 37 ▶ unless( $dt1->can( 'utc_rd_values' ) && $dt2->can( 'utc_rd_values' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dt1->can("utc_rd_values") and $dt2->can("utc_rd_values")) 0 37 37
Condition33%1/3
$dt1->can("utc_rd_values") and $dt2->can("utc_rd_values")
!ll&&!rl&&r
0037
MC/DC0%0/2
$dt1->can("utc_rd_values") and $dt2->can("utc_rd_values")
$dt1->can("utc_rd_values") $dt2->can("utc_rd_values")
Truth table33%1/3
A and B
A= $dt1->can("utc_rd_values")B= $dt2->can("utc_rd_values")
ABresult
0X0
100
111
2946 {
2947 0 my $s1 = overload::StrVal( $dt1 );
2948 0 my $s2 = overload::StrVal( $dt2 );
2949 0 die( "A DateTime::Lite object can only be compared to another compatible object ($s1, $s2)." );
2950 }
2951  
2952 # Short-circuit for Infinite objects before any clone/set_time_zone call: their
2953 # utc_rd_days is ±INFINITY, which overflows an XS IV parameter.
2954 # Use Perl <=> directly on the NV.
2955 # Cloning an Infinite object in pure-Perl mode requires special handling,
2956 # and Infinite objects are always UTC so floating-zone adjustment is moot.
2957 37 ▶ if( $dt1->is_infinite || $dt2->is_infinite )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt1->is_infinite or $dt2->is_infinite) 15 22 37
Condition100%3/3
$dt1->is_infinite or $dt2->is_infinite
l!l&&r!l&&!r
11422
MC/DC100%2/2
$dt1->is_infinite or $dt2->is_infinite
$dt1->is_infinite $dt2->is_infinite
Truth table100%3/3
A or B
A= $dt1->is_infiniteB= $dt2->is_infinite
ABresult
1X1
011
000
2958 {
2959 15 my @c1 = $dt1->utc_rd_values;
2960 15 my @c2 = $dt2->utc_rd_values;
2961 15 for my $i ( 0 .. 2 )
2962 {
2963 23 ▶ return( $c1[$i] <=> $c2[$i] ) if( $c1[$i] != $c2[$i] );
Branch: 1 branch
BranchTrueFalseTotal
if $c1[$i] != $c2[$i] 11 12 23
2964 }
2965 4 return(0);
2966 }
2967  
2968 22 ▶ if( !$consistent &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $consistent and $dt1->can("time_zone") and $dt2->can("time_zone")) 21 1 22
Condition66%4/6
not $consistent and $dt1->can("time_zone") and $dt2->can("time_zone")
!ll&&!rl&&r
1021
not $consistent and $dt1->can("time_zone")
!ll&&!rl&&r
1021
MC/DC33%1/3
not $consistent and $dt1->can("time_zone") and $dt2->can("time_zone")
not $consistent $dt1->can("time_zone") $dt2->can("time_zone")
Truth table50%2/4
not(A) and B and C
A= not $consistentB= $dt1->can("time_zone")C= $dt2->can("time_zone")
ABCresult
0XX0
10X0
1100
1111
2969 $dt1->can( 'time_zone' ) &&
2970 $dt2->can( 'time_zone' ) )
2971 {
2972 21 my $f1 = $dt1->time_zone->is_floating;
2973 21 my $f2 = $dt2->time_zone->is_floating;
2974 21 ▶ if( $f1 && !$f2 )
Branch: 2 branches
BranchTrueFalseTotal
if ($f1 and not $f2) { } 0 21 21
elsif ($f2 and not $f1) { } 0 42 42
Condition33%1/3
$f1 and not $f2
!ll&&!rl&&r
2100
MC/DC0%0/2
$f1 and not $f2
$f1 not $f2
Truth table33%1/3
A and not(B)
A= $f1B= not $f2
ABresult
0X0
100
111
2975 {
2976 0 $dt1 = $dt1->clone->set_time_zone( $dt2->time_zone );
2977 }
2978 ▶ elsif( $f2 && !$f1 )
Condition33%1/3
$f2 and not $f1
!ll&&!rl&&r
2100
MC/DC0%0/2
$f2 and not $f1
$f2 not $f1
Truth table33%1/3
A and not(B)
A= $f2B= not $f1
ABresult
0X0
100
111
2979 {
2980 0 $dt2 = $dt2->clone->set_time_zone( $dt1->time_zone );
2981 }
2982 }
2983  
2984 # Use XS fast-path when available
2985 22 ▶ if( !$IsPurePerl )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DateTime::Lite::IsPurePerl) 22 0 22
2986 {
2987 22 my @v1 = $dt1->utc_rd_values;
2988 22 my @v2 = $dt2->utc_rd_values;
2989 22 return( $dt1->_compare_rd( @v1, @v2 ) );
2990 }
2991  
2992 0 my @c1 = $dt1->utc_rd_values;
2993 0 my @c2 = $dt2->utc_rd_values;
2994 0 for my $i ( 0 .. 2 )
2995 {
2996 0 ▶ return( $c1[$i] <=> $c2[$i] ) if( $c1[$i] != $c2[$i] );
Branch: 1 branch
BranchTrueFalseTotal
if $c1[$i] != $c2[$i] 0 0 0
2997 }
2998 0 return(0);
2999 }
3000  
3001 sub _compare_overload
3002 22 ▶{
Subroutine _compare_overload: called CC=3 SCAR=12.0
3003 22 ▶ return unless( defined( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 22 22
3004 22 ▶ return( $_[2] ? -$_[0]->compare( $_[1] ) : $_[0]->compare( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 22 22
3005 }
3006  
3007 9 ▶sub _core_time { return( scalar( time ) ) }
Subroutine _core_time: called CC=1 SCAR=0.0
3008  
3009 sub _default_time_zone
3010 12 ▶{
Subroutine _default_time_zone: called CC=2 SCAR=7.6
3011 12 ▶ return( $ENV{PERL_DATETIME_DEFAULT_TZ} || 'floating' );
Condition50%1/2
$ENV{'PERL_DATETIME_DEFAULT_TZ'} || 'floating'
l!l
012
MC/DC0%0/1
$ENV{'PERL_DATETIME_DEFAULT_TZ'} || 'floating'
$ENV{'PERL_DATETIME_DEFAULT_TZ'}
Truth table50%1/2
A
A= $ENV{'PERL_DATETIME_DEFAULT_TZ'}
Aresult
11
00
3012 }
3013  
3014 sub _duration_object_from_args
3015 37 ▶{
Subroutine _duration_object_from_args: called CC=4 SCAR=17.1
3016 37 my $self = shift( @_ );
3017 37 ▶ return( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and builtin::blessed($_[0]) and $_[0]->isa($self->duration_class) 0 37 37
Condition33%2/6
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa($self->duration_class)
!ll&&!rl&&r
3700
@_ == 1 and builtin::blessed($_[0])
!ll&&!rl&&r
3700
MC/DC0%0/3
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa($self->duration_class)
@_ == 1 builtin::blessed($_[0]) $_[0]->isa($self->duration_class)
Truth table25%1/4
A and B and C
A= @_ == 1B= builtin::blessed($_[0])C= $_[0]->isa($self->duration_class)
ABCresult
0XX0
10X0
1100
1111
3018 if( @_ == 1 &&
3019 Scalar::Util::blessed( $_[0] ) &&
3020 $_[0]->isa( $self->duration_class ) );
3021 37 return( $self->duration_class->new( @_ ) );
3022 }
3023  
3024 3 ▶sub _era_index { $_[0]->{local_c}->{year} <= 0 ? 0 : 1 }
Subroutine _era_index: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'local_c'}{'year'} <= 0 ? : 0 3 3
3025  
3026 sub _format_nanosecs
3027 5 ▶{
Subroutine _format_nanosecs: called CC=2 SCAR=7.0
3028 5 my $self = shift( @_ );
3029 5 ▶ my $precision = shift( @_ ) // 9;
Condition50%1/2
shift @_ // 9
l!l
50
MC/DC0%0/1
shift @_ // 9
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3030 5 my $rv = sprintf( "%09d", $self->{rd_nanosecs} );
3031 5 return( substr( $rv, 0, $precision ) );
3032 }
3033  
3034 sub _handle_offset_modifier
3035 263 ▶{
Subroutine _handle_offset_modifier: called CC=19 SCAR=43.5
3036 263 my $self = shift( @_ );
3037 263 $self->{offset_modifier} = 0;
3038 263 ▶ return if( $self->{tz}->is_floating );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tz"}->is_floating 19 244 263
3039  
3040 244 my $second = shift( @_ );
3041 244 my $utc_is_valid = shift( @_ );
3042  
3043 244 my $utc_rd_days = $self->{utc_rd_days};
3044 244 ▶ my $offset = $utc_is_valid
Branch: 1 branch
BranchTrueFalseTotal
$utc_is_valid ? : 16 228 244
3045 ? $self->offset
3046 : $self->_offset_for_local_datetime;
3047  
3048 244 ▶ if( $offset >= 0 && $self->{local_rd_secs} >= $offset )
Branch: 2 branches
BranchTrueFalseTotal
if ($offset >= 0 and $self->{'local_rd_secs'} >= $offset) { } 213 31 244
elsif ($offset < 0 and $self->{'local_rd_secs'} >= 86400 + $offset) { } 0 57 57
Condition100%3/3
$offset >= 0 and $self->{"local_rd_secs"} >= $offset
!ll&&!rl&&r
526213
MC/DC100%2/2
$offset >= 0 and $self->{"local_rd_secs"} >= $offset
$offset >= 0 $self->{"local_rd_secs"} >= $offset
Truth table100%3/3
A and B
A= $offset >= 0B= $self->{"local_rd_secs"} >= $offset
ABresult
0X0
100
111
3049 {
3050 213 ▶ if( $second < 60 && $offset > 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($second < 60 and $offset > 0) { } 19 194 213
elsif ($second == 60 and $self->{'local_rd_secs'} == $offset && $offset > 0 || $offset == 0 && $self->{'local_rd_secs'} > 86399) { } 0 388 388
Condition100%3/3
$second < 60 and $offset > 0
!ll&&!rl&&r
518919
MC/DC100%2/2
$second < 60 and $offset > 0
$second < 60 $offset > 0
Truth table100%3/3
A and B
A= $second < 60B= $offset > 0
ABresult
0X0
100
111
3051 {
3052 $self->{offset_modifier}
3053 19 = $self->_day_length( $utc_rd_days - 1 ) - SECONDS_PER_DAY;
3054 19 $self->{local_rd_secs} += $self->{offset_modifier};
3055 }
3056 ▶ elsif( $second == 60 &&
Condition8%1/12
$second == 60 and $self->{"local_rd_secs"} == $offset && $offset > 0 || $offset == 0 && $self->{"local_rd_secs"} > 86399
!ll&&!rl&&r
19400
$self->{"local_rd_secs"} == $offset and $offset > 0 or $offset == 0 and $self->{"local_rd_secs"} > 86399
l!l&&r!l&&!r
000
$self->{"local_rd_secs"} == $offset and $offset > 0
!ll&&!rl&&r
000
$offset == 0 and $self->{"local_rd_secs"} > 86399
!ll&&!rl&&r
000
MC/DC0%0/5
$second == 60 and $self->{"local_rd_secs"} == $offset && $offset > 0 || $offset == 0 && $self->{"local_rd_secs"} > 86399
$second == 60 $self->{"local_rd_secs"} == $offset $offset > 0 $offset == 0 $self->{"local_rd_secs"} > 86399
Truth table12%1/8
A and B and C or D and E
A= $second == 60B= $self->{"local_rd_secs"} == $offsetC= $offset > 0D= $offset == 0E= $self->{"local_rd_secs"} > 86399
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
3057 ( ( $self->{local_rd_secs} == $offset && $offset > 0 ) ||
3058 ( $offset == 0 && $self->{local_rd_secs} > 86399 ) ) )
3059 {
3060 0 my $mod = $self->_day_length( $utc_rd_days - 1 ) - SECONDS_PER_DAY;
3061 0 ▶ unless( $mod == 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($mod == 0) 0 0 0
3062 {
3063 0 $self->{utc_rd_secs} -= $mod;
3064 0 $self->_normalize_seconds;
3065 }
3066 }
3067 }
3068 ▶ elsif( $offset < 0 &&
Condition66%2/3
$offset < 0 and $self->{"local_rd_secs"} >= 86400 + $offset
!ll&&!rl&&r
2650
MC/DC0%0/2
$offset < 0 and $self->{"local_rd_secs"} >= 86400 + $offset
$offset < 0 $self->{"local_rd_secs"} >= 86400 + $offset
Truth table66%2/3
A and B
A= $offset < 0B= $self->{"local_rd_secs"} >= 86400 + $offset
ABresult
0X0
100
111
3069 $self->{local_rd_secs} >= SECONDS_PER_DAY + $offset )
3070 {
3071 0 ▶ if( $second < 60 )
Branch: 2 branches
BranchTrueFalseTotal
if ($second < 60) { } 0 0 0
elsif ($second == 60 and $self->{'local_rd_secs'} == 86400 + $offset) { } 0 0 0
3072 {
3073 $self->{offset_modifier}
3074 0 = $self->_day_length( $utc_rd_days - 1 ) - SECONDS_PER_DAY;
3075 0 $self->{local_rd_secs} += $self->{offset_modifier};
3076 }
3077 ▶ elsif( $second == 60 &&
Condition0%0/3
$second == 60 and $self->{"local_rd_secs"} == 86400 + $offset
!ll&&!rl&&r
000
MC/DC0%0/2
$second == 60 and $self->{"local_rd_secs"} == 86400 + $offset
$second == 60 $self->{"local_rd_secs"} == 86400 + $offset
Truth table0%0/3
A and B
A= $second == 60B= $self->{"local_rd_secs"} == 86400 + $offset
ABresult
0X0
100
111
3078 $self->{local_rd_secs} == SECONDS_PER_DAY + $offset )
3079 {
3080 0 my $mod = $self->_day_length( $utc_rd_days - 1 ) - SECONDS_PER_DAY;
3081 0 ▶ unless( $mod == 0 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($mod == 0) 0 0 0
3082 {
3083 0 $self->{utc_rd_secs} -= $mod;
3084 0 $self->_normalize_seconds;
3085 }
3086 }
3087 }
3088 }
3089  
3090 # NOTE: Private helper: not a method; checks that a value is an integer (or integer-string)
3091 sub _is_integer
3092 978 ▶{
Subroutine _is_integer: called CC=3 SCAR=11.7
3093 978 my $v = shift( @_ );
3094 978 ▶ return(0) unless( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 978 978
3095 978 ▶ return( $v =~ /\A-?[0-9]+\z/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A-?[0-9]+\z/ ? : 978 0 978
3096 }
3097  
3098 sub _maybe_future_dst_warning
3099 223 ▶{
Subroutine _maybe_future_dst_warning: called CC=6 SCAR=19.6
3100 223 shift( @_ );
3101 223 my $year = shift( @_ );
3102 223 my $tz = shift( @_ );
3103 223 ▶ return unless( $year >= 5000 && $tz );
Branch: 1 branch
BranchTrueFalseTotal
unless $year >= 5000 and $tz 221 2 223
Condition66%2/3
$year >= 5000 and $tz
!ll&&!rl&&r
22102
MC/DC50%1/2
$year >= 5000 and $tz
$year >= 5000 $tz
Truth table66%2/3
A and B
A= $year >= 5000B= $tz
ABresult
0X0
100
111
3104 2 ▶ my $tz_name = ref( $tz ) ? $tz->name : $tz;
Branch: 1 branch
BranchTrueFalseTotal
ref $tz ? : 0 2 2
3105 2 ▶ return if( $tz_name eq 'floating' || $tz_name eq 'UTC' );
Branch: 1 branch
BranchTrueFalseTotal
if $tz_name eq "floating" or $tz_name eq "UTC" 2 0 2
Condition33%1/3
$tz_name eq "floating" or $tz_name eq "UTC"
l!l&&r!l&&!r
020
MC/DC0%0/2
$tz_name eq "floating" or $tz_name eq "UTC"
$tz_name eq "floating" $tz_name eq "UTC"
Truth table33%1/3
A or B
A= $tz_name eq "floating"B= $tz_name eq "UTC"
ABresult
1X1
011
000
3106 0 warnings::warnif(
3107 "Creating a DateTime::Lite with a far future year ($year) and time zone ($tz_name). "
3108 . "If the time zone has future DST changes this will be very slow."
3109 );
3110 }
3111  
3112 sub _month_length
3113 37 ▶{
Subroutine _month_length: called CC=2 SCAR=6.9
3114 37 ▶ return( $_[0]->_is_leap_year( $_[1] )
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_is_leap_year($_[1]) ? : 2 35 37
3115 ? $LeapYearMonthLengths[ $_[2] - 1 ]
3116 : $MonthLengths[ $_[2] - 1 ] );
3117 }
3118  
3119 sub _new_from_self
3120 38 ▶{
Subroutine _new_from_self: called CC=3 SCAR=11.0
3121 38 my $self = shift( @_ );
3122 38 my %p = @_;
3123  
3124 38 my %old = map { $_ => $self->$_() } qw(
3125 year month day
3126 hour minute second
3127 nanosecond locale time_zone
3128 );
3129 38 ▶ $old{formatter} = $self->formatter if( defined( $self->formatter ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->formatter 0 38 38
3130  
3131 38 ▶ my $method = delete( $p{_skip_validation} ) ? '_new' : 'new';
Branch: 1 branch
BranchTrueFalseTotal
delete $p{'_skip_validation'} ? : 30 8 38
3132 38 return( ( ref( $self ) )->$method( %old, %p ) );
3133 }
3134  
3135 sub _normalize_seconds
3136 21 ▶{
Subroutine _normalize_seconds: called CC=4 SCAR=14.0
3137 21 my $self = shift( @_ );
3138 21 ▶ return if( $self->{utc_rd_secs} >= 0 && $self->{utc_rd_secs} <= 86399 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"utc_rd_secs"} >= 0 and $self->{"utc_rd_secs"} <= 86399 7 14 21
Condition100%3/3
$self->{"utc_rd_secs"} >= 0 and $self->{"utc_rd_secs"} <= 86399
!ll&&!rl&&r
1047
MC/DC100%2/2
$self->{"utc_rd_secs"} >= 0 and $self->{"utc_rd_secs"} <= 86399
$self->{"utc_rd_secs"} >= 0 $self->{"utc_rd_secs"} <= 86399
Truth table100%3/3
A and B
A= $self->{"utc_rd_secs"} >= 0B= $self->{"utc_rd_secs"} <= 86399
ABresult
0X0
100
111
3139  
3140 14 ▶ if( $self->{tz}->is_floating )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tz'}->is_floating) { } 0 14 14
3141 {
3142 $self->_normalize_tai_seconds(
3143 $self->{utc_rd_days},
3144 $self->{utc_rd_secs},
3145 0 );
3146 }
3147 else
3148 {
3149 $self->_normalize_leap_seconds(
3150 $self->{utc_rd_days},
3151 $self->{utc_rd_secs},
3152 14 );
3153 }
3154 }
3155  
3156 sub _offset_for_local_datetime
3157 262 ▶{
Subroutine _offset_for_local_datetime: called CC=1 SCAR=0.0
3158 262 my $self = shift( @_ );
3159 262 return( $self->{tz}->offset_for_local_datetime( $self ) );
3160 }
3161  
3162 sub _resolve_time_zone
3163 272 ▶{
Subroutine _resolve_time_zone: called CC=18 SCAR=29.8
3164 272 my( $class, $locale, $time_zone ) = @_;
3165  
3166 # Explicit time_zone always takes priority
3167 272 ▶ if( defined( $time_zone ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time_zone and length $time_zone) 205 67 272
Condition66%2/3
defined $time_zone and length $time_zone
!ll&&!rl&&r
670205
MC/DC50%1/2
defined $time_zone and length $time_zone
defined $time_zone length $time_zone
Truth table66%2/3
A and B
A= defined $time_zoneB= length $time_zone
ABresult
0X0
100
111
3168 length( $time_zone ) )
3169 {
3170 205 return( $time_zone );
3171 }
3172  
3173 # Try to infer from the BCP47 -u-tz- locale extension.
3174 # Must be done BEFORE passing the locale to _set_locale, because
3175 # DateTime::Locale::FromCLDR->new() calls $locale->core which strips all -u-
3176 # extensions, making them inaccessible afterwards.
3177 # Three cases handled:
3178 # 1. Plain string: instantiate a temporary Locale::Unicode to read ->tz
3179 # 2. Locale::Unicode object: ->tz is directly accessible
3180 # 3. DateTime::Locale::FromCLDR object: core() has already stripped
3181 # the -u- extensions, so tz will be undef; but this may change in
3182 # the future so we try it out anyway.
3183 67 my $tz_code;
3184 67 ▶ if( defined( $locale ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (defined $locale and not ref $locale and length $locale) { } 10 57 67
elsif (defined $locale and builtin::blessed($locale) and $locale->isa('Locale::Unicode')) { } 1 56 57
elsif (defined $locale and builtin::blessed($locale) and $locale->isa('DateTime::Locale::FromCLDR') and $locale->can('locale')) { } 43 26 69
Condition83%5/6
defined $locale and not ref $locale and length $locale
!ll&&!rl&&r
57010
defined $locale and not ref $locale
!ll&&!rl&&r
134410
MC/DC66%2/3
defined $locale and not ref $locale and length $locale
defined $locale not ref $locale length $locale
Truth table75%3/4
A and not(B) and C
A= defined $localeB= not ref $localeC= length $locale
ABCresult
0XX0
10X0
1100
1111
3185 !ref( $locale ) &&
3186 length( $locale ) )
3187 {
3188 10 require Locale::Unicode;
3189 # Plain string: parse it to get the -u-tz- extension
3190 10 my $loc = Locale::Unicode->new( $locale );
3191 10 ▶ $tz_code = $loc->tz if( $loc );
Branch: 1 branch
BranchTrueFalseTotal
if $loc 10 0 10
3192 }
3193 ▶ elsif( defined( $locale ) &&
Condition83%5/6
defined $locale and builtin::blessed($locale) and $locale->isa("Locale::Unicode")
!ll&&!rl&&r
13431
defined $locale and builtin::blessed($locale)
!ll&&!rl&&r
13044
MC/DC66%2/3
defined $locale and builtin::blessed($locale) and $locale->isa("Locale::Unicode")
defined $locale builtin::blessed($locale) $locale->isa("Locale::Unicode")
Truth table75%3/4
A and B and C
A= defined $localeB= builtin::blessed($locale)C= $locale->isa("Locale::Unicode")
ABCresult
0XX0
10X0
1100
1111
3194 Scalar::Util::blessed( $locale ) &&
3195 $locale->isa( 'Locale::Unicode' ) )
3196 {
3197 # Already a Locale::Unicode object; extensions are intact
3198 1 $tz_code = $locale->tz;
3199 }
3200 ▶ elsif( defined( $locale ) &&
Condition66%6/9
defined $locale and builtin::blessed($locale) and $locale->isa("DateTime::Locale::FromCLDR") and $locale->can("locale")
!ll&&!rl&&r
13043
defined $locale and builtin::blessed($locale) and $locale->isa("DateTime::Locale::FromCLDR")
!ll&&!rl&&r
13043
defined $locale and builtin::blessed($locale)
!ll&&!rl&&r
13043
MC/DC25%1/4
defined $locale and builtin::blessed($locale) and $locale->isa("DateTime::Locale::FromCLDR") and $locale->can("locale")
defined $locale builtin::blessed($locale) $locale->isa("DateTime::Locale::FromCLDR") $locale->can("locale")
Truth table40%2/5
A and B and C and D
A= defined $localeB= builtin::blessed($locale)C= $locale->isa("DateTime::Locale::FromCLDR")D= $locale->can("locale")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3201 Scalar::Util::blessed( $locale ) &&
3202 $locale->isa( 'DateTime::Locale::FromCLDR' ) &&
3203 $locale->can( 'locale' ) )
3204 {
3205 # DateTime::Locale::FromCLDR object. core() has already stripped
3206 # the -u- extensions, so tz will be undef; but this may change in
3207 # the future so we try it out anyway.
3208 43 $tz_code = $locale->locale->tz;
3209 }
3210  
3211 67 ▶ if( defined( $tz_code ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz_code and length $tz_code) 10 57 67
Condition66%2/3
defined $tz_code and length $tz_code
!ll&&!rl&&r
57010
MC/DC50%1/2
defined $tz_code and length $tz_code
defined $tz_code length $tz_code
Truth table66%2/3
A and B
A= defined $tz_codeB= length $tz_code
ABresult
0X0
100
111
3212 length( $tz_code ) )
3213 {
3214 10 require Locale::Unicode;
3215 10 my $names = Locale::Unicode->tz_id2names( $tz_code );
3216 10 ▶ return( $names->[0] ) if( $names && scalar( @$names ) );
Branch: 1 branch
BranchTrueFalseTotal
if $names and scalar @$names 10 0 10
Condition50%1/2
$names and scalar @$names
!ll
010
MC/DC0%0/1
$names and scalar @$names
$names
Truth table50%1/2
A
A= $names
Aresult
00
11
3217 }
3218  
3219 # Nothing found: return undef and let the caller decide the fallback
3220 57 return;
3221 }
3222  
3223 sub _set_get_prop
3224 4 ▶{
Subroutine _set_get_prop: called CC=3 SCAR=11.4
3225 4 my $self = shift( @_ );
3226 4 ▶ my $prop = shift( @_ ) || die( "No object property was provided." );
Condition50%1/2
shift @_ || die('No object property was provided.')
l!l
40
MC/DC0%0/1
shift @_ || die('No object property was provided.')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
3227 4 ▶ $self->{ $prop } = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
3228 4 return( $self->{ $prop } );
3229 }
3230  
3231 sub _set_locale
3232 213 ▶{
Subroutine _set_locale: called CC=6 SCAR=17.9
3233 213 my $self = shift( @_ );
3234 213 my $locale = shift( @_ );
3235  
3236 # Assuming this is either DateTime::Locale::FromData or DateTime::Locale::FromCLDR
3237 # But we need better check than this. However, if we check too strictly, we
3238 # might break things.
3239 213 ▶ if( defined( $locale ) && Scalar::Util::blessed( $locale ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $locale and builtin::blessed($locale)) { } 83 130 213
elsif (defined $locale) { } 18 112 130
Condition100%3/3
defined $locale and builtin::blessed($locale)
!ll&&!rl&&r
1121883
MC/DC100%2/2
defined $locale and builtin::blessed($locale)
defined $locale builtin::blessed($locale)
Truth table100%3/3
A and B
A= defined $localeB= builtin::blessed($locale)
ABresult
0X0
100
111
3240 {
3241 83 $self->{locale} = $locale;
3242 }
3243 elsif( defined( $locale ) )
3244 {
3245 # If this is an unblessed reference, return an error
3246 18 ▶ return( $self->error( "Locale provided (", overload::StrVal( $locale ), ") is not a string." ) )
Branch: 1 branch
BranchTrueFalseTotal
if ref $locale 1 17 18
3247 if( ref( $locale ) );
3248 17 ▶ $locale = DateTime::Locale::FromCLDR->new( $locale ) ||
Condition50%1/2
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
l!l
170
MC/DC0%0/1
'DateTime::Locale::FromCLDR'->new($locale) || (return $self->pass_error('DateTime::Locale::FromCLDR'->error))
'DateTime::Locale::FromCLDR'->new($locale)
Truth table50%1/2
A
A= 'DateTime::Locale::FromCLDR'->new($locale)
Aresult
11
00
3249 return( $self->pass_error( DateTime::Locale::FromCLDR->error ) );
3250 }
3251 else
3252 {
3253 112 $locale = $self->DefaultLocale;
3254 }
3255 212 return( $self->{locale} = $locale );
3256 }
3257  
3258 sub _string_compare_overload
3259 2 ▶{
Subroutine _string_compare_overload: called CC=3 SCAR=14.2
3260 2 my( $dt1, $dt2, $flip ) = @_;
3261 2 ▶ if( !$dt2->can( 'utc_rd_values' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $dt2->can('utc_rd_values')) { } 0 2 2
3262 {
3263 0 ▶ my $sign = $flip ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$flip ? : 0 0 0
3264 0 return( $sign * ( "$dt1" cmp "$dt2" ) );
3265 }
3266 else
3267 {
3268 2 my $meth = $dt1->can( '_compare_overload' );
3269 2 goto $meth;
3270 }
3271 }
3272  
3273 sub _string_equals_overload
3274 5 ▶{
Subroutine _string_equals_overload: called CC=6 SCAR=22.8
3275 5 ▶ my( $class, $dt1, $dt2 ) = ref( $_[0] ) ? ( undef, @_ ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 5 0 5
3276 5 ▶ return( "$dt1" eq "$dt2" ) unless( $dt2 && Scalar::Util::blessed( $dt2 ) && $dt2->can( 'utc_rd_values' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $dt2 and builtin::blessed($dt2) and $dt2->can("utc_rd_values") 0 5 5
Condition33%2/6
$dt2 and builtin::blessed($dt2) and $dt2->can("utc_rd_values")
!ll&&!rl&&r
005
$dt2 and builtin::blessed($dt2)
!ll&&!rl&&r
005
MC/DC0%0/3
$dt2 and builtin::blessed($dt2) and $dt2->can("utc_rd_values")
$dt2 builtin::blessed($dt2) $dt2->can("utc_rd_values")
Truth table25%1/4
A and B and C
A= $dt2B= builtin::blessed($dt2)C= $dt2->can("utc_rd_values")
ABCresult
0XX0
10X0
1100
1111
3277 5 ▶ $class ||= ref( $dt1 );
Condition33%1/3
$class ||= ref $dt1
l!l&&r!l&&!r
050
MC/DC0%0/2
$class ||= ref $dt1
$class ref $dt1
Truth table33%1/3
A ||= B
A= $classB= ref $dt1
ABresult
1X1
011
000
3278 5 return( !$class->compare( $dt1, $dt2 ) );
3279 }
3280  
3281 0 ▶sub _string_not_equals_overload { return( !_string_equals_overload( @_ ) ) }
Subroutine _string_not_equals_overload: not called CC=1 SCAR=6.9
3282  
3283 sub _subtract_overload
3284 2 ▶{
Subroutine _subtract_overload: called CC=6 SCAR=20.5
3285 2 my( $date1, $date2, $reversed ) = @_;
3286 2 ▶ ( $date2, $date1 ) = ( $date1, $date2 ) if( $reversed );
Branch: 1 branch
BranchTrueFalseTotal
if $reversed 0 2 2
3287  
3288 2 ▶ if( Scalar::Util::blessed( $date2 ) && $date2->isa( 'DateTime::Lite::Duration' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($date2) and $date2->isa('DateTime::Lite::Duration')) { } 1 1 2
elsif (builtin::blessed($date2) and $date2->can('utc_rd_values')) { } 1 0 1
Condition66%2/3
builtin::blessed($date2) and $date2->isa("DateTime::Lite::Duration")
!ll&&!rl&&r
011
MC/DC50%1/2
builtin::blessed($date2) and $date2->isa("DateTime::Lite::Duration")
builtin::blessed($date2) $date2->isa("DateTime::Lite::Duration")
Truth table66%2/3
A and B
A= builtin::blessed($date2)B= $date2->isa("DateTime::Lite::Duration")
ABresult
0X0
100
111
3289 {
3290 1 my $new = $date1->clone;
3291 1 $new->add_duration( $date2->inverse );
3292 1 return( $new );
3293 }
3294 ▶ elsif( Scalar::Util::blessed( $date2 ) && $date2->can( 'utc_rd_values' ) )
Condition33%1/3
builtin::blessed($date2) and $date2->can("utc_rd_values")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($date2) and $date2->can("utc_rd_values")
builtin::blessed($date2) $date2->can("utc_rd_values")
Truth table33%1/3
A and B
A= builtin::blessed($date2)B= $date2->can("utc_rd_values")
ABresult
0X0
100
111
3295 {
3296 1 return( $date1->subtract_datetime( $date2 ) );
3297 }
3298 else
3299 {
3300 0 my $class = ref( $date1 );
3301 0 my $dt_string = overload::StrVal( $date1 );
3302 0 die( "Cannot subtract $date2 from a $class object ($dt_string). Only a DateTime::Lite::Duration or compatible object can be subtracted." );
3303 }
3304 }
3305  
3306 # Algorithm from https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date
3307 # Pure arithmetic - no clone, no add(), no risk of recursion.
3308 sub _week_values
3309 4 ▶{
Subroutine _week_values: called CC=4 SCAR=17.3
3310 4 my $self = shift( @_ );
3311  
3312 4 my $week = int( ( ( $self->day_of_year - $self->day_of_week ) + 10 ) / 7 );
3313 4 my $year = $self->year;
3314  
3315 4 ▶ if( $week == 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($week == 0) { } 0 4 4
elsif ($week == 53 and $self->_weeks_in_year($year) == 52) { } 0 8 8
3316 {
3317 0 $year--;
3318 0 return( [ $year, $self->_weeks_in_year( $year ) ] );
3319 }
3320 ▶ elsif( $week == 53 && $self->_weeks_in_year( $year ) == 52 )
Condition33%1/3
$week == 53 and $self->_weeks_in_year($year) == 52
!ll&&!rl&&r
400
MC/DC0%0/2
$week == 53 and $self->_weeks_in_year($year) == 52
$week == 53 $self->_weeks_in_year($year) == 52
Truth table33%1/3
A and B
A= $week == 53B= $self->_weeks_in_year($year) == 52
ABresult
0X0
100
111
3321 {
3322 0 return( [ $year + 1, 1 ] );
3323 }
3324  
3325 4 return( [ $year, $week ] );
3326 }
3327  
3328 sub _weeks_in_year
3329 0 ▶{
Subroutine _weeks_in_year: not called CC=4 SCAR=30.0
3330 0 my $self = shift( @_ );
3331 0 my $year = shift( @_ );
3332  
3333 # Day-of-week of January 1st (0=Mon..6=Sun in RD modulo)
3334 0 my $dow = $self->_ymd2rd( $year, 1, 1 ) % 7;
3335  
3336 # Years starting on Thursday, and leap years starting on Wednesday,
3337 # have 53 ISO weeks.
3338 0 ▶ return( ( $dow == 4 || ( $dow == 3 && $self->_is_leap_year( $year ) ) )
Branch: 1 branch
BranchTrueFalseTotal
$dow == 4 || $dow == 3 && $self->_is_leap_year($year) ? : 0 0 0
Condition0%0/6
$dow == 4 or $dow == 3 and $self->_is_leap_year($year)
l!l&&r!l&&!r
000
$dow == 3 and $self->_is_leap_year($year)
!ll&&!rl&&r
000
MC/DC0%0/3
$dow == 4 or $dow == 3 and $self->_is_leap_year($year)
$dow == 4 $dow == 3 $self->_is_leap_year($year)
Truth table0%0/4
A or B and C
A= $dow == 4B= $dow == 3C= $self->_is_leap_year($year)
ABCresult
1XX1
0111
00X0
0100
3339 ? 53
3340 : 52 );
3341 }
3342  
3343 16 1;
3344  
3345 # NOTE: Minimal thaw helper (mirrors DateTime::_Thawed)
3346 # NOTE: DateTime::Lite::_Thawed class
3347 package DateTime::Lite::_Thawed;
3348  
3349 6 ▶sub time_zone { $_[0]->{tz} }
Subroutine time_zone: called CC=1 SCAR=0.0
3350 2 ▶sub utc_rd_values { @{ $_[0]->{utc_vals} } }
Subroutine utc_rd_values: called CC=1 SCAR=0.0
3351  
3352 {
3353 # NOTE: DateTime::Lite::NullObject class
3354 package
3355 DateTime::Lite::NullObject;
3356 BEGIN
3357 {
3358 16 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3359 16 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3360 16 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
3361 0 ▶ '""' => sub{ '' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3362 16 fallback => 1,
3363 16 );
3364 16 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
3365 };
3366 16 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3367 16 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3368  
3369 sub new
3370 0 ▶ {
Subroutine new: not called CC=3 SCAR=24.8
3371 0 my $this = shift( @_ );
3372 0 ▶ my $ref = @_ ? { @_ } : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
3373 0 ▶ return( bless( $ref => ( ref( $this ) || $this ) ) );
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
3374 }
3375  
3376 sub AUTOLOAD
3377 0 ▶ {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
3378 0 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
3379 0 my $self = shift( @_ );
3380 0 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 0 0
3381 {
3382 0 rreturn( $self );
3383 }
3384 # Otherwise, we return undef; Empty return returns undef in scalar context and empty list in list context
3385 0 return;
3386 };
3387 }
3388  
3389 16 1;
3390 # NOTE: POD
3391 __END__
« lib/DateTime/Lite/TimeZone.pm ↑ Summary lib/DateTime/Lite/Exception.pm »