#!perl
use strict;
use Test::More (tests => 61);
BEGIN
{
    use_ok("DateTime::Format::Japanese");
}

my @params = (
    [
        "平成１６年１月３日",
        DateTime->new(year => 2004, month => 1, day => 3)
    ],
    [
        "平成１６年１月３日午前５時",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5)
    ],
    [
        "平成１６年１月３日午前５時３０分",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5, minute => 30)
    ],
    [
        "平成１６年１月３日午前５時３０分２９秒",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5, minute => 30, second => 29)
    ],
    [
        "平成１６年１月３日午後５時３０分２９秒",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 17, minute => 30, second => 29)
    ],
    [
        "平成１６年１月３日午後５時３０分２９秒土曜日",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 17, minute => 30, second => 29)
    ],
    [
        "平成十六年一月三日",
        DateTime->new(year => 2004, month => 1, day => 3)
    ],
    [
        "平成十六年一月三日午前五時",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5)
    ],
    [
        "平成十六年一月三日午前五時三〇分",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5, minute => 30)
    ],
    [
        "平成十六年一月三日午前五時三〇分二九秒",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5, minute => 30, second => 29)
    ],
    [
        "平成一六年一月三日午後五時三〇分二九秒",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 17, minute => 30, second => 29)
    ],
    [
        "平成16年1月3日",
        DateTime->new(year => 2004, month => 1, day => 3)
    ],
    [
        "平成16年1月3日午前5時",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5)
    ],
    [
        "平成16年1月3日午前5時30分",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5, minute => 30)
    ],
    [
        "平成16年1月3日午前5時30分29秒",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 5, minute => 30, second => 29)
    ],
    [
        "平成16年1月3日午後5時30分29秒",
        DateTime->new(year => 2004, month => 1, day => 3, hour => 17, minute => 30, second => 29)
    ],
    [
        "1989年3月7日",
        DateTime->new(year => 1989, month => 3, day => 7)
    ],
    [
        "1989年3月7日13時",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13)
    ],
    [
        "1989年3月7日13時37分",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13, minute => 37)
    ],
    [
        "1989年3月7日13時37分18秒",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13, minute => 37, second => 18)
    ],
    [
        "一九八九年三月七日",
        DateTime->new(year => 1989, month => 3, day => 7)
    ],
    [
        "一九八九年三月七日一三時",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13)
    ],
    [
        "一九八九年三月七日一三時三十七分",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13, minute => 37)
    ],
    [
        "一九八九年三月七日一三時三十七分十八秒",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13, minute => 37, second => 18)
    ],
    [
        "西暦1989年3月7日13時37分18秒",
        DateTime->new(year => 1989, month => 3, day => 7, hour => 13, minute => 37, second => 18)
    ],
    [
        "紀元前1989年3月7日",
        DateTime->new(year => -1989, month => 3, day => 7)
    ],
    [
        "紀元前1989年3月7日13時",
        DateTime->new(year => -1989, month => 3, day => 7, hour => 13)
    ],
    [
        "紀元前1989年3月7日13時37分",
        DateTime->new(year => -1989, month => 3, day => 7, hour => 13, minute => 37)
    ],
    [
        "紀元前1989年3月7日13時37分18秒",
        DateTime->new(year => -1989, month => 3, day => 7, hour => 13, minute => 37, second => 18)
    ],
    [
        "紀元前西暦1989年3月7日13時37分18秒",
        DateTime->new(year => -1989, month => 3, day => 7, hour => 13, minute => 37, second => 18)
    ],
);

my $dt;
foreach my $param (@params) {
    $dt = eval { DateTime::Format::Japanese->parse_datetime($param->[0]) };
    ok($dt);
    SKIP:{
        skip("parse_datetime raised exception or didn't return a DateTime object: $@", 1) if !$dt;
        is( $dt->compare($param->[1]), 0, "Test parse_datetime($param->[0]) = " . $param->[1]->datetime);
    }
}


