#!/usr/bin/perl -w

use strict;
use DateTime;
use DateTime::Format::Strptime;

my $strp = DateTime::Format::Strptime->new(
    pattern => '%Y-%m-%d'
    );


my %batailles = ( 
    'f' => { start => '1914-08-07', end => '1914-08-23'}, # Bataille des frontières
    'm' => { start => '1914-09-05', end => '1914-09-12'}, # Marne
    'C' => { start => '1914-09-13', end => '1914-11-13'}, # Chemin des dames
    'a' => { start => '1915-05-09', end => '1915-06-25'}, # Artois
    'c' => { start => '1915-09-25', end => '1915-10-06'}, # Champagne
    '.' => { start => '1916-02-21', end => '1916-12-18'}, # Verdun
    's' => { start => '1916-07-01', end => '1916-11-18'}, # Somme
    '1C' => { start => '1917-04-16', end => '1917-04-17'}, # Chemin des dames
    '2M' => { start => '1918-05-27', end => '1918-08-06'}, # Marne
    );

my %dates = ();

foreach my $b (keys %batailles) {
    my $ds = $strp->parse_datetime($batailles{$b}->{start});
    my $de = $strp->parse_datetime($batailles{$b}->{end});
    my $des = $strp->format_datetime($de);
    while (1) {
        my $c = $strp->format_datetime($ds);
        #print "$c,$b\n";
        $dates{$c}.=$b;
        last if ( $c eq $des );
        $ds->add(days => 1);
    }

};

print "Date,Bataille\n";
foreach my $d (sort keys %dates) {
        my $b = ($dates{$d} eq '2M')?'m':($dates{$d} eq '1C')?'C':$dates{$d};
        print "$d,$b\n";
}
