derick Sun Jan 27 17:29:15 2008 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/date/tests timezones-list.phpt
Modified files:
/php-src NEWS
/php-src/ext/date php_date.c
Log:
- MFH: Added support for selectively listing timezone identifiers through
timezone_identifiers_list() / DateTimezone::listIdentifiers().
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.88&r2=1.2027.2.547.2.965.2.89&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.88
php-src/NEWS:1.2027.2.547.2.965.2.89
--- php-src/NEWS:1.2027.2.547.2.965.2.88 Fri Jan 25 18:10:45 2008
+++ php-src/NEWS Sun Jan 27 17:29:14 2008
@@ -2,7 +2,7 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 20??, PHP 5.3.0
- Added garbage collector. (David Wang, Dmitry).
-- Added new date/time functionality:
+- Added new date/time functionality: (Derick)
* date_parse_from_format(): Parse date/time strings according to a format.
* date_create_from_format()/DateTime::createFromFormat(): Create a date/time
@@ -14,6 +14,10 @@
- date_parse_from_format()
* support for abbreviation and offset based timezone specifiers for
DateTime::getOffset() and DateTime::getName().
+ * support for selectively listing timezone identifiers through
+ timezone_identifiers_list() / DateTimezone::listIdentifiers().
+ * date_timestamp_set() / DateTime::setTimestamp() to set a Unix timestamp
+ without invoking the date parser. (Scott)
- Added ability to use Traversable objects instead of plain arrays in ext/soap.
(Joshua Reese, Dmitry)
@@ -40,8 +44,6 @@
(Etienne Kneuss)
- Added "compact" handler for Zend MM storage. (Dmitry)
- Added "+" and "*" specifiers to zend_parse_parameters(). (Andrei)
-- Added DateTime::setTimestamp() to set a unix timestamp without
- invoking the date parser. (Scott)
- Added SplDoublyLinkedList, SplStack, SplQueue classes. (Etienne)
- Removed the experimental RPL (master/slave) functions from mysqli. (Andrey)
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.43.2.45.2.51.2.11&r2=1.43.2.45.2.51.2.12&diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.43.2.45.2.51.2.11
php-src/ext/date/php_date.c:1.43.2.45.2.51.2.12
--- php-src/ext/date/php_date.c:1.43.2.45.2.51.2.11 Thu Jan 17 20:35:01 2008
+++ php-src/ext/date/php_date.c Sun Jan 27 17:29:14 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_date.c,v 1.43.2.45.2.51.2.11 2008/01/17 20:35:01 derick Exp $ */
+/* $Id: php_date.c,v 1.43.2.45.2.51.2.12 2008/01/27 17:29:14 derick Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -1497,6 +1497,19 @@
}
/* }}} */
+#define PHP_DATE_TIMEZONE_GROUP_AMERICA 0x0001
+#define PHP_DATE_TIMEZONE_GROUP_ANTARCTICA 0x0002
+#define PHP_DATE_TIMEZONE_GROUP_ARCTIC 0x0004
+#define PHP_DATE_TIMEZONE_GROUP_ASIA 0x0008
+#define PHP_DATE_TIMEZONE_GROUP_ATLANTIC 0x0010
+#define PHP_DATE_TIMEZONE_GROUP_AUSTRALIA 0x0020
+#define PHP_DATE_TIMEZONE_GROUP_EUROPE 0x0040
+#define PHP_DATE_TIMEZONE_GROUP_INDIAN 0x0080
+#define PHP_DATE_TIMEZONE_GROUP_PACIFIC 0x0100
+#define PHP_DATE_TIMEZONE_GROUP_UTC 0x0200
+#define PHP_DATE_TIMEZONE_GROUP_ALL 0x03FF
+#define PHP_DATE_TIMEZONE_GROUP_ALL_W_BC 0x07FF
+
static void date_register_classes(TSRMLS_D)
{
zend_class_entry ce_date, ce_timezone;
@@ -1529,6 +1542,22 @@
date_ce_timezone = zend_register_internal_class_ex(&ce_timezone, NULL,
NULL TSRMLS_CC);
memcpy(&date_object_handlers_timezone, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
date_object_handlers_timezone.clone_obj = date_object_clone_timezone;
+
+#define REGISTER_TIMEZONE_CLASS_CONST_STRING(const_name, value) \
+ zend_declare_class_constant_long(date_ce_timezone, const_name,
sizeof(const_name)-1, value TSRMLS_CC);
+
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("AMERICA",
PHP_DATE_TIMEZONE_GROUP_AMERICA);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("ANTARCTICA",
PHP_DATE_TIMEZONE_GROUP_ANTARCTICA);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("ARCTIC",
PHP_DATE_TIMEZONE_GROUP_ARCTIC);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("ASIA",
PHP_DATE_TIMEZONE_GROUP_ASIA);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("ATLANTIC",
PHP_DATE_TIMEZONE_GROUP_ATLANTIC);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("AUSTRALIA",
PHP_DATE_TIMEZONE_GROUP_AUSTRALIA);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("EUROPE",
PHP_DATE_TIMEZONE_GROUP_EUROPE);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("INDIAN",
PHP_DATE_TIMEZONE_GROUP_INDIAN);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("PACIFIC",
PHP_DATE_TIMEZONE_GROUP_PACIFIC);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("UTC",
PHP_DATE_TIMEZONE_GROUP_UTC);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("ALL",
PHP_DATE_TIMEZONE_GROUP_ALL);
+ REGISTER_TIMEZONE_CLASS_CONST_STRING("ALL_WITH_BC",
PHP_DATE_TIMEZONE_GROUP_ALL_W_BC);
}
static inline zend_object_value date_object_new_date_ex(zend_class_entry
*class_type, php_date_obj **ptr TSRMLS_DC)
@@ -2423,6 +2452,21 @@
}
/* }}} */
+static int check_id_allowed(char *id, long what)
+{
+ if (what & PHP_DATE_TIMEZONE_GROUP_AMERICA && strncasecmp(id,
"America/", 8) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_ANTARCTICA && strncasecmp(id,
"Antarctica/", 11) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_ARCTIC && strncasecmp(id,
"Arctic/", 7) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_ASIA && strncasecmp(id,
"Asia/", 5) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_ATLANTIC && strncasecmp(id,
"Atlantic/", 9) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_AUSTRALIA && strncasecmp(id,
"Australia/", 10) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_EUROPE && strncasecmp(id,
"Europe/", 7) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_INDIAN && strncasecmp(id,
"Indian/", 7) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_PACIFIC && strncasecmp(id,
"Pacific/", 8) == 0) return 1;
+ if (what & PHP_DATE_TIMEZONE_GROUP_UTC && strncasecmp(id, "UTC",
3) == 0) return 1;
+ return 0;
+}
+
/* {{{ proto array timezone_identifiers_list()
Returns numerically index array with all timezone identifiers.
*/
@@ -2431,6 +2475,11 @@
const timelib_tzdb *tzdb;
const timelib_tzdb_index_entry *table;
int i, item_count;
+ long what = PHP_DATE_TIMEZONE_GROUP_ALL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &what) ==
FAILURE) {
+ RETURN_FALSE;
+ }
tzdb = DATE_TIMEZONEDB;
item_count = tzdb->index_size;
@@ -2439,7 +2488,9 @@
array_init(return_value);
for (i = 0; i < item_count; ++i) {
- add_next_index_string(return_value, table[i].id, 1);
+ if (what == PHP_DATE_TIMEZONE_GROUP_ALL_W_BC ||
check_id_allowed(table[i].id, what)) {
+ add_next_index_string(return_value, table[i].id, 1);
+ }
};
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/date/tests/timezones-list.phpt?view=markup&rev=1.1
Index: php-src/ext/date/tests/timezones-list.phpt
+++ php-src/ext/date/tests/timezones-list.phpt
--TEST--
timezone_identifiers_list()
--FILE--
<?php
$a = timezone_identifiers_list();
$b = timezone_identifiers_list( DateTimezone::AMERICA );
$c = timezone_identifiers_list( DateTimezone::ALL_WITH_BC );
$d = timezone_identifiers_list( DateTimezone::EUROPE | DateTimezone::UTC );
echo in_array( "Europe/Oslo", $a ) ? "found" : "notfound", "\n";
echo in_array( "Europe/Oslo", $b ) ? "found" : "notfound", "\n";
echo in_array( "Europe/Oslo", $c ) ? "found" : "notfound", "\n";
echo in_array( "Europe/Oslo", $d ) ? "found" : "notfound", "\n\n";
echo in_array( "America/New_York", $a ) ? "found" : "notfound", "\n";
echo in_array( "America/New_York", $b ) ? "found" : "notfound", "\n";
echo in_array( "America/New_York", $c ) ? "found" : "notfound", "\n";
echo in_array( "America/New_York", $d ) ? "found" : "notfound", "\n\n";
echo in_array( "UTC", $a ) ? "found" : "notfound", "\n";
echo in_array( "UTC", $b ) ? "found" : "notfound", "\n";
echo in_array( "UTC", $c ) ? "found" : "notfound", "\n";
echo in_array( "UTC", $d ) ? "found" : "notfound", "\n\n";
echo in_array( "US/Eastern", $a ) ? "found" : "notfound", "\n";
echo in_array( "US/Eastern", $b ) ? "found" : "notfound", "\n";
echo in_array( "US/Eastern", $c ) ? "found" : "notfound", "\n";
echo in_array( "US/Eastern", $d ) ? "found" : "notfound", "\n\n";
?>
--EXPECT--
found
notfound
found
found
found
found
found
notfound
found
notfound
found
found
notfound
notfound
found
notfound
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php