diff --git a/lib/DDG/Goodie/RandomDate.pm b/lib/DDG/Goodie/RandomDate.pm index 6da1ae34e32..ea083b08d4f 100644 --- a/lib/DDG/Goodie/RandomDate.pm +++ b/lib/DDG/Goodie/RandomDate.pm @@ -83,7 +83,9 @@ handle query => sub { return if $range_text && $range_type eq 'none'; my ($min_date, $max_date) = parse_range($range_type, $lang->locale, $range_text); return if $range_text && !(defined $min_date && defined $max_date); - my $random_date = get_random_date($lang->locale, $min_date, $max_date); + my $random_date = get_random_date( + $lang->locale, $min_date, $max_date + ) or return; my ($formatted, $min_date_formatted, $max_date_formatted) = map { format_date($format, $_, $force_cldr); } ($random_date, $min_date, $max_date); @@ -144,6 +146,7 @@ my $MIN_DATE = -62_167_219_200; sub get_random_date { my ($locale, $min_date, $max_date) = @_; my $range = abs($max_date->epoch - $min_date->epoch); + return if $range == 0; my $rand_num = int(rand($range)); my $rand_epoch = $min_date->epoch + $rand_num; return DateTime->from_epoch( diff --git a/t/RandomDate.t b/t/RandomDate.t index 3f10bda9dc3..6983b752b73 100644 --- a/t/RandomDate.t +++ b/t/RandomDate.t @@ -180,6 +180,7 @@ ddg_goodie_test( 'random date between 2005-06-10 and 2006-06-11' => build_range_test( 'Date', 'Jun 10, 2005', 'Jun 11, 2006', ), + 'random date between 2005-06-10 and 2005-06-10' => undef, 'random date between' => undef, 'random date between now and bar' => undef, 'random date between now' => undef,