use strict; use warnings; use Time::Piece; use Test::More tests => 6; my $FMT = '%Y-%m-%d'; # ISO dates my @less = ('2018-03-01', '2019-07-20', '2019-08-07'); my @more = ('2020-03-01', '2019-09-20', '2019-08-20'); for (@less) { ok within_2_months ($_), "$_ is not more than 2 months in the future"; } for (@more) { ok !within_2_months ($_), "$_ is more than 2 months in the future"; } sub within_2_months { my $now = localtime (time); BAIL_OUT "Ach, you're too late. Should have run this earlier" if $now > Time::Piece->strptime ('2019-06-20', $FMT); my $then = Time::Piece->strptime (shift, $FMT); return $then < $now->add_months(2); }