| 1 | |||||||||||||||||||||||||||||||||||||||||||
| 2 | package DateTimeX::Lite; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 18 | ▶ | use overload ( 'fallback' => 1, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | '-' => '_subtract_overload', | ||||||||||||||||||||||||||||||||||||||||||
| 9 | '+' => '_add_overload', | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 18 | ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub subtract_datetime | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subtract_datetime: called CC=21 SCAR=30.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 51 | my $dt1 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 51 | my $dt2 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 51 | ▶ | $dt2 = $dt2->clone->set_time_zone( $dt1->time_zone ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | unless $dt1->time_zone->name eq $dt2->time_zone->name; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # We only want a negative duration if $dt2 > $dt1 ($self) | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 51 | ▶ | my ( $bigger, $smaller, $negative ) = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | ( $dt1 >= $dt2 ? | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ( $dt1, $dt2, 0 ) : | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ( $dt2, $dt1, 1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 51 | ▶ | my $is_floating = $dt1->time_zone->is_floating && | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$dt1->time_zone->is_floating && $dt2->time_zone->is_floating
MC/DC50%1/2
$dt1->time_zone->is_floating && $dt2->time_zone->is_floating
$dt1->time_zone->is_floating
$dt2->time_zone->is_floating
Truth table66%2/3
A && B
A= $dt1->time_zone->is_floatingB= $dt2->time_zone->is_floating
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | $dt2->time_zone->is_floating; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 51 | my $minute_length = 60; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 51 | ▶ | unless ($is_floating) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 39 | my ( $utc_rd_days, $utc_rd_secs ) = $smaller->utc_rd_values; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 39 | ▶ | if ( $utc_rd_secs >= 86340 && ! $is_floating ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$utc_rd_secs >= 86340 and not $is_floating
MC/DC50%1/2
$utc_rd_secs >= 86340 and not $is_floating
$utc_rd_secs >= 86340
not $is_floating
Truth table66%2/3
A and not(B)
A= $utc_rd_secs >= 86340B= not $is_floating
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # If the smaller of the two datetimes occurs in the last | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # UTC minute of the UTC day, then that minute may not be | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # 60 seconds long. If we need to subtract a minute from | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # the larger datetime's minutes count in order to adjust | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # the seconds difference to be positive, we need to know | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # how long that minute was. If one of the datetimes is | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # floating, we just assume a minute is 60 seconds. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | $minute_length = DateTimeX::Lite::LeapSecond::day_length($utc_rd_days) - 86340; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # This is a gross hack that basically figures out if the bigger of | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # the two datetimes is the day of a DST change. If it's a 23 hour | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # day (switching _to_ DST) then we subtract 60 minutes from the | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # local time. If it's a 25 hour day then we add 60 minutes to the | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # local time. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # This produces the most "intuitive" results, though there are | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # still reversibility problems with the resultant duration. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # However, if the two objects are on the same (local) date, and we | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # are not crossing a DST change, we don't want to invoke the hack | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # - see 38local-subtract.t | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 51 | my $bigger_min = $bigger->hour * 60 + $bigger->minute; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 51 | ▶ | if ( $bigger->time_zone->has_dst_changes | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$bigger->time_zone->has_dst_changes and $bigger->ymd ne $smaller->ymd || $bigger->is_dst != $smaller->is_dst
$bigger->ymd ne $smaller->ymd or $bigger->is_dst != $smaller->is_dst
MC/DC100%3/3
$bigger->time_zone->has_dst_changes and $bigger->ymd ne $smaller->ymd || $bigger->is_dst != $smaller->is_dst
$bigger->time_zone->has_dst_changes
$bigger->ymd ne $smaller->ymd
$bigger->is_dst != $smaller->is_dst
Truth table100%4/4
A and B or C
A= $bigger->time_zone->has_dst_changesB= $bigger->ymd ne $smaller->ymdC= $bigger->is_dst != $smaller->is_dst
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | && ( $bigger->ymd ne $smaller->ymd | ||||||||||||||||||||||||||||||||||||||||||
| 66 | || $bigger->is_dst != $smaller->is_dst ) | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | $bigger_min -= 60 | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # it's a 23 hour (local) day | ||||||||||||||||||||||||||||||||||||||||||
| 72 | if ( $bigger->is_dst | ||||||||||||||||||||||||||||||||||||||||||
| 73 | && | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | ▶ | do { local $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$bigger->is_dst and do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && !$prev_day->is_dst ? 1 : 0
}
MC/DC100%2/2
$bigger->is_dst and do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && !$prev_day->is_dst ? 1 : 0
}
$bigger->is_dst
do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && !$prev_day->is_dst ? 1 : 0
}
Truth table100%3/3
A and B
A= $bigger->is_dstB= do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && !$prev_day->is_dst ? 1 : 0
}
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | my $prev_day = eval { $bigger->clone->subtract( days => 1 ) }; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | ▶ | $prev_day && ! $prev_day->is_dst ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev_day and not $prev_day->is_dst
MC/DC100%2/2
$prev_day and not $prev_day->is_dst
$prev_day
not $prev_day->is_dst
Truth table100%3/3
A and not(B)
A= $prev_dayB= not $prev_day->is_dst
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | $bigger_min += 60 | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # it's a 25 hour (local) day | ||||||||||||||||||||||||||||||||||||||||||
| 81 | if ( ! $bigger->is_dst | ||||||||||||||||||||||||||||||||||||||||||
| 82 | && | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 13 | ▶ | do { local $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $bigger->is_dst and do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && $prev_day->is_dst ? 1 : 0
}
MC/DC100%2/2
not $bigger->is_dst and do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && $prev_day->is_dst ? 1 : 0
}
not $bigger->is_dst
do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && $prev_day->is_dst ? 1 : 0
}
Truth table100%3/3
not(A) and B
A= not $bigger->is_dstB= do {
local $@;
my $prev_day = eval {
do {
$bigger->clone->subtract("days", 1)
}
};
$prev_day && $prev_day->is_dst ? 1 : 0
}
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | my $prev_day = eval { $bigger->clone->subtract( days => 1 ) }; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | $prev_day && $prev_day->is_dst ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev_day and $prev_day->is_dst
MC/DC50%1/2
$prev_day and $prev_day->is_dst
$prev_day
$prev_day->is_dst
Truth table66%2/3
A and B
A= $prev_dayB= $prev_day->is_dst
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 51 | my ( $months, $days, $minutes, $seconds, $nanoseconds ) = | |||||||||||||||||||||||||||||||||||||||||
| 90 | $dt1->_adjust_for_positive_difference | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ( $bigger->year * 12 + $bigger->month, $smaller->year * 12 + $smaller->month, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | $bigger->day, $smaller->day, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | $bigger_min, $smaller->hour * 60 + $smaller->minute, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | $bigger->second, $smaller->second, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | $bigger->nanosecond, $smaller->nanosecond, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | $minute_length, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # XXX - using the smaller as the month length is | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # somewhat arbitrary, we could also use the bigger - | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # either way we have reversibility problems | ||||||||||||||||||||||||||||||||||||||||||
| 106 | DateTimeX::Lite::Util::month_length( $smaller->year, $smaller->month ), | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 51 | ▶ | if ($negative) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 16 | for ( $months, $days, $minutes, $seconds, $nanoseconds ) | |||||||||||||||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # Some versions of Perl can end up with -0 if we do "0 * -1"!! | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 80 | ▶ | $_ *= -1 if $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | return | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 51 | DateTimeX::Lite::Duration->new | |||||||||||||||||||||||||||||||||||||||||
| 120 | ( months => $months, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | days => $days, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | minutes => $minutes, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | seconds => $seconds, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | nanoseconds => $nanoseconds, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | sub _adjust_for_positive_difference | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 55 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_adjust_for_positive_difference: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 55 | my ( $self, | |||||||||||||||||||||||||||||||||||||||||
| 131 | $month1, $month2, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | $day1, $day2, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | $min1, $min2, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | $sec1, $sec2, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | $nano1, $nano2, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | $minute_length, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | $month_length, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 55 | ▶ | if ( $nano1 < $nano2 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | $sec1--; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | $nano1 += &DateTimeX::Lite::MAX_NANOSECONDS; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 55 | ▶ | if ( $sec1 < $sec2 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | $min1--; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | $sec1 += $minute_length; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # A day always has 24 * 60 minutes, though the minutes may vary in | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # length. | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 55 | ▶ | if ( $min1 < $min2 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | $day1--; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | $min1 += 24 * 60; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 55 | ▶ | if ( $day1 < $day2 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | $month1--; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | $day1 += $month_length; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 55 | return ( $month1 - $month2, | |||||||||||||||||||||||||||||||||||||||||
| 167 | $day1 - $day2, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | $min1 - $min2, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $sec1 - $sec2, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | $nano1 - $nano2, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | sub subtract_datetime_absolute | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subtract_datetime_absolute: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 8 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 8 | my $utc_rd_secs1 = $self->utc_rd_as_seconds; | |||||||||||||||||||||||||||||||||||||||||
| 180 | $utc_rd_secs1 += DateTimeX::Lite::LeapSecond::leap_seconds( $self->{utc_rd_days} ) | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 8 | ▶ | if ! $self->time_zone->is_floating; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 8 | my $utc_rd_secs2 = $dt->utc_rd_as_seconds; | |||||||||||||||||||||||||||||||||||||||||
| 184 | $utc_rd_secs2 += DateTimeX::Lite::LeapSecond::leap_seconds( $dt->{utc_rd_days} ) | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 8 | ▶ | if ! $dt->time_zone->is_floating; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 8 | my $seconds = $utc_rd_secs1 - $utc_rd_secs2; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | my $nanoseconds = $self->nanosecond - $dt->nanosecond; | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | ▶ | if ( $nanoseconds < 0 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | $seconds--; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | $nanoseconds += &DateTimeX::Lite::MAX_NANOSECONDS; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | return | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | DateTimeX::Lite::Duration->new | |||||||||||||||||||||||||||||||||||||||||
| 198 | ( seconds => $seconds, | ||||||||||||||||||||||||||||||||||||||||||
| 199 | nanoseconds => $nanoseconds, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | sub delta_md | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delta_md: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | my ( $smaller, $bigger ) = sort $self, $dt; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | my ( $months, $days, undef, undef, undef ) = | |||||||||||||||||||||||||||||||||||||||||
| 211 | $dt->_adjust_for_positive_difference | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ( $bigger->year * 12 + $bigger->month, $smaller->year * 12 + $smaller->month, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | $bigger->day, $smaller->day, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0, 0, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0, 0, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0, 0, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 60, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | DateTimeX::Lite::Util::month_length( $smaller->year, $smaller->month ), | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | return DateTimeX::Lite::Duration->new( months => $months, | |||||||||||||||||||||||||||||||||||||||||
| 228 | days => $days ); | ||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | sub delta_days | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delta_days: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | my ( $smaller, $bigger ) = sort( ($self->local_rd_values)[0], ($dt->local_rd_values)[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | DateTimeX::Lite::Duration->new( days => $bigger - $smaller ); | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | sub delta_ms | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delta_ms: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | my ( $smaller, $greater ) = sort $self, $dt; | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | my $days = int( $greater->jd - $smaller->jd ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | my $dur = $greater->subtract_datetime($smaller); | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | my %p; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | $p{hours} = $dur->hours + ( $days * 24 ); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | $p{minutes} = $dur->minutes; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 3 | $p{seconds} = $dur->seconds; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | return DateTimeX::Lite::Duration->new(%p); | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | sub _add_overload | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 4866 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_overload: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 4866 | my ( $dt, $dur, $reversed ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 4866 | ▶ | if ($reversed) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ( $dur, $dt ) = ( $dt, $dur ); | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 4866 | ▶ | unless ( blessed $dur && $dur->isa( 'DateTimeX::Lite::Duration' ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($dur) and $dur->isa("DateTimeX::Lite::Duration")
MC/DC100%2/2
builtin::blessed($dur) and $dur->isa("DateTimeX::Lite::Duration")
builtin::blessed($dur)
$dur->isa("DateTimeX::Lite::Duration")
Truth table100%3/3
A and B
A= builtin::blessed($dur)B= $dur->isa("DateTimeX::Lite::Duration")
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | my $class = ref $dt; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | my $dt_string = overload::StrVal($dt); | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | Carp::croak( "Cannot add $dur to a $class object ($dt_string).\n" | |||||||||||||||||||||||||||||||||||||||||
| 275 | . " Only a DateTimeX::Lite::Duration object can " | ||||||||||||||||||||||||||||||||||||||||||
| 276 | . " be added to a $class object." ); | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 4864 | return $dt->clone->add_duration($dur); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | sub _subtract_overload | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 1357 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_subtract_overload: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 1357 | my ( $date1, $date2, $reversed ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 1357 | ▶ | if ($reversed) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ( $date2, $date1 ) = ( $date1, $date2 ); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 1357 | ▶ | if ( blessed $date2 && $date2->isa( 'DateTimeX::Lite::Duration' ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
builtin::blessed($date2) and $date2->isa("DateTimeX::Lite::Duration")
MC/DC100%2/2
builtin::blessed($date2) and $date2->isa("DateTimeX::Lite::Duration")
builtin::blessed($date2)
$date2->isa("DateTimeX::Lite::Duration")
Truth table100%3/3
A and B
A= builtin::blessed($date2)B= $date2->isa("DateTimeX::Lite::Duration")
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 1336 | my $new = $date1->clone; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 1336 | $new->add_duration( $date2->inverse ); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 1336 | return $new; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | ▶ | elsif ( blessed $date2 && $date2->isa( 'DateTimeX::Lite' ) ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::blessed($date2) and $date2->isa("DateTimeX::Lite")
MC/DC100%2/2
builtin::blessed($date2) and $date2->isa("DateTimeX::Lite")
builtin::blessed($date2)
$date2->isa("DateTimeX::Lite")
Truth table100%3/3
A and B
A= builtin::blessed($date2)B= $date2->isa("DateTimeX::Lite")
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 19 | return $date1->subtract_datetime($date2); | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | else | ||||||||||||||||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | my $class = ref $date1; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | my $dt_string = overload::StrVal($date1); | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | Carp::croak( "Cannot subtract $date2 from a $class object ($dt_string).\n" | |||||||||||||||||||||||||||||||||||||||||
| 307 | . " Only a DateTimeX::Lite::Duration or DateTimeX::Lite object can " | ||||||||||||||||||||||||||||||||||||||||||
| 308 | . " be subtracted from a $class object." ); | ||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 620 | ▶ | sub add { return shift->add_duration( DateTimeX::Lite::Duration->new(@_) ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 54 | ▶ | sub subtract { return shift->subtract_duration( DateTimeX::Lite::Duration->new(@_) ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subtract: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 71 | ▶ | sub subtract_duration { return $_[0]->add_duration( $_[1]->inverse ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subtract_duration: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | sub add_duration | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 6960 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_duration: called CC=23 SCAR=31.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 6960 | my ($self, $dur) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 6960 | ▶ | if (! blessed $dur || !$dur->isa('DateTimeX::Lite::Duration')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($dur) and $dur->isa("DateTimeX::Lite::Duration")
MC/DC0%0/2
builtin::blessed($dur) and $dur->isa("DateTimeX::Lite::Duration")
builtin::blessed($dur)
$dur->isa("DateTimeX::Lite::Duration")
Truth table33%1/3
A and B
A= builtin::blessed($dur)B= $dur->isa("DateTimeX::Lite::Duration")
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | Carp::croak("Duration is not a DateTimeX::Lite::Duration object"); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # simple optimization | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 6960 | ▶ | return $self if $dur->is_zero; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 6960 | my %deltas = $dur->deltas; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | # This bit isn't quite right since DateTimeX::Lite::Infinite::Future - | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # infinite duration should NaN | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 6960 | foreach my $val ( values %deltas ) | |||||||||||||||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 34792 | my $inf; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 34792 | ▶ | if ( $val == &DateTimeX::Lite::INFINITY ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $inf = DateTimeX::Lite::Infinite::Future->new; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | elsif ( $val == &DateTimeX::Lite::NEG_INFINITY ) | ||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | $inf = DateTimeX::Lite::Infinite::Past->new; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 34792 | ▶ | if ($inf) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | %$self = %$inf; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | bless $self, blessed $inf; | |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 6958 | ▶ | return $self if $self->is_infinite; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 6954 | ▶ | if ( $deltas{days} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 3867 | $self->{local_rd_days} += $deltas{days}; | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 3867 | $self->{utc_year} += int( $deltas{days} / 365 ) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 6954 | ▶ | if ( $deltas{months} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # For preserve mode, if it is the last day of the month, make | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # it the 0th day of the following month (which then will | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # normalize back to the last day of the new month). | ||||||||||||||||||||||||||||||||||||||||||
| 367 | my ($y, $m, $d) = ( $dur->is_preserve_mode ? | ||||||||||||||||||||||||||||||||||||||||||
| 368 | DateTimeX::Lite::Util::rd2ymd( $self->{local_rd_days} + 1 ) : | ||||||||||||||||||||||||||||||||||||||||||
| 369 | DateTimeX::Lite::Util::rd2ymd( $self->{local_rd_days} ) | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 575 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 575 | ▶ | $d -= 1 if $dur->is_preserve_mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 575 | ▶ | if ( ! $dur->is_wrap_mode && $d > 28 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $dur->is_wrap_mode and $d > 28
MC/DC100%2/2
not $dur->is_wrap_mode and $d > 28
not $dur->is_wrap_mode
$d > 28
Truth table100%3/3
not(A) and B
A= not $dur->is_wrap_modeB= $d > 28
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||
| 376 | # find the rd for the last day of our target month | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | $self->{local_rd_days} = DateTimeX::Lite::Util::ymd2rd( $y, $m + $deltas{months} + 1, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # what day of the month is it? (discard year and month) | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | my $last_day = (DateTimeX::Lite::Util::rd2ymd( $self->{local_rd_days} ))[2]; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | # if our original day was less than the last day, | ||||||||||||||||||||||||||||||||||||||||||
| 383 | # use that instead | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | $self->{local_rd_days} -= $last_day - $d if $last_day > $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | else | ||||||||||||||||||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 574 | $self->{local_rd_days} = DateTimeX::Lite::Util::ymd2rd( $y, $m + $deltas{months}, $d ); | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 575 | $self->{utc_year} += int( $deltas{months} / 12 ) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 6954 | ▶ | if ( $deltas{days} || $deltas{months} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$deltas{"days"} or $deltas{"months"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | { | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 4440 | $self->_calc_utc_rd; | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 4437 | $self->_handle_offset_modifier( $self->second ); | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 6951 | ▶ | if ( $deltas{minutes} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | { | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 85 | $self->{utc_rd_secs} += $deltas{minutes} * 60; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | # This intentionally ignores leap seconds | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 85 | DateTimeX::Lite::Util::normalize_tai_seconds( $self->{utc_rd_days}, $self->{utc_rd_secs} ); | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 6951 | ▶ | if ( $deltas{seconds} || $deltas{nanoseconds} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$deltas{"seconds"} or $deltas{"nanoseconds"}
MC/DC100%2/2
$deltas{"seconds"} or $deltas{"nanoseconds"}
$deltas{"seconds"}
$deltas{"nanoseconds"}
Truth table100%3/3
A or B
A= $deltas{"seconds"}B= $deltas{"nanoseconds"}
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | { | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 2452 | $self->{utc_rd_secs} += $deltas{seconds}; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 2452 | ▶ | if ( $deltas{nanoseconds} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | $self->{rd_nanosecs} += $deltas{nanoseconds}; | |||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | DateTimeX::Lite::Util::normalize_nanoseconds( $self->{utc_rd_secs}, $self->{rd_nanosecs} ); | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 2452 | DateTimeX::Lite::Util::normalize_seconds($self); | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | # This might be some big number much bigger than 60, but | ||||||||||||||||||||||||||||||||||||||||||
| 422 | # that's ok (there are tests in 19leap_second.t to confirm | ||||||||||||||||||||||||||||||||||||||||||
| 423 | # that) | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 2452 | $self->_handle_offset_modifier( $self->second + $deltas{seconds} ); | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | my $new = | ||||||||||||||||||||||||||||||||||||||||||
| 428 | (ref $self)->from_object | ||||||||||||||||||||||||||||||||||||||||||
| 429 | ( object => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 430 | locale => $self->{locale}, | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 6951 | ▶ | ( $self->{formatter} ? ( formatter => $self->{formatter} ) : () ), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 6951 | %$self = %$new; | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 6951 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||