diff options
author | Jakub Zelenka <bukka@php.net> | 2016-06-19 16:20:02 +0100 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2016-06-19 16:20:02 +0100 |
commit | c2b90805e81de43b4fa28fa1b30ed255bfba76b2 (patch) | |
tree | a353bb7b1cb958fd4f3e576ab44f3b6ef03a02c2 /ext/intl/timezone/timezone_methods.cpp | |
parent | b44cf1a8540d321583a0d83ebca688ebab10d3b0 (diff) | |
parent | d0e84c6f4702dc5dda473851dd33c5e6cee82ee6 (diff) | |
download | php-git-c2b90805e81de43b4fa28fa1b30ed255bfba76b2.tar.gz |
Merge branch 'master' into openssl_error_store
Diffstat (limited to 'ext/intl/timezone/timezone_methods.cpp')
-rw-r--r-- | ext/intl/timezone/timezone_methods.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
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 |