The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

use strict;
use MARC::Convert::Wikidata::Utils qw(clean_date);
use Test::More 'tests' => 13;
use Unicode::UTF8 qw(decode_utf8 encode_utf8);
# Test.
my $input_date = '2020.';
my $ret = clean_date($input_date);
is($ret, 2020, "Date '$input_date' after cleanup.");
# Test.
$input_date = decode_utf8('2020 př. Kr.');
$ret = clean_date($input_date);
is($ret, -2020, encode_utf8("Date '$input_date' after cleanup."));
# Test.
$input_date = decode_utf8('20 po. Kr.');
$ret = clean_date($input_date);
is($ret, 20, encode_utf8("Date '$input_date' after cleanup."));
# Test.
$input_date = decode_utf8('2020 březen 03.');
$ret = clean_date($input_date);
is($ret, '2020-03-03', encode_utf8("Date '$input_date' after cleanup."));
# Test.
$input_date = decode_utf8('2020 leden 3.');
$ret = clean_date($input_date);
is($ret, '2020-01-3', encode_utf8("Date '$input_date' after cleanup."));
# Test.
$input_date = undef;
$ret = clean_date($input_date);
is($ret, undef, encode_utf8("Undefined date after cleanup."));
# Test.
$input_date = 'c2002';
($ret, my $options_hr) = clean_date($input_date);
is($ret, 2002, encode_utf8("Date '$input_date' after cleanup."));
is_deeply(
$options_hr,
{
'circa' => 1,
},
"Date '$input_date' has option 'circa'."
);
# Test.
$input_date = 'asi 2002';
($ret, $options_hr) = clean_date($input_date);
is($ret, 2002, encode_utf8("Date '$input_date' after cleanup."));
is_deeply(
$options_hr,
{
'circa' => 1,
},
"Date '$input_date' has option 'circa'."
);
# Test.
$input_date = decode_utf8('asi 2510 př. Kr.');
($ret, $options_hr) = clean_date($input_date);
is($ret, -2510, encode_utf8("Date '$input_date' after cleanup."));
is_deeply(
$options_hr,
{
'circa' => 1,
},
encode_utf8("Date '$input_date' has option 'circa'.")
);