From 294bf4d47eec328145ba8185265d883fc788349e Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Fri, 15 Dec 2017 15:01:53 +0100
Subject: [PATCH] more granularity in dates

---
 bin/account-manager.pl.in        | 8 ++++----
 conf/create-manager-db.sql       | 8 ++++----
 lib/AccountManager/Account.pm    | 4 ++--
 lib/AccountManager/Token.pm      | 8 ++++----
 lib/AccountManager/WebRequest.pm | 8 ++++----
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/bin/account-manager.pl.in b/bin/account-manager.pl.in
index 7e12682..04f06db 100755
--- a/bin/account-manager.pl.in
+++ b/bin/account-manager.pl.in
@@ -103,8 +103,8 @@ sub add_account {
         scope           => $configuration->{idp}->{scope},
         password        => $password,
         password_hash   => AccountManager::Tools::sha256_hash($password),
-        creation_date   => DateTime->today(),
-        expiration_date => DateTime->today()->add(days => $validity_period)
+        creation_date   => DateTime->now(),
+        expiration_date => DateTime->now()->add(days => $validity_period)
     );
 
     die "Failed to save test account\n"
@@ -329,8 +329,8 @@ sub add_token {
         db              => $db,
         email_address   => $options{email_address},
         sp_entityid     => $options{sp_entityid},
-        creation_date   => DateTime->today(),
-        expiration_date => DateTime->today()->add(hours => $validity_period),
+        creation_date   => DateTime->now(),
+        expiration_date => DateTime->now()->add(hours => $validity_period),
         token           => AccountManager::Tools::generate_token()
     );
 
diff --git a/conf/create-manager-db.sql b/conf/create-manager-db.sql
index 908ab0e..43158aa 100644
--- a/conf/create-manager-db.sql
+++ b/conf/create-manager-db.sql
@@ -11,8 +11,8 @@ CREATE TABLE `tokens` (
   `token` varchar(50) NOT NULL,
   `email_address` varchar(200) NOT NULL,
   `sp_entityid` varchar(200) NOT NULL,
-  `creation_date` date DEFAULT NULL,
-  `expiration_date` date DEFAULT NULL,
+  `creation_date` datetime DEFAULT NULL,
+  `expiration_date` datetime DEFAULT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `token_2` (`token`),
   KEY `token` (`token`),
@@ -31,8 +31,8 @@ CREATE TABLE `services` (
 CREATE TABLE `accounts` (
   `id` bigint(20) NOT NULL AUTO_INCREMENT,
   `password_hash` varchar(50) NOT NULL,
-  `creation_date` date DEFAULT NULL,
-  `expiration_date` date DEFAULT NULL,
+  `creation_date` datetime DEFAULT NULL,
+  `expiration_date` datetime DEFAULT NULL,
   `profile` varchar(100) NOT NULL,
   `scope` varchar(100) NOT NULL,
   `sp_entityid` varchar(250) NOT NULL,
diff --git a/lib/AccountManager/Account.pm b/lib/AccountManager/Account.pm
index 7052eb8..4c329f0 100644
--- a/lib/AccountManager/Account.pm
+++ b/lib/AccountManager/Account.pm
@@ -12,8 +12,8 @@ __PACKAGE__->meta->setup(
         id              => { type => 'bigserial', not_null => 1 },
         password_hash   => { type => 'varchar', length => 50, not_null => 1 },
         password        => { type => 'varchar', length => 50, nonpersistent => 1 },
-        creation_date   => { type => 'date' },
-        expiration_date => { type => 'date' },
+        creation_date   => { type => 'datetime' },
+        expiration_date => { type => 'datetime' },
         profile         => { type => 'varchar', length => 100, not_null => 1 },
         scope           => { type => 'varchar', length => 100, not_null => 1 },
         sp_entityid     => { type => 'varchar', length => 250, not_null => 1 },
diff --git a/lib/AccountManager/Token.pm b/lib/AccountManager/Token.pm
index b44bc5f..5e4a944 100644
--- a/lib/AccountManager/Token.pm
+++ b/lib/AccountManager/Token.pm
@@ -13,8 +13,8 @@ __PACKAGE__->meta->setup(
         token           => { type => 'varchar', length => 50, not_null => 1 },
         email_address   => { type => 'varchar', length => 200, not_null => 1 },
         sp_entityid     => { type => 'varchar', length => 200, not_null => 1 },
-        creation_date   => { type => 'date' },
-        expiration_date => { type => 'date' },
+        creation_date   => { type => 'datetime' },
+        expiration_date => { type => 'datetime' },
     ],
 
     primary_key_columns => [ 'id' ],
@@ -35,8 +35,8 @@ sub print {
         $self->token(),
         $self->email_address(),
         $self->sp_entityid(),
-        $self->creation_date()->strftime('%Y:%m:%d'),
-        $self->expiration_date()->strftime('%Y:%m:%d');
+        $self->creation_date()->strftime('%Y:%m:%d %H:%M'),
+        $self->expiration_date()->strftime('%Y:%m:%d %H:%M');
 }
 
 1;
diff --git a/lib/AccountManager/WebRequest.pm b/lib/AccountManager/WebRequest.pm
index 2f4cf54..0447fe1 100644
--- a/lib/AccountManager/WebRequest.pm
+++ b/lib/AccountManager/WebRequest.pm
@@ -345,8 +345,8 @@ sub req_generate_token {
         db              => $self->{db},
         email_address   => $self->{in}->{email_address},
         sp_entityid     => $self->{in}->{sp_entityid},
-        creation_date   => DateTime->today(),
-        expiration_date => DateTime->today()->add(hours => $validity_period),
+        creation_date   => DateTime->now(),
+        expiration_date => DateTime->now()->add(hours => $validity_period),
         token           => AccountManager::Tools::generate_token()
     );
 
@@ -480,8 +480,8 @@ sub req_validate_token {
             scope           => $self->{configuration}->{idp}->{scope},
             password        => $password,
             password_hash   => AccountManager::Tools::sha256_hash($password),
-            creation_date   => DateTime->today(),
-            expiration_date => DateTime->today()->add(days => $validity_period)
+            creation_date   => DateTime->now(),
+            expiration_date => DateTime->now()->add(days => $validity_period)
         );
         next unless $account->save();
         push @accounts, $account;
-- 
GitLab