Skip to content

Commit

Permalink
Move additional code into the shared trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 6, 2015
1 parent fb62516 commit 0eca841
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
18 changes: 15 additions & 3 deletions src/I18n/DateFormatTrait.php
Expand Up @@ -24,6 +24,19 @@
*/
trait DateFormatTrait
{
/**
* The default locale to be used for displaying formatted date strings.
*
* @var string
*/
public static $defaultLocale;

/**
* In-memory cache of date formatters
*
* @var array
*/
protected static $_formatters = [];

/**
* The format to use when when converting this object to json
Expand Down Expand Up @@ -169,7 +182,7 @@ protected function _formatObject($date, $format, $locale)
);
}

return static::$_formatters[$key]->format($date);
return static::$_formatters[$key]->format($date->format('U'));
}

/**
Expand Down Expand Up @@ -259,8 +272,7 @@ public static function parseDateTime($time, $format = null)
$time = $formatter->parse($time);
if ($time) {
$result = new static('@' . $time);
$result->setTimezone(date_default_timezone_get());
return $result;
return $result->setTimezone(date_default_timezone_get());
}
return null;
}
Expand Down
15 changes: 0 additions & 15 deletions src/I18n/Time.php
Expand Up @@ -61,14 +61,6 @@ class Time extends Chronos implements JsonSerializable
* @see \Cake\I18n\Time::nice()
*/
public static $niceFormat = [IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT];

/**
* The default locale to be used for displaying formatted date strings.
*
* @var string
*/
public static $defaultLocale;

/**
* The format to use when formatting a time using `Cake\I18n\Time::timeAgoInWords()`
* and the difference is more than `Cake\I18n\Time::$wordEnd`
Expand Down Expand Up @@ -103,13 +95,6 @@ class Time extends Chronos implements JsonSerializable
*/
public static $wordEnd = '+1 month';

/**
* In-memory cache of date formatters
*
* @var array
*/
protected static $_formatters = [];

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 0eca841

Please sign in to comment.