Skip to content

Commit

Permalink
update to only use output timezone formatting for time/frozentime
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Hartmann authored and markstory committed Jun 2, 2016
1 parent e8cae33 commit 24b228c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/I18n/DateFormatTrait.php
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 24b228c

Please sign in to comment.