Date-Parse-Lite
view release on metacpan or search on metacpan
t/01-parse.t view on Meta::CPAN
$parser->prefer_month_first_order(0);
test_date_parser($parser, "$expected:$day/$month/$year");
test_date_parser($parser, sprintf "$expected:%04i%02i%02i", $year, $month, $day);
}
}
}
use utf8;
my $non_ascii_month = 'áéÃóú';
no utf8;
$fixtures = <<"EOT";
1/1/2015:1firstmonth2015
1/1/2015:1primero2015
20/12/2015:20lastmonth2015
20/12/2015:20doce2015
20/3/2015:20${non_ascii_month}2015
EOT
foreach my $fixture (split "\n", $fixtures) {
$fixture =~ /:(.+)$/;
test_date_parser($parser, ":$1");
}
$parser->month_names(firstmonth => 1);
$parser->month_names(primero => 1, lastmonth => 12, doce => 12, ${non_ascii_month} => 3);
no utf8;
test_date_parser($parser, $_) foreach (split "\n", $fixtures);
foreach my $two_digit_year_fixture (@two_digit_year_fixtures) {
my($test_year, $expected_year) = @$two_digit_year_fixture;
test_date_parser($parser, "21/6/$expected_year:21/06/$test_year");
$parser->literal_years_below_100(1);
test_date_parser($parser, "21/6/$test_year:21/06/$test_year");
$parser->literal_years_below_100(0);
}
$parser = Date::Parse::Lite->new(
prefer_month_first_order => 0,
literal_years_below_100 => 1,
month_names => [ first => 1, last => 12 ],
date => '2/3/4',
);
is($parser->month, 3, "Can initialise prefer_month_first_order");
is($parser->year, 4, "Can initialise literal_years_below_100");
$fixtures = <<EOT;
1/1/15:1first15
1/2/2015:1/2/2015
20/12/15:20last15
20/12/15:12/20/15
20/12/2015:20last2015
EOT
test_date_parser($parser, $_) foreach (split "\n", $fixtures);
sub test_date_parser {
my($parser, $fixture) = @_;
my($date, $string) = split m{\s*:\s*}, $fixture, 2;
my($d, $m, $y) = split m{\s*/\s*}, $date;
$parser->parse($string);
if($parser->parsed) {
ok($date ne '', "parsed, as expected: $string");
is($parser->day, $d, "Extracted day '$d': $string");
is($parser->month, $m, "Extracted month '$m': $string");
is($parser->year, $y, "Extracted year '$y': $string");
}
else {
ok($date eq '', "parse fail was expected: $string");
}
}
( run in 1.214 second using v1.01-cache-2.11-cpan-71847e10f99 )