From a24cb95b3b385145a1c39c9475844592b134d3de Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Sun, 15 Oct 2023 10:43:10 +0000 Subject: [PATCH] Bug 1856428 - MacOS Sonoma doesn't return correct timezone. r=anba, a=dmeehan Import from https://unicode-org.atlassian.net/browse/ICU-22541 (https://github.com/unicode-org/icu/pull/2669). Differential Revision: https://phabricator.services.mozilla.com/D191013 --- intl/icu-patches/bug-1856428-ICU-22541.diff | 39 +++++++++++++++++++++ intl/icu/source/common/putil.cpp | 15 ++++++++ intl/update-icu.sh | 1 + 3 files changed, 55 insertions(+) create mode 100644 intl/icu-patches/bug-1856428-ICU-22541.diff diff --git a/intl/icu-patches/bug-1856428-ICU-22541.diff b/intl/icu-patches/bug-1856428-ICU-22541.diff new file mode 100644 index 0000000000000..64c98c3e109ee --- /dev/null +++ b/intl/icu-patches/bug-1856428-ICU-22541.diff @@ -0,0 +1,39 @@ +# Fix MacOS 14 default timezone issue +# +# ICU bug: https://unicode-org.atlassian.net/browse/ICU-22541 + +diff --git a/intl/icu/source/common/putil.cpp b/intl/icu/source/common/putil.cpp +--- a/intl/icu/source/common/putil.cpp ++++ b/intl/icu/source/common/putil.cpp +@@ -1170,16 +1170,31 @@ uprv_tzname(int n) + This is a trick to look at the name of the link to get the Olson ID + because the tzfile contents is underspecified. + This isn't guaranteed to work because it may not be a symlink. + */ + char *ret = realpath(TZDEFAULT, gTimeZoneBuffer); + if (ret != nullptr && uprv_strcmp(TZDEFAULT, gTimeZoneBuffer) != 0) { + int32_t tzZoneInfoTailLen = uprv_strlen(TZZONEINFOTAIL); + const char *tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); ++ // MacOS14 has the realpath as something like ++ // /usr/share/zoneinfo.default/Australia/Melbourne ++ // which will not have "/zoneinfo/" in the path. ++ // Therefore if we fail, we fall back to read the link which is ++ // /var/db/timezone/zoneinfo/Australia/Melbourne ++ // We also fall back to reading the link if the realpath leads to something like ++ // /usr/share/zoneinfo/posixrules ++ if (tzZoneInfoTailPtr == nullptr || ++ uprv_strcmp(tzZoneInfoTailPtr + tzZoneInfoTailLen, "posixrules") == 0) { ++ ssize_t size = readlink(TZDEFAULT, gTimeZoneBuffer, sizeof(gTimeZoneBuffer)-1); ++ if (size > 0) { ++ gTimeZoneBuffer[size] = 0; ++ tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); ++ } ++ } + if (tzZoneInfoTailPtr != nullptr) { + tzZoneInfoTailPtr += tzZoneInfoTailLen; + skipZoneIDPrefix(&tzZoneInfoTailPtr); + if (isValidOlsonID(tzZoneInfoTailPtr)) { + return (gTimeZoneBufferPtr = tzZoneInfoTailPtr); + } + } + } else { diff --git a/intl/icu/source/common/putil.cpp b/intl/icu/source/common/putil.cpp index ab904af20ac41..ab25f3b996de4 100644 --- a/intl/icu/source/common/putil.cpp +++ b/intl/icu/source/common/putil.cpp @@ -1175,6 +1175,21 @@ uprv_tzname(int n) if (ret != nullptr && uprv_strcmp(TZDEFAULT, gTimeZoneBuffer) != 0) { int32_t tzZoneInfoTailLen = uprv_strlen(TZZONEINFOTAIL); const char *tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); + // MacOS14 has the realpath as something like + // /usr/share/zoneinfo.default/Australia/Melbourne + // which will not have "/zoneinfo/" in the path. + // Therefore if we fail, we fall back to read the link which is + // /var/db/timezone/zoneinfo/Australia/Melbourne + // We also fall back to reading the link if the realpath leads to something like + // /usr/share/zoneinfo/posixrules + if (tzZoneInfoTailPtr == nullptr || + uprv_strcmp(tzZoneInfoTailPtr + tzZoneInfoTailLen, "posixrules") == 0) { + ssize_t size = readlink(TZDEFAULT, gTimeZoneBuffer, sizeof(gTimeZoneBuffer)-1); + if (size > 0) { + gTimeZoneBuffer[size] = 0; + tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); + } + } if (tzZoneInfoTailPtr != nullptr) { tzZoneInfoTailPtr += tzZoneInfoTailLen; skipZoneIDPrefix(&tzZoneInfoTailPtr); diff --git a/intl/update-icu.sh b/intl/update-icu.sh index 78adacd4e9387..c63c8c248eecc 100755 --- a/intl/update-icu.sh +++ b/intl/update-icu.sh @@ -60,6 +60,7 @@ for patch in \ bug-1790071-ICU-22132-standardize-vtzone-output.diff \ bug-1838173-ICU-22412-start-time-iso8601.diff \ double-conversion.diff \ + bug-1856428-ICU-22541.diff \ ; do echo "Applying local patch $patch" patch -d ${icu_dir}/../../ -p1 --no-backup-if-mismatch < ${icu_dir}/../icu-patches/$patch