diff --git a/.travis.yml b/.travis.yml index 82761958e..69e87f0e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ before_script: - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi" - chmod -R 777 ./app/tmp - sudo apt-get install lighttpd + - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.3" ]] ; then pecl install timezonedb ; fi - sh -c "if [ '$PHPCS' = '1' ]; then composer global require 'cakephp/cakephp-codesniffer:1.*'; fi" - sh -c "if [ '$PHPCS' = '1' ]; then ~/.composer/vendor/bin/phpcs --config-set installed_paths ~/.composer/vendor/cakephp/cakephp-codesniffer; fi" - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 447af6dca..35499e506 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -1166,6 +1166,19 @@ class CakeTimeTest extends CakeTestCase { $this->assertTrue(isset($return['Asia']['Asia/Bangkok'])); $this->assertFalse(isset($return['Pacific'])); + $return = CakeTime::listTimezones(null, null, array('abbr' => true)); + $this->assertTrue(isset($return['Asia']['Asia/Jakarta'])); + $this->assertEquals('Jakarta - WIB', $return['Asia']['Asia/Jakarta']); + $this->assertEquals('Amsterdam - CEST', $return['Europe']['Europe/Amsterdam']); + + $return = CakeTime::listTimezones(null, null, array( + 'abbr' => true, + 'before' => ' (', + 'after' => ')', + )); + $this->assertEquals('Jayapura (WIT)', $return['Asia']['Asia/Jayapura']); + $this->assertEquals('Amsterdam (CEST)', $return['Europe']['Europe/Amsterdam']); + $return = CakeTime::listTimezones('#^(America|Pacific)/#', null, false); $this->assertTrue(isset($return['America/Argentina/Buenos_Aires'])); $this->assertTrue(isset($return['Pacific/Tahiti'])); diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 0987dce3c..2cfcaff90 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -1075,12 +1075,29 @@ class CakeTime { * Or one of DateTimeZone class constants (PHP 5.3 and above) * @param string $country A two-letter ISO 3166-1 compatible country code. * This option is only used when $filter is set to DateTimeZone::PER_COUNTRY (available only in PHP 5.3 and above) - * @param bool $group If true (default value) groups the identifiers list by primary region + * @param bool|array $options If true (default value) groups the identifiers list by primary region. + * Otherwise, an array containing `group`, `abbr`, `before`, and `after` keys. + * Setting `group` and `abbr` to true will group results and append timezone + * abbreviation in the display value. Set `before` and `after` to customize + * the abbreviation wrapper. * @return array List of timezone identifiers * @since 2.2 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::listTimezones */ - public static function listTimezones($filter = null, $country = null, $group = true) { + public static function listTimezones($filter = null, $country = null, $options = array()) { + if (is_bool($options)) { + $options = array( + 'group' => $options, + ); + } + $options = array_merge(array( + 'group' => true, + 'abbr' => false, + 'before' => ' - ', + 'after' => null, + ), $options); + $group = $options['group']; + $regex = null; if (is_string($filter)) { $regex = $filter; @@ -1108,12 +1125,23 @@ class CakeTime { if ($group) { $return = array(); + $now = time(); + $before = $options['before']; + $after = $options['after']; foreach ($identifiers as $key => $tz) { + $abbr = null; + if ($options['abbr']) { + $dateTimeZone = new DateTimeZone($tz); + $trans = $dateTimeZone->getTransitions($now, $now); + $abbr = isset($trans[0]['abbr']) ? + $before . $trans[0]['abbr'] . $after : + null; + } $item = explode('/', $tz, 2); if (isset($item[1])) { - $return[$item[0]][$tz] = $item[1]; + $return[$item[0]][$tz] = $item[1] . $abbr; } else { - $return[$item[0]] = array($tz => $item[0]); + $return[$item[0]] = array($tz => $item[0] . $abbr); } } return $return;