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

Conversation

devnexen
Copy link
Member

returns the primary IANA zone ID from the provided timezone ID. Most of the time, timezone ID==IANA ID.
available from icu >= 74.

@devnexen
Copy link
Member Author

no systems in CI supports icu >= 74 yet, but tested on my ubuntu 24.04 instance.

@devnexen devnexen requested a review from Girgias February 17, 2024 16:20
@@ -112,6 +112,14 @@ public function getErrorMessage(): string|false {}
*/
public static function getGMT(): IntlTimeZone {}

#if U_ICU_VERSION_MAJOR_NUM >= 74
/**
* @tentative-return-type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to use a real return type because there is no BC impact of new methods (besides accidental collision iwth similarly named userland methods)

UnicodeString id;
if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) {
intl_error_set(NULL, status,
"intltz_get_iana_id: could not convert time zone id to UTF-16", 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual function/method name can be retrieved via using get_active_function_or_method_name

@devnexen devnexen force-pushed the ext_intl_timezone_ianaid branch 2 times, most recently from b838a67 to 9f727a1 Compare February 17, 2024 22:49
@@ -112,6 +112,14 @@ public function getErrorMessage(): string|false {}
*/
public static function getGMT(): IntlTimeZone {}

#if U_ICU_VERSION_MAJOR_NUM >= 74
/**
* @return string|false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary anymore :)

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

zend_string *u8str =intl_convert_utf16_to_utf8(result.getBuffer(), result.length(), &status);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit:

Suggested change
zend_string *u8str =intl_convert_utf16_to_utf8(result.getBuffer(), result.length(), &status);
zend_string *u8str = intl_convert_utf16_to_utf8(result.getBuffer(), result.length(), &status);

@devnexen devnexen force-pushed the ext_intl_timezone_ianaid branch from 9f727a1 to 35b12b9 Compare February 18, 2024 08:55
Comment on lines 17 to 20
Warning: IntlTimeZone::getIanaID(): intltz_get_iana_id: could not convert time zone id to UTF-16 in %s on line %d
bool(false)

Warning: IntlTimeZone::getIanaID(): intltz_get_iana_id: error obtaining IANA ID in %s on line %d
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that the INTL warning mechanism is jank... Having intltz_get_iana_id: is kinda pointless...

@devnexen
Copy link
Member Author

ping :)

UnicodeString id;
if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) {
intl_error_set(NULL, status,
"intltz_get_iana_id: could not convert time zone id to UTF-16", 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"intltz_get_iana_id: could not convert time zone id to UTF-16", 0);
"could not convert time zone id to UTF-16", 0);

This looks unneeded? Or if using the exception mode, then the message looks weird?

Also does this actually have a procedural equivalent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ; I was just trying to be consistent with the rest. However since it s master I ll do the same with the rest, not too much of a BC I don t think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing the error message is fine in master because it is somewhat weird.

@devnexen devnexen force-pushed the ext_intl_timezone_ianaid branch from 35b12b9 to 3efc4a5 Compare February 21, 2024 05:47
returns the primary IANA zone ID from the provided timezone ID.
Most of the time, timezone ID==IANA ID.
available from icu >= 74.
@devnexen devnexen force-pushed the ext_intl_timezone_ianaid branch from 3efc4a5 to 9b582e7 Compare February 21, 2024 06:30
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@devnexen devnexen closed this in 22a3866 Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants