use warnings;
use strict;
use feature qw(say);
my @MONTH_ADJUST = qw(3 0 3 2 3 2 3 3 2 3 2 3);
sub leap_adjust {
my $year = shift;
return ($year % 4 == 0) && ($year % 100 != 0) || ($year % 400 == 0) ? 1 : 0;
}
sub last_day_of_month {
my ($year, $month) = (@_);
return 28 + ($month == 2 ? leap_adjust($year) : 0) + $MONTH_ADJUST[$month-1];
}
sub date_add {
my ($iso_date, $days) = (@_);
my @date = split(/-/, $iso_date);
return $iso_date;
}
say last_day_of_month(2016,2);
say last_day_of_month(2016,12);
say last_day_of_month(2017,2);
say last_day_of_month(2017,12);
my $date = "2017-10-12";
my $days = 150;
say "A $days days from $date is " . date_add($date, $days);