-
Notifications
You must be signed in to change notification settings - Fork 462
Improve handling of no-inheritance-marker in timezone data #1194
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
+161
−2
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| bin/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| bin/icu4c_date_format: icu4c_date_format.cpp | ||
| mkdir -p bin | ||
| $(CXX) -Wall -std=c++17 -o $@ $^ $(shell pkg-config --cflags --libs icu-uc icu-i18n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # icu4c-tools | ||
|
|
||
| Some haphazard tools for cross-checking results between ICU4C and Babel. | ||
| These are not meant to be production-ready or e.g. guaranteed to not leak memory in any way. | ||
|
|
||
| ## icu4c_date_format | ||
|
|
||
| ### Compiling | ||
|
|
||
| This worked on my macOS – on a Linux machine, you shouldn't need the `PKG_CONFIG_PATH` environment variable. | ||
|
|
||
| ``` | ||
| env PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c@76/lib/pkgconfig" make bin/icu4c_date_format | ||
| ``` | ||
|
|
||
| ### Running | ||
|
|
||
| E.g. | ||
|
|
||
| ``` | ||
| env TEST_TIMEZONES=Pacific/Honolulu TEST_LOCALES=en_US,en,en_GB TEST_TIME_FORMAT="YYYY-MM-dd H:mm zz" bin/icu4c_date_format | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #include <iostream> | ||
| #include <sstream> | ||
| #include <unicode/smpdtfmt.h> | ||
| #include <unicode/timezone.h> | ||
|
|
||
| static std::vector<std::string> split(const std::string &s, char delimiter) { | ||
| std::vector<std::string> tokens; | ||
| std::string token; | ||
| std::istringstream tokenStream(s); | ||
| while (std::getline(tokenStream, token, delimiter)) { | ||
| tokens.push_back(token); | ||
| } | ||
| return tokens; | ||
| } | ||
|
|
||
| static UDate parse_time_str(const char *time_str) { | ||
| UErrorCode status = U_ZERO_ERROR; | ||
| icu::UnicodeString fauxISO8601("yyyy-MM-dd'T'hh:mm:ss'Z'"); | ||
| auto fmt = new icu::SimpleDateFormat(fauxISO8601, status); | ||
| fmt->setTimeZone(*icu::TimeZone::getGMT()); | ||
| UDate date = fmt->parse(icu::UnicodeString(time_str), status); | ||
| if (U_FAILURE(status)) { | ||
| std::cerr << "Failed to parse time string: " << time_str << std::endl; | ||
| exit(1); | ||
| } | ||
| return date; | ||
| } | ||
|
|
||
| static std::vector<icu::Locale> parse_locales(const char *locales_str) { | ||
| auto locales = std::vector<icu::Locale>{}; | ||
| for (auto token : split(locales_str, ',')) { | ||
| auto loc = icu::Locale(token.c_str()); | ||
| if (loc.isBogus()) { | ||
| std::cerr << "Invalid locale: " << token << std::endl; | ||
| exit(1); | ||
| } | ||
| locales.push_back(loc); | ||
| } | ||
| return locales; | ||
| } | ||
|
|
||
| static std::vector<icu::TimeZone *> parse_timezones(const char *timezones_str) { | ||
| auto timezones = std::vector<icu::TimeZone *>{}; | ||
| for (auto token : split(timezones_str, ',')) { | ||
| auto tz = icu::TimeZone::createTimeZone(token.c_str()); | ||
| if (tz == nullptr) { | ||
| std::cerr << "Invalid timezone: " << token << std::endl; | ||
| exit(1); | ||
| } | ||
| timezones.push_back(tz); | ||
| } | ||
| return timezones; | ||
| } | ||
|
|
||
| int main() { | ||
| UErrorCode status = U_ZERO_ERROR; | ||
| const char *timezones_str = getenv("TEST_TIMEZONES"); | ||
| const char *locales_str = getenv("TEST_LOCALES"); | ||
| const char *time_str = getenv("TEST_TIME"); | ||
| const char *time_format_str = getenv("TEST_TIME_FORMAT"); | ||
|
|
||
| if (!timezones_str || !locales_str) { | ||
| std::cerr << "Please set TEST_TIMEZONES, TEST_LOCALES environment variables" | ||
| << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| if (time_str == nullptr) { | ||
| time_str = "2025-03-04T13:53:00Z"; | ||
| std::cerr << "Defaulting TEST_TIME to " << time_str << std::endl; | ||
| } | ||
|
|
||
| if (time_format_str == nullptr) { | ||
| time_format_str = "z:zz:zzz:zzzz"; | ||
| std::cerr << "Defaulting TEST_TIME_FORMAT to " << time_format_str | ||
| << std::endl; | ||
| } | ||
|
|
||
| auto date = parse_time_str(time_str); | ||
| auto timezones = parse_timezones(timezones_str); | ||
| auto locales = parse_locales(locales_str); | ||
|
|
||
| for (auto tz : timezones) { | ||
| icu::UnicodeString tzid; | ||
| tz->getID(tzid); | ||
| std::string tzid_str; | ||
| tzid.toUTF8String(tzid_str); | ||
| for (auto loc : locales) { | ||
| auto fmt = new icu::SimpleDateFormat(time_format_str, loc, status); | ||
| fmt->setTimeZone(*tz); | ||
| icu::UnicodeString name; | ||
| fmt->format(date, name); | ||
| std::string result; | ||
| name.toUTF8String(result); | ||
| std::cout << tzid_str << "\t" << loc.getName() << "\t" << result | ||
| << std::endl; | ||
| delete fmt; | ||
| } | ||
| } | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some digging and we get
Hawaii-Aleutian Standard Timeinstead ofGMT-10here because of this fallback to the long tz name:babel/babel/dates.py
Lines 659 to 662 in 2b93a4a
When I get rid of it,
get_timezone_gmtis used instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, I should've mentioned I also found the culprit, but it's out of scope for this PR 😅