Skip to content

Make Time compatible with DateTime #5022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions system/I18n/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
use IntlCalendar;
use IntlDateFormatter;
use Locale;
use ReturnTypeWillChange;

/**
* Class Time
*
* A localized date/time package inspired
* by Nesbot/Carbon and CakePHP/Chronos.
*
Expand Down Expand Up @@ -232,19 +231,20 @@ public static function create(?int $year = null, ?int $month = null, ?int $day =
*
* @param string $format
* @param string $datetime
* @param DateTimeZone|string|null $timeZone
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function createFromFormat($format, $datetime, $timeZone = null)
#[ReturnTypeWillChange]
public static function createFromFormat($format, $datetime, $timezone = null)
{
if (! $date = parent::createFromFormat($format, $datetime)) {
throw I18nException::forInvalidFormat($format);
}

return new self($date->format('Y-m-d H:i:s'), $timeZone);
return new self($date->format('Y-m-d H:i:s'), $timezone);
}

/**
Expand Down Expand Up @@ -679,6 +679,7 @@ protected function setValue(string $name, $value)
*
* @return Time
*/
#[ReturnTypeWillChange]
public function setTimezone($timezone)
{
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
Expand All @@ -695,6 +696,7 @@ public function setTimezone($timezone)
*
* @return Time
*/
#[ReturnTypeWillChange]
public function setTimestamp($timestamp)
{
$time = date('Y-m-d H:i:s', $timestamp);
Expand Down Expand Up @@ -1181,7 +1183,7 @@ public function __isset($name): bool
/**
* This is called when we unserialize the Time object.
*/
public function __wakeup()
public function __wakeup(): void
{
/**
* Prior to unserialization, this is a string.
Expand Down