1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/perl
use strict;
use warnings;
use DateTime::Format::Natural;
use DateTime::Format::Natural::Test qw(_result_string);
use Test::More tests => 9;
my @iso8601 = (
{ '2016T12' => '01.01.2016 12:00:00' },
{ '2016T12:12' => '01.01.2016 12:12:00' },
{ '2016T12:12:11' => '01.01.2016 12:12:11' },
{ '2016-06T12' => '01.06.2016 12:00:00' },
{ '2016-06T12:12' => '01.06.2016 12:12:00' },
{ '2016-06T12:12:11' => '01.06.2016 12:12:11' },
{ '2016-06-19T12' => '19.06.2016 12:00:00' },
{ '2016-06-19T12:12' => '19.06.2016 12:12:00' },
{ '2016-06-19T12:12:11' => '19.06.2016 12:12:11' },
);
compare(\@iso8601);
sub compare
{
my $aref = shift;
foreach my $href (@$aref) {
my $key = (keys %$href)[0];
compare_strings($key, $href->{$key});
}
}
sub compare_strings
{
my ($string, $result) = @_;
my $parser = DateTime::Format::Natural->new;
my $dt = $parser->parse_datetime($string);
if ($parser->success && $parser->_get_truncated) {
is(_result_string($dt), $result, $string);
}
else {
fail($string);
}
}
|