Skip to content

Commit

Permalink
Make Time compatible with DateTime (#5022)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Aug 26, 2021
1 parent d8b43eb commit 26a4f69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion system/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use CodeIgniter\I18n\Time;
use Exception;
use JsonSerializable;
use ReturnTypeWillChange;

/**
* Entity encapsulation, for use with CodeIgniter\Model
Expand Down Expand Up @@ -406,8 +407,9 @@ private function castAsJson($value, bool $asArray = false)
/**
* Support for json_encode()
*
* @return array|mixed
* @return array
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
Expand Down
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

0 comments on commit 26a4f69

Please sign in to comment.