Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
clip to end of month instead of overflow to next
ShimmerFairy++ for the suggestion. This simplifies the logic a bit.
  • Loading branch information
Carl Masak committed Aug 23, 2015
1 parent 4288450 commit d6bf551
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/core/Temporal.pm
Expand Up @@ -373,13 +373,9 @@ my class DateTime does Dateish {
$month += $amount;
$year += floor(($month - 1) / 12);
$month = ($month - 1) % 12 + 1;
my $day = $!day;
# If we overflow on days in the month, rather than throw an
# exception, we just clip to the 1st of the next month
if $day > $.days-in-month($year, $month) {
$day = 1;
$month++;
}
# exception, we just clip to the last of the month
my $day = $!day min $.days-in-month($year, $month);
$date = Date.new(:$year, :$month, :$day);
succeed;
}
Expand Down Expand Up @@ -612,13 +608,9 @@ my class Date does Dateish {
$month += $amount;
$year += floor(($month - 1) / 12);
$month = ($month - 1) % 12 + 1;
my $day = $!day;
# If we overflow on days in the month, rather than throw an
# exception, we just clip to the 1st of the next month
if $day > $.days-in-month($year, $month) {
$day = 1;
$month++;
}
# exception, we just clip to the last of the month
my $day = $!day min $.days-in-month($year, $month);
$date = Date.new(:$year, :$month, :$day);
succeed;
}
Expand Down

0 comments on commit d6bf551

Please sign in to comment.