]> granicus.if.org Git - php/commitdiff
Update IntlTimeZone methods for ICU 52
authorSara Golemon <pollita@php.net>
Wed, 16 Mar 2016 00:32:36 +0000 (00:32 +0000)
committerSara Golemon <pollita@php.net>
Mon, 18 Apr 2016 23:01:25 +0000 (23:01 +0000)
Adds:
  string IntlTimeZone::getWindowsID(string id)
  string IntlTimeZone::getIDForWindowsID(string winID[, string region])

And matching procedural functions

ext/intl/tests/timezone_IDforWindowsID_basic.phpt [new file with mode: 0644]
ext/intl/tests/timezone_windowsID_basic.phpt [new file with mode: 0644]
ext/intl/timezone/timezone_class.cpp
ext/intl/timezone/timezone_methods.cpp
ext/intl/timezone/timezone_methods.h

diff --git a/ext/intl/tests/timezone_IDforWindowsID_basic.phpt b/ext/intl/tests/timezone_IDforWindowsID_basic.phpt
new file mode 100644 (file)
index 0000000..2fab10f
--- /dev/null
@@ -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 (file)
index 0000000..8a9fcfe
--- /dev/null
@@ -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"
index d1e8e2e0a678b44cb179d87106c3330f89b439bd..f67e55ae4e5676b68e72f792a3eeef829f2948e9 100644 (file)
@@ -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
 };
 /* }}} */
index a35174d3da92a00c43b7c1c536cebf76fd0b6773..20c0e0248075b6ce24b0b74a8f1c49b9ccb88d25 100644 (file)
@@ -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, &region) == 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
index 29d72913fd57b297bff768e0b1575a4ac764d809..6e6fa3f472af063174f029c95e0baa335e1647c7 100644 (file)
@@ -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 */