fixes
This commit is contained in:
31
vendor/nette/utils/src/Utils/DateTime.php
vendored
31
vendor/nette/utils/src/Utils/DateTime.php
vendored
@@ -32,19 +32,17 @@ class DateTime extends \DateTime implements \JsonSerializable
|
||||
public const WEEK = 7 * self::DAY;
|
||||
|
||||
/** average month in seconds */
|
||||
public const MONTH = 2629800;
|
||||
public const MONTH = 2_629_800;
|
||||
|
||||
/** average year in seconds */
|
||||
public const YEAR = 31557600;
|
||||
public const YEAR = 31_557_600;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.
|
||||
* @param string|int|\DateTimeInterface $time
|
||||
* @return static
|
||||
* @throws \Exception if the date and time are not valid.
|
||||
*/
|
||||
public static function from($time)
|
||||
public static function from(string|int|\DateTimeInterface|null $time): static
|
||||
{
|
||||
if ($time instanceof \DateTimeInterface) {
|
||||
return new static($time->format('Y-m-d H:i:s.u'), $time->getTimezone());
|
||||
@@ -64,7 +62,6 @@ class DateTime extends \DateTime implements \JsonSerializable
|
||||
|
||||
/**
|
||||
* Creates DateTime object.
|
||||
* @return static
|
||||
* @throws Nette\InvalidArgumentException if the date and time are not valid.
|
||||
*/
|
||||
public static function fromParts(
|
||||
@@ -73,8 +70,9 @@ class DateTime extends \DateTime implements \JsonSerializable
|
||||
int $day,
|
||||
int $hour = 0,
|
||||
int $minute = 0,
|
||||
float $second = 0.0
|
||||
) {
|
||||
float $second = 0.0,
|
||||
): static
|
||||
{
|
||||
$s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5F', $year, $month, $day, $hour, $minute, $second);
|
||||
if (
|
||||
!checkdate($month, $day, $year)
|
||||
@@ -94,22 +92,18 @@ class DateTime extends \DateTime implements \JsonSerializable
|
||||
|
||||
/**
|
||||
* Returns new DateTime object formatted according to the specified format.
|
||||
* @param string $format The format the $time parameter should be in
|
||||
* @param string $time
|
||||
* @param string|\DateTimeZone $timezone (default timezone is used if null is passed)
|
||||
* @return static|false
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public static function createFromFormat($format, $time, $timezone = null)
|
||||
public static function createFromFormat(
|
||||
string $format,
|
||||
string $time,
|
||||
string|\DateTimeZone|null $timezone = null,
|
||||
): static|false
|
||||
{
|
||||
if ($timezone === null) {
|
||||
$timezone = new \DateTimeZone(date_default_timezone_get());
|
||||
|
||||
} elseif (is_string($timezone)) {
|
||||
$timezone = new \DateTimeZone($timezone);
|
||||
|
||||
} elseif (!$timezone instanceof \DateTimeZone) {
|
||||
throw new Nette\InvalidArgumentException('Invalid timezone given');
|
||||
}
|
||||
|
||||
$date = parent::createFromFormat($format, $time, $timezone);
|
||||
@@ -137,9 +131,8 @@ class DateTime extends \DateTime implements \JsonSerializable
|
||||
|
||||
/**
|
||||
* Creates a copy with a modified time.
|
||||
* @return static
|
||||
*/
|
||||
public function modifyClone(string $modify = '')
|
||||
public function modifyClone(string $modify = ''): static
|
||||
{
|
||||
$dolly = clone $this;
|
||||
return $modify ? $dolly->modify($modify) : $dolly;
|
||||
|
||||
Reference in New Issue
Block a user