Skip to content
Permalink
Browse files

fixes offset style timezone for datefmt_create

  • Loading branch information...
Tietew committed Apr 3, 2015
1 parent b307d68 commit ed3c91ce89ff29c103fd27e2f03deddc89c7603d
Showing with 30 additions and 1 deletion.
  1. +7 −1 src/I18n/Time.php
  2. +23 −0 tests/TestCase/I18n/TimeTest.php
@@ -17,6 +17,7 @@
use Carbon\Carbon;
use IntlDateFormatter;
use JsonSerializable;
use RuntimeException;
/**
* Extends the built-in DateTime class to provide handy methods and locale-aware
@@ -578,11 +579,16 @@ protected function _formatObject($date, $format, $locale)
$key = "{$locale}.{$dateFormat}.{$timeFormat}.{$timezone}.{$calendar}.{$pattern}";
if (!isset(static::$_formatters[$key])) {
if ($timezone === '+00:00') {
$timezone = 'UTC';
} elseif ($timezone[0] === '+' || $timezone[0] === '-') {
$timezone = 'GMT' . $timezone;
}
static::$_formatters[$key] = datefmt_create(
$locale,
$dateFormat,
$timeFormat,
$timezone === '+00:00' ? 'UTC' : $timezone,
$timezone,
$calendar,
$pattern
);
@@ -529,6 +529,29 @@ public function testI18nFormat()
$this->assertTimeFormat($expected, $result, 'DEfault locale should not be used');
}
/**
* test formatting dates with offset style timezone
*
* @return void
*/
public function testI18nFormatWithOffsetTimezone()
{
$time = new Time('2014-01-01T00:00:00+00');
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'Wednesday January 1 2014 12:00:00 AM GMT';
$this->assertTimeFormat($expected, $result);
$time = new Time('2014-01-01T00:00:00+09');
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'Wednesday January 1 2014 12:00:00 AM GMT+09:00';
$this->assertTimeFormat($expected, $result);
$time = new Time('2014-01-01T00:00:00-01:30');
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'Wednesday January 1 2014 12:00:00 AM GMT-01:30';
$this->assertTimeFormat($expected, $result);
}
/**
* testListTimezones
*

0 comments on commit ed3c91c

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