Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make .later not die on day-of-month overflow
  • Loading branch information
Carl Masak committed Aug 23, 2015
1 parent ac34880 commit 4288450
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/core/Temporal.pm
Expand Up @@ -373,7 +373,14 @@ my class DateTime does Dateish {
$month += $amount;
$year += floor(($month - 1) / 12);
$month = ($month - 1) % 12 + 1;
$date = Date.new(:$year, :$month, :$!day);
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++;
}
$date = Date.new(:$year, :$month, :$day);
succeed;
}

Expand Down Expand Up @@ -605,7 +612,14 @@ my class Date does Dateish {
$month += $amount;
$year += floor(($month - 1) / 12);
$month = ($month - 1) % 12 + 1;
$date = self.new(:$year, :$month, :$!day);
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++;
}
$date = Date.new(:$year, :$month, :$day);
succeed;
}

Expand Down

0 comments on commit 4288450

Please sign in to comment.