LibJS+LibUnicode: Rename some Unicode::DayPeriod values

In the CLDR, there aren't "night" values, there are "night1" & "night2"
values. This is for locales which use a different name for nighttime
depending on the hour. For example, the ja locale uses "夜" between the
hours of 19:00 and 23:00, and "夜中" between the hours of 23:00 and
04:00. Our CLDR parser is currently ignoring "night2", so this rename
is to prepare for that.

We could probably come up with better names, but in the end, the API in
LibUnicode will be such that outside callers won't even see Night1, etc.
This commit is contained in:
Timothy Flynn 2021-12-10 11:44:24 -05:00 committed by Linus Groh
parent 1a5bf15b4d
commit 76aab821f4
Notes: sideshowbarker 2024-07-18 00:41:35 +09:00
3 changed files with 12 additions and 12 deletions

View file

@ -913,13 +913,13 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
else if (key == "pm"sv) else if (key == "pm"sv)
symbols[to_underlying(Unicode::DayPeriod::PM)] = locale_data.unique_strings.ensure(move(symbol)); symbols[to_underlying(Unicode::DayPeriod::PM)] = locale_data.unique_strings.ensure(move(symbol));
else if (key == "morning1"sv) else if (key == "morning1"sv)
symbols[to_underlying(Unicode::DayPeriod::Morning)] = locale_data.unique_strings.ensure(move(symbol)); symbols[to_underlying(Unicode::DayPeriod::Morning1)] = locale_data.unique_strings.ensure(move(symbol));
else if (key == "afternoon1"sv) else if (key == "afternoon1"sv)
symbols[to_underlying(Unicode::DayPeriod::Afternoon)] = locale_data.unique_strings.ensure(move(symbol)); symbols[to_underlying(Unicode::DayPeriod::Afternoon1)] = locale_data.unique_strings.ensure(move(symbol));
else if (key == "evening1"sv) else if (key == "evening1"sv)
symbols[to_underlying(Unicode::DayPeriod::Evening)] = locale_data.unique_strings.ensure(move(symbol)); symbols[to_underlying(Unicode::DayPeriod::Evening1)] = locale_data.unique_strings.ensure(move(symbol));
else if (key == "night1"sv) else if (key == "night1"sv)
symbols[to_underlying(Unicode::DayPeriod::Night)] = locale_data.unique_strings.ensure(move(symbol)); symbols[to_underlying(Unicode::DayPeriod::Night1)] = locale_data.unique_strings.ensure(move(symbol));
}; };
narrow_symbols.for_each_member([&](auto const& key, JsonValue const& value) { narrow_symbols.for_each_member([&](auto const& key, JsonValue const& value) {

View file

@ -760,12 +760,12 @@ static Optional<StringView> day_period_for_hour(StringView locale, StringView ca
// FIXME: This isn't locale-aware. We should parse the CLDR's cldr-core/supplemental/dayPeriods.json file // FIXME: This isn't locale-aware. We should parse the CLDR's cldr-core/supplemental/dayPeriods.json file
// to acquire day periods per-locale. For now, these are hard-coded to the en locale's values. // to acquire day periods per-locale. For now, these are hard-coded to the en locale's values.
if ((hour >= 6) && (hour < 12)) if ((hour >= 6) && (hour < 12))
return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Morning); return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Morning1);
if ((hour >= 12) && (hour < 18)) if ((hour >= 12) && (hour < 18))
return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Afternoon); return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Afternoon1);
if ((hour >= 18) && (hour < 21)) if ((hour >= 18) && (hour < 21))
return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Evening); return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Evening1);
return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Night); return Unicode::get_calendar_day_period_symbol(locale, calendar, style, Unicode::DayPeriod::Night1);
} }
// 11.1.7 FormatDateTimePattern ( dateTimeFormat, patternParts, x, rangeFormatOptions ), https://tc39.es/ecma402/#sec-formatdatetimepattern // 11.1.7 FormatDateTimePattern ( dateTimeFormat, patternParts, x, rangeFormatOptions ), https://tc39.es/ecma402/#sec-formatdatetimepattern

View file

@ -48,10 +48,10 @@ enum class Weekday : u8 {
enum class DayPeriod : u8 { enum class DayPeriod : u8 {
AM, AM,
PM, PM,
Morning, Morning1,
Afternoon, Afternoon1,
Evening, Evening1,
Night, Night1,
}; };
enum class HourCycle : u8 { enum class HourCycle : u8 {