From 4ef26443006e095cdb822a8743589940475b01a9 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Thu, 27 Aug 2020 10:29:23 +0200 Subject: [PATCH] Use date.lib.php functions --- htdocs/comm/action/card.php | 14 +++++++------- htdocs/core/lib/date.lib.php | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index d05b0914254..9ab1cf3366a 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -393,20 +393,20 @@ if (empty($reshook) && $action == 'add') $actionCommReminder = new ActionCommReminder($db); if($offsetunit == 'minute'){ - $dateremind = strtotime("-".$offsetvalue." minutes", $datep); + $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'i'); } elseif($offsetunit == 'hour'){ - $dateremind = strtotime("-".$offsetvalue." hours", $datep); + $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'h'); } elseif ($offsetunit == 'day') { - $dateremind = strtotime("-".$offsetvalue." day", $datep); + $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'd'); } elseif ($offsetunit == 'week') { - $dateremind = strtotime("-".$offsetvalue." week", $datep); + $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'w'); } elseif ($offsetunit == 'month') { - $dateremind = strtotime("-".$offsetvalue." month", $datep); + $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'm'); } elseif ($offsetunit == 'year') { - $dateremind = strtotime("-".$offsetvalue." year", $datep); + $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'y'); } - $actionCommReminder->dateremind = date('Y-m-d H:i:s', $dateremind); + $actionCommReminder->dateremind = $db->idate($dateremind); $actionCommReminder->typeremind = $remindertype; $actionCommReminder->fk_user = $user; $actionCommReminder->offsetunit = $offsetunit; diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 22f99312520..1c7ff2cf20e 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -108,7 +108,7 @@ function getServerTimeZoneInt($refgmtdate = 'now') * * @param int $time Date timestamp (or string with format YYYY-MM-DD) * @param int $duration_value Value of delay to add - * @param int $duration_unit Unit of added delay (d, m, y, w, h) + * @param int $duration_unit Unit of added delay (d, m, y, w, h, i) * @return int New timestamp */ function dol_time_plus_duree($time, $duration_value, $duration_unit) @@ -116,6 +116,7 @@ function dol_time_plus_duree($time, $duration_value, $duration_unit) global $conf; if ($duration_value == 0) return $time; + if ($duration_unit == 'i') return $time + (60 * $duration_value); if ($duration_unit == 'h') return $time + (3600 * $duration_value); if ($duration_unit == 'w') return $time + (3600 * 24 * 7 * $duration_value);