diff --git a/application/Espo/Core/Utils/DateTime.php b/application/Espo/Core/Utils/DateTime.php index c9c5984969..db08570de4 100644 --- a/application/Espo/Core/Utils/DateTime.php +++ b/application/Espo/Core/Utils/DateTime.php @@ -31,11 +31,16 @@ namespace Espo\Core\Utils; use Carbon\Carbon; -use DateTimeZone; +use Espo\Core\Field\Date; +use Espo\Core\Field\DateTime as DateTimeField; + use DateTime as DateTimeStd; +use DateTimeImmutable; +use DateTimeZone; use Exception; use RuntimeException; + /** * Util for a date-time formatting and conversion. * Available as 'dateTime' service. @@ -240,6 +245,35 @@ class DateTime ); } + /** + * Get the default time zone. + */ + public function getTimezone(): DateTimeZone + { + return $this->timezone; + } + + /** + * Get a today's date according the default time zone. + */ + public function getToday(): Date + { + $string = (new DateTimeImmutable) + ->setTimezone($this->getTimezone()) + ->format(self::SYSTEM_DATE_FORMAT); + + return Date::fromString($string); + } + + /** + * Get a now date-time with the default time zone applied. + */ + public function getNow(): DateTimeField + { + return DateTimeField::createNow() + ->withTimezone($this->getTimezone()); + } + /** * @deprecated Use `SYSTEM_DATE_TIME_FORMAT constant`. */