package Common::Date::FrenchText;

use utf8;
use Common::UTF8;

use base 'Common::Date';

sub priority { 800 }
sub type     { 'french_text' }

sub _monthIndex {
    {
        "janvier"   => 1,
        "janv"      => 1,
        "fevrier"   => 2,
        "fevr"      => 2,
        "mars"      => 3,
        "avril"     => 4,
        "mai"       => 5,
        "juin"      => 6,
        "juillet"   => 7,
        "juil"      => 7,
        "aout"      => 8,
        "septembre" => 9,
        "sept"      => 9,
        "octobre"   => 10,
        "oct"       => 10,
        "novembre"  => 11,
        "nov"       => 11,
        "decembre"  => 12,
        "dec"       => 12

    };
}

sub _patterns {
    my $self = shift;
    my @months;

    foreach my $month ( keys( %{ $self->_monthIndex } ) ) {
        push( @months, $month );
    }

    return [
        new Common::Date::Pattern( pattern => '(' . join( '|',           @months ) . ') (\d{2,4})', month => 1, year => 2 ),
        new Common::Date::Pattern( pattern => '(\d{2,4}) (' . join( '|', @months ) . ')',           month => 2, year => 1 ),
    ];
}

sub month {
    my $self = shift;

    my $month = Common::UTF8::ToAscii( lc( $self->{_month} ) );
    $month =~ s/\s//g;

    my $index = $self->_monthIndex();

    return $index->{$month};
}

sub year {
    my $self = shift;

    if ( $self->{_year} && $self->{_year} =~ /^\d{2}$/ ) {
        return "20$self->{_year}";
    } else {
        return $self->{_year};
    }
}

1;
