Skip to content
Permalink
Browse files

update to only use output timezone formatting for time/frozentime

  • Loading branch information...
Jonas Hartmann authored and markstory committed May 13, 2016
1 parent e8cae33 commit 24b228c3db11860324e701e773866cedb15032d4
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/I18n/DateFormatTrait.php
@@ -17,6 +17,7 @@
use Cake\Chronos\Date as ChronosDate;
use Cake\Chronos\MutableDate;
use IntlDateFormatter;
use \NotImplementedException;
/**
* Trait for date formatting methods shared by both Time & Date.
@@ -35,7 +36,7 @@ trait DateFormatTrait
public static $defaultLocale;
/**
* The \DateTimeZone default output timezone.
* The \DateTimeZone default output timezone used by Time and FrozenTime.
* See http://php.net/manual/en/timezones.php.
*
* @var \DateTimeZone|null
@@ -72,24 +73,30 @@ trait DateFormatTrait
*/
protected static $_isDateInstance;
/** Gets the default output timezone.
/** Gets the default output timezone used by Time and FrozenTime.
*
* @return \DateTimeZone|null DateTimeZone object in which the date will be displayed or null.
*/
public static function getDefaultOutputTimezone()
{
if (static::$_isDateInstance === true) {
throw new NotImplementedException('Timezone conversion is not supported by Date/FrozenDate.');
}
return static::$_defaultOutputTimezone;
}
/**
* Sets the default output timezone.
* Sets the default output timezone used by Time and FrozenTime.
*
* @param string|\DateTimeZone $timezone Timezone string or DateTimeZone object
* in which the date will be displayed.
* @return void
*/
public static function setDefaultOutputTimezone($timezone)
{
if (static::$_isDateInstance === true) {
throw new NotImplementedException('Timezone conversion is not supported by Date/FrozenDate.');
}
if (is_string($timezone)) {
static::$_defaultOutputTimezone = new \DateTimeZone($timezone);
} elseif ($timezone instanceof \DateTimeZone) {
@@ -192,10 +199,9 @@ public function i18nFormat($format = null, $timezone = null, $locale = null)
{
$time = $this;
// This is required for testI18nFormatWithOffsetTimezone to pass
// if ($time->getTimezone()->getName() === date_default_timezone_get()) {
if (static::$_isDateInstance === false) {
$timezone = $timezone ?: static::getDefaultOutputTimezone();
// }
}
if ($timezone) {
// Handle the immutable and mutable object cases.

0 comments on commit 24b228c

Please sign in to comment.
You can’t perform that action at this time.