mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 15:06:06 +00:00
date time methods
This commit is contained in:
@@ -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`.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user