DatesRole: Adding parse_vague_string_to_date; needs fleshing out
parent
28b6d07f3a
commit
702451fade
|
@ -154,4 +154,25 @@ sub date_output_string {
|
|||
return $string;
|
||||
}
|
||||
|
||||
# Parses a really vague description and basically guesses
|
||||
sub parse_vague_string_to_date {
|
||||
my ($string) = @_;
|
||||
if($string =~ qr#(?:(?<q>next|last)\s(?<m1>$full_month|$short_month))|(?:(?<m2>$full_month|$short_month)\s(?<y>[0-9]{4}))|(?<m3>$full_month|$short_month)#i) {
|
||||
if ($+{m1} && $+{q}) {
|
||||
# TODO: implement
|
||||
# next january
|
||||
# last january
|
||||
}
|
||||
}
|
||||
elsif ($+{m2} && $+{y}) {
|
||||
return parse_string_to_date("01 $+{m2} $+{y}");
|
||||
}
|
||||
elsif ($+{m3}) {
|
||||
# TODO: implement
|
||||
# the nearest january
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
13
t/00-roles.t
13
t/00-roles.t
|
@ -233,6 +233,19 @@ subtest 'Dates' => sub {
|
|||
is($result, '', '... and yields an empty string as a result');
|
||||
}
|
||||
};
|
||||
subtest 'Vague strings' => sub {
|
||||
my %strings = (
|
||||
#'next december' => '',
|
||||
#'last january' => '',
|
||||
#'june' => '',
|
||||
'december 2015' => '',
|
||||
'june 2000' => ''
|
||||
);
|
||||
foreach my $test_date (sort keys %strings) {
|
||||
my $result = RoleTester::parse_vague_string_to_date($test_date);
|
||||
isa_ok($result, 'DateTime', $test_date);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue