From 6ed1a681fc16dfcb91b48b4ec4d13f237d456e5b Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Tue, 17 Feb 2015 17:50:20 +0100
Subject: [PATCH] correct date insertion

---
 Sam/commands/add.pm    | 6 +++---
 Sam/commands/parser.pm | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Sam/commands/add.pm b/Sam/commands/add.pm
index 9e09295..bef7466 100644
--- a/Sam/commands/add.pm
+++ b/Sam/commands/add.pm
@@ -13,17 +13,17 @@ our $log;
 
 sub exec {
     my ($chanName, $title, $day, $month, $year, $place, $desc) = @_;
-    my $timestamp = timelocal(0, 59, 23, $day, $month - 1, $year);
 
-    my $chan = Sam::Chan->new(name => $chanName);
+    $year += 2000 if ($year < 2000);
 
+    my $chan = Sam::Chan->new(name => $chanName);
     unless ($chan->load(speculative => 1)) {
         die "ce chan n'est pas encore configuré";
     }
 
     my $event = Sam::Event->new(
         title       => $title,
-        date        => $timestamp,
+        date        => "$year-$month-$day 23:59:00",
         place       => $place,
         description => $desc,
         calendar    => $chan->calendar
diff --git a/Sam/commands/parser.pm b/Sam/commands/parser.pm
index 4024c0e..9fa8ec9 100644
--- a/Sam/commands/parser.pm
+++ b/Sam/commands/parser.pm
@@ -60,6 +60,8 @@ sub exec {
             =xi) {
         my (undef, undef, undef, undef, $current_mon, $current_year, undef, undef, undef) =
             localtime(time);
+        $current_mon++; # localtime returns month between 0 and 11
+        $current_year += 1900; # same shit
 
         my ($title, $place, $desc) = ($+{'title'}, $+{'place'}, $+{'desc'});
         my ($day, $month, $year) = ($+{'day'}, $+{'month'} || $current_mon, $+{'year'} || $current_year);
-- 
GitLab