Skip to content

Commit

Permalink
Using own variable in Time to avoid CS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 21, 2014
1 parent ed4de11 commit f7bb82f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/Utility/Time.php
Expand Up @@ -39,7 +39,7 @@ class Time extends Carbon {
* @var mixed
* @see \Cake\Utility\Time::i18nFormat()
*/
protected static $toStringFormat = [IntlDateFormatter::SHORT, IntlDateFormatter::SHORT];
protected static $_toStringFormat = [IntlDateFormatter::SHORT, IntlDateFormatter::SHORT];

/**
* The format to use when formatting a time using `Cake\Utility\Time::nice()`
Expand Down Expand Up @@ -539,7 +539,7 @@ public function i18nFormat($format = null, $timezone = null, $locale = null) {
$time->timezone($timezone);
}

$format = $format !== null ? $format : static::$toStringFormat;
$format = $format !== null ? $format : static::$_toStringFormat;
$locale = $locale ?: static::$defaultLocale;
return IntlDateFormatter::formatObject($time, $format, $locale);
}
Expand Down Expand Up @@ -598,4 +598,22 @@ public static function listTimezones($filter = null, $country = null, $group = t
return array_combine($identifiers, $identifiers);
}

/**
* Resets the format used to the default when converting an instance of this type to
* a string
*
*/
public static function resetToStringFormat() {
static::setToStringFormat([IntlDateFormatter::SHORT, IntlDateFormatter::SHORT]);
}

/**
* Sets the default format used when type converting instances of this type to string
*
* @param string|int $format
*/
public static function setToStringFormat($format) {
static::$_toStringFormat = $format;
}

}
5 changes: 4 additions & 1 deletion tests/TestCase/Utility/TimeTest.php
Expand Up @@ -45,6 +45,7 @@ public function tearDown() {
parent::tearDown();
Time::setTestNow($this->now);
Time::$defaultLocale = $this->locale;
Time::resetToStringFormat();
}

/**
Expand Down Expand Up @@ -547,8 +548,10 @@ public function testToString() {

Time::$defaultLocale = 'fr-FR';
$this->assertEquals('20/04/2014 22:10', (string)$time);
}

Time::setToStringFormat(\IntlDateFormatter::FULL);
$this->assertEquals('dimanche 20 avril 2014 22:10:00 UTC', (string)$time);
}

/**
* Tests diffForHumans
Expand Down

0 comments on commit f7bb82f

Please sign in to comment.