Skip to content

Commit

Permalink
move the check to the Time class
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Jan 31, 2016
1 parent 3e9121b commit cf1993a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/I18n/Time.php
Expand Up @@ -17,6 +17,7 @@
use Cake\Chronos\ChronosInterface;
use Cake\Chronos\MutableDateTime;
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use IntlDateFormatter;
use JsonSerializable;
Expand Down Expand Up @@ -102,6 +103,9 @@ class Time extends MutableDateTime implements JsonSerializable
*/
public function __construct($time = null, $tz = null)
{
if ($time instanceof DateTimeImmutable) {
$time = $time->toMutable();
}
if ($time instanceof DateTime) {
$tz = $time->getTimeZone();
$time = $time->format('Y-m-d H:i:s');
Expand Down
4 changes: 0 additions & 4 deletions src/View/Helper/TimeHelper.php
Expand Up @@ -333,10 +333,6 @@ public function i18nFormat($date, $format = null, $invalid = false, $timezone =
return $invalid;
}

if ($date instanceof \DateTimeImmutable) {
$date = $date->toMutable();
}

try {
$time = new Time($date);
return $time->i18nFormat($format, $timezone);
Expand Down

0 comments on commit cf1993a

Please sign in to comment.