[Pkg-owncloud-commits] [php-sabre-vobject] 21/43: alternative solution for #116
David Prévot
taffit at moszumanska.debian.org
Fri Oct 10 14:16:16 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabre-vobject.
commit e8a8a3685b548ee8f318ff02df4095f755c1feb6
Author: Dominik Tobschall <dominik at fruux.com>
Date: Tue Sep 30 13:09:26 2014 +0200
alternative solution for #116
---
lib/TimeZoneUtil.php | 40 +++++-
lib/timezonedata/php-bc.php | 150 +++++++++++++++++++++
.../{php-compat.php => php-workaround.php} | 5 +
tests/VObject/TimeZoneUtilTest.php | 28 +++-
4 files changed, 219 insertions(+), 4 deletions(-)
diff --git a/lib/TimeZoneUtil.php b/lib/TimeZoneUtil.php
index dc90ebf..326e4d5 100644
--- a/lib/TimeZoneUtil.php
+++ b/lib/TimeZoneUtil.php
@@ -135,10 +135,29 @@ class TimeZoneUtil {
// this method will return just GMT+01:00. This is wrong, because it
// doesn't take DST into account.
if ($tzid[0]!=='(') {
+
+ // PHP has a bug that logs PHP warnings even it shouldn't:
+ // https://bugs.php.net/bug.php?id=67881
+ //
+ // That's why we're checking if we'll be able to successfull instantiate
+ // \DateTimeZone() before doing so. Otherwise we could simplify this to:
+ // try {
+ // return new \DateTimeZone($tzid);
+ // } catch(\Exception $e) {
+ // }
+ $tzIdentifiers = \DateTimeZone::listIdentifiers();
+
try {
- return new \DateTimeZone($tzid);
- } catch (\Exception $e) {
+ if (
+ (in_array($tzid, $tzIdentifiers)) ||
+ (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) ||
+ (in_array($tzid, self::getIdentifiersBC()))
+ ) {
+ return new \DateTimeZone($tzid);
+ }
+ } catch(\Exception $e) {
}
+
}
self::loadTzMaps();
@@ -226,9 +245,24 @@ class TimeZoneUtil {
include __DIR__ . '/timezonedata/windowszones.php',
include __DIR__ . '/timezonedata/lotuszones.php',
include __DIR__ . '/timezonedata/exchangezones.php',
- include __DIR__ . '/timezonedata/php-compat.php'
+ include __DIR__ . '/timezonedata/php-workaround.php'
);
}
+ /**
+ * This method returns an array of timezone identifiers, that are supported
+ * by DateTimeZone(), but not returned by DateTimeZone::listIdentifiers()
+ *
+ * We're not using DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC) because:
+ * - It's not supported by some PHP versions as well as HHVM.
+ * - It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions.
+ * (See timezonedata/php-bc.php and timezonedata php-workaround.php)
+ *
+ * @return array
+ */
+ static public function getIdentifiersBC() {
+ return include __DIR__ . '/timezonedata/php-bc.php';
+ }
+
}
diff --git a/lib/timezonedata/php-bc.php b/lib/timezonedata/php-bc.php
new file mode 100644
index 0000000..87c24c1
--- /dev/null
+++ b/lib/timezonedata/php-bc.php
@@ -0,0 +1,150 @@
+<?php
+/**
+ * A list of additional PHP timezones that are returned by
+ * DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC)
+ * valid for new DateTimeZone()
+ *
+ * Instead of using DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC)
+ * directly, we use this file because DateTimeZone::ALL_WITH_BC is not properly
+ * supported by all PHP version and HHVM.
+ *
+ * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+ return array(
+ 'Africa/Asmera',
+ 'Africa/Timbuktu',
+ 'America/Argentina/ComodRivadavia',
+ 'America/Atka',
+ 'America/Buenos_Aires',
+ 'America/Catamarca',
+ 'America/Coral_Harbour',
+ 'America/Cordoba',
+ 'America/Ensenada',
+ 'America/Fort_Wayne',
+ 'America/Indianapolis',
+ 'America/Jujuy',
+ 'America/Knox_IN',
+ 'America/Louisville',
+ 'America/Mendoza',
+ 'America/Montreal',
+ 'America/Porto_Acre',
+ 'America/Rosario',
+ 'America/Shiprock',
+ 'America/Virgin',
+ 'Antarctica/South_Pole',
+ 'Asia/Ashkhabad',
+ 'Asia/Calcutta',
+ 'Asia/Chungking',
+ 'Asia/Dacca',
+ 'Asia/Istanbul',
+ 'Asia/Katmandu',
+ 'Asia/Macao',
+ 'Asia/Saigon',
+ 'Asia/Tel_Aviv',
+ 'Asia/Thimbu',
+ 'Asia/Ujung_Pandang',
+ 'Asia/Ulan_Bator',
+ 'Atlantic/Faeroe',
+ 'Atlantic/Jan_Mayen',
+ 'Australia/ACT',
+ 'Australia/Canberra',
+ 'Australia/LHI',
+ 'Australia/North',
+ 'Australia/NSW',
+ 'Australia/Queensland',
+ 'Australia/South',
+ 'Australia/Tasmania',
+ 'Australia/Victoria',
+ 'Australia/West',
+ 'Australia/Yancowinna',
+ 'Brazil/Acre',
+ 'Brazil/DeNoronha',
+ 'Brazil/East',
+ 'Brazil/West',
+ 'Canada/Atlantic',
+ 'Canada/Central',
+ 'Canada/East-Saskatchewan',
+ 'Canada/Eastern',
+ 'Canada/Mountain',
+ 'Canada/Newfoundland',
+ 'Canada/Pacific',
+ 'Canada/Saskatchewan',
+ 'Canada/Yukon',
+ 'CET',
+ 'Chile/Continental',
+ 'Chile/EasterIsland',
+ 'EET',
+ 'EST',
+ 'Etc/GMT',
+ 'Etc/GMT+0',
+ 'Etc/GMT+1',
+ 'Etc/GMT+10',
+ 'Etc/GMT+11',
+ 'Etc/GMT+12',
+ 'Etc/GMT+2',
+ 'Etc/GMT+3',
+ 'Etc/GMT+4',
+ 'Etc/GMT+5',
+ 'Etc/GMT+6',
+ 'Etc/GMT+7',
+ 'Etc/GMT+8',
+ 'Etc/GMT+9',
+ 'Etc/GMT-0',
+ 'Etc/GMT-1',
+ 'Etc/GMT-10',
+ 'Etc/GMT-11',
+ 'Etc/GMT-12',
+ 'Etc/GMT-13',
+ 'Etc/GMT-14',
+ 'Etc/GMT-2',
+ 'Etc/GMT-3',
+ 'Etc/GMT-4',
+ 'Etc/GMT-5',
+ 'Etc/GMT-6',
+ 'Etc/GMT-7',
+ 'Etc/GMT-8',
+ 'Etc/GMT-9',
+ 'Etc/GMT0',
+ 'Etc/Greenwich',
+ 'Etc/UCT',
+ 'Etc/Universal',
+ 'Etc/UTC',
+ 'Etc/Zulu',
+ 'Europe/Belfast',
+ 'Europe/Nicosia',
+ 'Europe/Tiraspol',
+ 'GB',
+ 'GMT',
+ 'GMT+0',
+ 'GMT-0',
+ 'HST',
+ 'MET',
+ 'Mexico/BajaNorte',
+ 'Mexico/BajaSur',
+ 'Mexico/General',
+ 'MST',
+ 'NZ',
+ 'Pacific/Ponape',
+ 'Pacific/Samoa',
+ 'Pacific/Truk',
+ 'Pacific/Yap',
+ 'PRC',
+ 'ROC',
+ 'ROK',
+ 'UCT',
+ 'US/Alaska',
+ 'US/Aleutian',
+ 'US/Arizona',
+ 'US/Central',
+ 'US/East-Indiana',
+ 'US/Eastern',
+ 'US/Hawaii',
+ 'US/Indiana-Starke',
+ 'US/Michigan',
+ 'US/Mountain',
+ 'US/Pacific',
+ 'US/Pacific-New',
+ 'US/Samoa',
+ 'WET',
+);
diff --git a/lib/timezonedata/php-compat.php b/lib/timezonedata/php-workaround.php
similarity index 85%
rename from lib/timezonedata/php-compat.php
rename to lib/timezonedata/php-workaround.php
index c3db746..c41b74e 100644
--- a/lib/timezonedata/php-compat.php
+++ b/lib/timezonedata/php-workaround.php
@@ -3,6 +3,10 @@
* A list of PHP timezones that were supported in PHP 5.5.9, but are no longer
* in PHP 5.5.10.
*
+ * They are still returned by DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC),
+ * but are invalid for new DateTimeZone(). Fixed in PHP 5.5.17.
+ * https://bugs.php.net/bug.php?id=66985
+ *
* Some more info here:
* http://evertpot.com/php-5-5-10-timezone-changes/
*
@@ -37,4 +41,5 @@ return array(
'Turkey' => 'Europe/Istanbul',
'Universal' => 'UTC',
'W-SU' => 'Europe/Moscow',
+ 'Zulu' => 'UTC',
);
diff --git a/tests/VObject/TimeZoneUtilTest.php b/tests/VObject/TimeZoneUtilTest.php
index fd2dec8..3a076b2 100644
--- a/tests/VObject/TimeZoneUtilTest.php
+++ b/tests/VObject/TimeZoneUtilTest.php
@@ -151,6 +151,32 @@ HI;
}
+ function testPHPTimeZoneIdentifiers() {
+
+ $tzIdentifiers = \DateTimeZone::listIdentifiers();
+
+ foreach ($tzIdentifiers as $tzid) {
+ $tz = TimeZoneUtil::getTimeZone($tzid);
+ $ex = new \DateTimeZone($tzid);
+
+ $this->assertEquals($ex->getName(), $tz->getName());
+ }
+
+ }
+
+ function testPHPBCTimeZoneIdentifiers() {
+
+ $tzIdentifiers = TimeZoneUtil::getIdentifiersBC();
+
+ foreach ($tzIdentifiers as $tzid) {
+ $tz = TimeZoneUtil::getTimeZone($tzid);
+ $ex = new \DateTimeZone($tzid);
+
+ $this->assertEquals($ex->getName(), $tz->getName());
+ }
+
+ }
+
function testTimezoneOffset() {
$tz = TimeZoneUtil::getTimeZone('GMT-0400', null, true);
@@ -169,7 +195,7 @@ HI;
*/
function testTimezoneFail() {
- $tz = TimeZoneUtil::getTimeZone('FooBar',null,true);
+ $tz = TimeZoneUtil::getTimeZone('FooBar', null, true);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git
More information about the Pkg-owncloud-commits
mailing list