From 5801c329b2246ad63f95a77eee0041e8f8c8bff0 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 20 Apr 2021 19:27:12 +0300 Subject: [PATCH] datetime refactoring --- application/Espo/Core/Utils/DateTime.php | 18 ++++++++++++------ application/Espo/Core/Utils/ScheduledJob.php | 4 ++-- application/Espo/Core/Webhook/Queue.php | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/application/Espo/Core/Utils/DateTime.php b/application/Espo/Core/Utils/DateTime.php index 5934ee6ba4..2cefdaecf0 100644 --- a/application/Espo/Core/Utils/DateTime.php +++ b/application/Espo/Core/Utils/DateTime.php @@ -36,11 +36,15 @@ use Exception; use DateTime as DateTimeStd; /** - * Util for a date-time formatting and convetion. + * Util for a date-time formatting and conversion. * Available as 'dateTime' service. */ class DateTime { + public const SYSTEM_DATE_TIME_FORMAT = 'Y-m-d H:i:s'; + + public const SYSTEM_DATE_FORMAT = 'Y-m-d'; + protected $dateFormat; protected $timeFormat; @@ -49,13 +53,15 @@ class DateTime protected $langauge; - public static $systemDateTimeFormat = 'Y-m-d H:i:s'; + /** @deprecated */ + public static $systemDateTimeFormat = self::SYSTEM_DATE_TIME_FORMAT; - public static $systemDateFormat = 'Y-m-d'; + /** @deprecated */ + public static $systemDateFormat = self::SYSTEM_DATE_FORMAT; - protected $internalDateTimeFormat = 'Y-m-d H:i:s'; + protected $internalDateTimeFormat = self::SYSTEM_DATE_TIME_FORMAT; - protected $internalDateFormat = 'Y-m-d'; + protected $internalDateFormat = self::SYSTEM_DATE_FORMAT; protected $dateFormats = [ 'MM/DD/YYYY' => 'm/d/Y', @@ -258,6 +264,6 @@ class DateTime public static function getSystemNowString(): string { - return date(self::$systemDateTimeFormat); + return date(self::SYSTEM_DATE_TIME_FORMAT); } } diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index b9374c1558..bd51038422 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -123,7 +123,7 @@ class ScheduledJob $r2From = new DateTime('-1 hour'); $r2To = new DateTime(); - $format = DateTimeUtil::$systemDateTimeFormat; + $format = DateTimeUtil::SYSTEM_DATE_TIME_FORMAT; $selectParams = [ 'select' => ['id'], @@ -131,7 +131,7 @@ class ScheduledJob 'whereClause' => [ 'OR' => [ [ - ['executedAt>=' => $r2From->format($format)] , + ['executedAt>=' => $r2From->format($format)], ['executedAt<=' => $r2To->format($format)], ], [ diff --git a/application/Espo/Core/Webhook/Queue.php b/application/Espo/Core/Webhook/Queue.php index ed875ecc21..c68dbd650e 100644 --- a/application/Espo/Core/Webhook/Queue.php +++ b/application/Espo/Core/Webhook/Queue.php @@ -46,7 +46,7 @@ use Exception; use DateTime; /** - * Groups ocurred events into portions and sends them. A portion contains + * Groups occurred events into portions and sends them. A portion contains * multiple events of the same webhook. */ class Queue @@ -362,7 +362,7 @@ class Queue $item->set([ 'attempts' => $attempts, - 'processAt' => $dt->format(DateTimeUtil::$systemDateTimeFormat), + 'processAt' => $dt->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT), ]); if ($attempts >= $maxAttemptsNumber) {