diff options
-rw-r--r-- | ext/intl/tests/timezone_IDforWindowsID_basic.phpt | 44 | ||||
-rw-r--r-- | ext/intl/tests/timezone_windowsID_basic.phpt | 41 | ||||
-rw-r--r-- | ext/intl/timezone/timezone_class.cpp | 15 | ||||
-rw-r--r-- | ext/intl/timezone/timezone_methods.cpp | 78 | ||||
-rw-r--r-- | ext/intl/timezone/timezone_methods.h | 5 |
5 files changed, 183 insertions, 0 deletions
diff --git a/ext/intl/tests/timezone_IDforWindowsID_basic.phpt b/ext/intl/tests/timezone_IDforWindowsID_basic.phpt new file mode 100644 index 0000000000..2fab10fdd7 --- /dev/null +++ b/ext/intl/tests/timezone_IDforWindowsID_basic.phpt @@ -0,0 +1,44 @@ +--TEST-- +IntlTimeZone::getIDForWindowsID basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php + +$tzs = array( + 'Gnomeregan' => array(NULL), + 'India Standard Time' => array(NULL), + 'Pacific Standard Time' => array('001', 'CA', 'MX', 'US', 'ZZ'), + 'Romance Standard Time' => array('001', 'BE', 'DK', 'ES', 'FR'), +); + +foreach ($tzs as $tz => $regions) { + echo "** $tz\n"; + foreach ($regions as $region) { + var_dump(IntlTimeZone::getIDForWindowsID($tz, $region)); + if (intl_get_error_code() != U_ZERO_ERROR) { + echo "Error: ", intl_get_error_message(), "\n"; + } + } +} + +--EXPECT-- +** Gnomeregan +bool(false) +Error: intltz_get_windows_id: Unknown windows timezone: U_ILLEGAL_ARGUMENT_ERROR +** India Standard Time +string(13) "Asia/Calcutta" +** Pacific Standard Time +string(19) "America/Los_Angeles" +string(17) "America/Vancouver" +string(15) "America/Tijuana" +string(19) "America/Los_Angeles" +string(7) "PST8PDT" +** Romance Standard Time +string(12) "Europe/Paris" +string(15) "Europe/Brussels" +string(17) "Europe/Copenhagen" +string(13) "Europe/Madrid" +string(12) "Europe/Paris" diff --git a/ext/intl/tests/timezone_windowsID_basic.phpt b/ext/intl/tests/timezone_windowsID_basic.phpt new file mode 100644 index 0000000000..8a9fcfe95f --- /dev/null +++ b/ext/intl/tests/timezone_windowsID_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +IntlTimeZone::getWindowsID basic test +--SKIPIF-- +<?php +if (!extension_loaded('intl')) + die('skip intl extension not enabled'); +--FILE-- +<?php + +$tzs = array( + 'America/Bogota', + 'America/Havana', + 'America/Indiana/Knox', + 'America/Los_Angeles', + 'Azeroth/Kalimdor/Durotar', + 'Africa/Casablanca', + 'Asia/Singapore', + 'Australia/Perth', + 'Europe/London', + 'Europe/Istanbul', +); + +foreach ($tzs as $tz) { + var_dump(IntlTimeZone::getWindowsID($tz)); + if (intl_get_error_code() != U_ZERO_ERROR) { + echo "Error: ", intl_get_error_message(), "\n"; + } +} + +--EXPECT-- +string(24) "SA Pacific Standard Time" +string(21) "Eastern Standard Time" +string(21) "Central Standard Time" +string(21) "Pacific Standard Time" +bool(false) +Error: intltz_get_windows_id: Unknown system timezone: U_ILLEGAL_ARGUMENT_ERROR +string(21) "Morocco Standard Time" +string(23) "Singapore Standard Time" +string(26) "W. Australia Standard Time" +string(17) "GMT Standard Time" +string(20) "Turkey Standard Time" diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp index d1e8e2e0a6..f67e55ae4e 100644 --- a/ext/intl/timezone/timezone_class.cpp +++ b/ext/intl/timezone/timezone_class.cpp @@ -439,6 +439,17 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_void, 0, 0, 0) ZEND_END_ARG_INFO() +#if U_ICU_VERSION_MAJOR_NUM >= 52 +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getWindowsID, 0, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, timezone) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getIDForWindowsID, 0, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, timezone) + ZEND_ARG_INFO(0, region) +ZEND_END_ARG_INFO() +#endif + /* }}} */ /* {{{ TimeZone_class_functions @@ -475,6 +486,10 @@ static zend_function_entry TimeZone_class_functions[] = { PHP_ME_MAPPING(toDateTimeZone, intltz_to_date_time_zone, ainfo_tz_void, ZEND_ACC_PUBLIC) PHP_ME_MAPPING(getErrorCode, intltz_get_error_code, ainfo_tz_void, ZEND_ACC_PUBLIC) PHP_ME_MAPPING(getErrorMessage, intltz_get_error_message, ainfo_tz_void, ZEND_ACC_PUBLIC) +#if U_ICU_VERSION_MAJOR_NUM >= 52 + PHP_ME_MAPPING(getWindowsID, intltz_get_windows_id, ainfo_tz_getWindowsID, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME_MAPPING(getIDForWindowsID, intltz_get_id_for_windows_id, ainfo_tz_getIDForWindowsID, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) +#endif PHP_FE_END }; /* }}} */ diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp index a35174d3da..20c0e02480 100644 --- a/ext/intl/timezone/timezone_methods.cpp +++ b/ext/intl/timezone/timezone_methods.cpp @@ -647,3 +647,81 @@ U_CFUNC PHP_FUNCTION(intltz_get_error_message) message = intl_error_get_message(TIMEZONE_ERROR_P(to)); RETURN_STR(message); } + +#if U_ICU_VERSION_MAJOR_NUM >= 52 +/* {{{ proto string IntlTimeZone::getWindowsID(string $timezone) + proto string intltz_get_windows_id(string $timezone) +Translate a system timezone (e.g. "America/Los_Angeles" into a +Windows Timezone (e.g. "Pacific Standard Time") + */ +U_CFUNC PHP_FUNCTION(intltz_get_windows_id) +{ + zend_string *id, *winID; + UnicodeString uID, uWinID; + UErrorCode error; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &id) == FAILURE) { + return; + } + + error = U_ZERO_ERROR; + if (intl_stringFromChar(uID, id->val, id->len, &error) == FAILURE) { + intl_error_set(NULL, error, + "intltz_get_windows_id: could not convert time zone id to UTF-16", 0); + RETURN_FALSE; + } + + error = U_ZERO_ERROR; + TimeZone::getWindowsID(uID, uWinID, error); + INTL_CHECK_STATUS(error, "intltz_get_windows_id: Unable to get timezone from windows ID"); + if (uWinID.length() == 0) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_windows_id: Unknown system timezone", 0); + RETURN_FALSE; + } + + error = U_ZERO_ERROR; + winID = intl_convert_utf16_to_utf8(uWinID.getBuffer(), uWinID.length(), &error); + INTL_CHECK_STATUS(error, "intltz_get_windows_id: could not convert time zone id to UTF-8"); + RETURN_STR(winID); +} +/* }}} */ + +/* {{{ proto string IntlTimeZone::getIDForWindowsID(string $timezone[, string $region = NULL]) + proto string intltz_get_id_for_windows_id(string $timezone[, string $region = NULL]) +Translate a windows timezone (e.g. "Pacific Time Zone" into a +System Timezone (e.g. "America/Los_Angeles") + */ +U_CFUNC PHP_FUNCTION(intltz_get_id_for_windows_id) +{ + zend_string *winID, *region = NULL, *id; + UnicodeString uWinID, uID; + UErrorCode error; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &winID, ®ion) == FAILURE) { + return; + } + + error = U_ZERO_ERROR; + if (intl_stringFromChar(uWinID, winID->val, winID->len, &error) == FAILURE) { + intl_error_set(NULL, error, + "intltz_get_id_for_windows_id: could not convert time zone id to UTF-16", 0); + RETURN_FALSE; + } + + error = U_ZERO_ERROR; + TimeZone::getIDForWindowsID(uWinID, region ? region->val : NULL, uID, error); + INTL_CHECK_STATUS(error, "intltz_get_id_for_windows_id: Unable to get windows ID for timezone"); + if (uID.length() == 0) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intltz_get_windows_id: Unknown windows timezone", 0); + RETURN_FALSE; + } + + error = U_ZERO_ERROR; + id = intl_convert_utf16_to_utf8(uID.getBuffer(), uID.length(), &error); + INTL_CHECK_STATUS(error, "intltz_get_id_for_windows_id: could not convert time zone id to UTF-8"); + RETURN_STR(id); +} +/* }}} */ +#endif diff --git a/ext/intl/timezone/timezone_methods.h b/ext/intl/timezone/timezone_methods.h index 29d72913fd..6e6fa3f472 100644 --- a/ext/intl/timezone/timezone_methods.h +++ b/ext/intl/timezone/timezone_methods.h @@ -65,4 +65,9 @@ PHP_FUNCTION(intltz_get_error_code); PHP_FUNCTION(intltz_get_error_message); +#if U_ICU_VERSION_MAJOR_NUM >= 52 +PHP_FUNCTION(intltz_get_windows_id); +PHP_FUNCTION(intltz_get_id_for_windows_id); +#endif + #endif /* #ifndef TIMEZONE_METHODS_H */ |