Skip to content

ext/intl: Timezone::getIanaID method addition. #13419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/intl/php_intl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ function intltz_to_date_time_zone(IntlTimeZone $timezone): DateTimeZone|false {}

function intltz_use_daylight_time(IntlTimeZone $timezone): bool {}

#if U_ICU_VERSION_MAJOR_NUM >= 74
function intltz_get_iana_id(string $timezoneId): string|false {}
#endif

/* transliterator */

function transliterator_create(string $id, int $direction = Transliterator::FORWARD): ?Transliterator {}
Expand Down
14 changes: 13 additions & 1 deletion ext/intl/php_intl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions ext/intl/tests/timezone_getIanaID.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
IntlTimeZone::getIanaID
--EXTENSIONS--
intl
--SKIPIF--
<?php if (version_compare(INTL_ICU_VERSION, '74.0') < 0) die('skip for ICU >= 74.0'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

var_dump(IntlTimeZone::getIanaID("php\x81"));
var_dump(IntlTimeZone::getIanaID("Galaxy/Pluto"));
var_dump(IntlTimeZone::getIanaID('Europe/Dublin'));
var_dump(IntlTimeZone::getIanaID('Asia/Calcutta'));
var_dump(intltz_get_iana_id('Asia/Calcutta') === IntlTimeZone::getIanaID('Asia/Calcutta'));
?>
--EXPECTF--
Warning: IntlTimeZone::getIanaID(): could not convert time zone id to UTF-16 in %s on line %d
bool(false)

Warning: IntlTimeZone::getIanaID(): error obtaining IANA ID in %s on line %d
bool(false)
string(13) "Europe/Dublin"
string(12) "Asia/Kolkata"
bool(true)
7 changes: 7 additions & 0 deletions ext/intl/timezone/timezone.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public function getErrorMessage(): string|false {}
*/
public static function getGMT(): IntlTimeZone {}

#if U_ICU_VERSION_MAJOR_NUM >= 74
/**
* @alias intltz_get_iana_id
*/
public static function getIanaID(string $timezoneId): string|false {}
#endif

/**
* @tentative-return-type
* @alias intltz_get_id
Expand Down
14 changes: 13 additions & 1 deletion ext/intl/timezone/timezone_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions ext/intl/timezone/timezone_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,37 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id)
RETVAL_NEW_STR(u8str);
}

#if U_ICU_VERSION_MAJOR_NUM >= 74
U_CFUNC PHP_FUNCTION(intltz_get_iana_id)
{
char *str_id;
size_t str_id_len;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
&str_id, &str_id_len) == FAILURE) {
RETURN_THROWS();
}

UErrorCode status = UErrorCode();
UnicodeString id;
if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) {
intl_error_set(NULL, status,
"could not convert time zone id to UTF-16", 0);
RETURN_FALSE;
}

UnicodeString result;
TimeZone::getIanaID(id, result, status);
INTL_CHECK_STATUS(status, "error obtaining IANA ID");

zend_string *u8str = intl_convert_utf16_to_utf8(result.getBuffer(), result.length(), &status);
INTL_CHECK_STATUS(status,
"could not convert time zone id to UTF-16");
RETVAL_NEW_STR(u8str);
}
#endif

U_CFUNC PHP_FUNCTION(intltz_get_id)
{
TIMEZONE_METHOD_INIT_VARS;
Expand Down