2021-11-27 19:54:48 +00:00
|
|
|
/*
|
2022-01-02 19:23:24 +00:00
|
|
|
* Copyright (c) 2021-2022, Tim Flynn <trflynn89@pm.me>
|
2021-11-27 19:54:48 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Types.h>
|
2021-11-27 22:31:31 +00:00
|
|
|
#include <AK/Vector.h>
|
2021-11-27 19:54:48 +00:00
|
|
|
#include <LibUnicode/Forward.h>
|
|
|
|
|
|
|
|
namespace Unicode {
|
|
|
|
|
2021-12-06 17:22:39 +00:00
|
|
|
enum class Era : u8 {
|
|
|
|
BC,
|
|
|
|
AD,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Month : u8 {
|
|
|
|
January,
|
|
|
|
February,
|
|
|
|
March,
|
|
|
|
April,
|
|
|
|
May,
|
|
|
|
June,
|
|
|
|
July,
|
|
|
|
August,
|
|
|
|
September,
|
|
|
|
October,
|
|
|
|
November,
|
|
|
|
December,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Weekday : u8 {
|
|
|
|
Sunday,
|
|
|
|
Monday,
|
|
|
|
Tuesday,
|
|
|
|
Wednesday,
|
|
|
|
Thursday,
|
|
|
|
Friday,
|
|
|
|
Saturday,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class DayPeriod : u8 {
|
|
|
|
AM,
|
|
|
|
PM,
|
2021-12-10 16:44:24 +00:00
|
|
|
Morning1,
|
2021-12-10 16:59:58 +00:00
|
|
|
Morning2,
|
2021-12-10 16:44:24 +00:00
|
|
|
Afternoon1,
|
2021-12-10 16:59:58 +00:00
|
|
|
Afternoon2,
|
2021-12-10 16:44:24 +00:00
|
|
|
Evening1,
|
2021-12-10 16:59:58 +00:00
|
|
|
Evening2,
|
2021-12-10 16:44:24 +00:00
|
|
|
Night1,
|
2021-12-10 16:59:58 +00:00
|
|
|
Night2,
|
2021-12-06 17:22:39 +00:00
|
|
|
};
|
|
|
|
|
LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
1. Check if the locale itself is assigned hour cycles.
2. If the locale has a region, check if that region is assigned hour
cycles.
3. Otherwise, maximize that locale, and if the maximized locale has
a region, check if that region is assigned hour cycles.
4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
2021-11-28 01:57:21 +00:00
|
|
|
enum class HourCycle : u8 {
|
|
|
|
H11,
|
|
|
|
H12,
|
|
|
|
H23,
|
|
|
|
H24,
|
|
|
|
};
|
|
|
|
|
2021-11-27 19:54:48 +00:00
|
|
|
enum class CalendarPatternStyle : u8 {
|
|
|
|
Narrow,
|
|
|
|
Short,
|
|
|
|
Long,
|
|
|
|
Numeric,
|
|
|
|
TwoDigit,
|
2022-01-02 19:23:24 +00:00
|
|
|
ShortOffset,
|
|
|
|
LongOffset,
|
|
|
|
ShortGeneric,
|
|
|
|
LongGeneric,
|
2021-11-27 19:54:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CalendarPattern {
|
2021-12-07 13:40:06 +00:00
|
|
|
enum class Field {
|
|
|
|
Era,
|
|
|
|
Year,
|
|
|
|
Month,
|
|
|
|
Weekday,
|
|
|
|
Day,
|
|
|
|
DayPeriod,
|
|
|
|
Hour,
|
|
|
|
Minute,
|
|
|
|
Second,
|
|
|
|
FractionalSecondDigits,
|
|
|
|
TimeZoneName,
|
|
|
|
};
|
|
|
|
|
2021-11-28 22:55:47 +00:00
|
|
|
template<typename Callback>
|
|
|
|
void for_each_calendar_field_zipped_with(CalendarPattern const& other, Callback&& callback)
|
|
|
|
{
|
2021-12-07 13:40:06 +00:00
|
|
|
callback(era, other.era, Field::Era);
|
|
|
|
callback(year, other.year, Field::Year);
|
|
|
|
callback(month, other.month, Field::Month);
|
|
|
|
callback(weekday, other.weekday, Field::Weekday);
|
|
|
|
callback(day, other.day, Field::Day);
|
|
|
|
callback(day_period, other.day_period, Field::DayPeriod);
|
|
|
|
callback(hour, other.hour, Field::Hour);
|
|
|
|
callback(minute, other.minute, Field::Minute);
|
|
|
|
callback(second, other.second, Field::Second);
|
|
|
|
callback(fractional_second_digits, other.fractional_second_digits, Field::FractionalSecondDigits);
|
|
|
|
callback(time_zone_name, other.time_zone_name, Field::TimeZoneName);
|
2021-11-28 22:55:47 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 18:42:04 +00:00
|
|
|
String skeleton {};
|
2021-11-27 19:54:48 +00:00
|
|
|
String pattern {};
|
|
|
|
Optional<String> pattern12 {};
|
|
|
|
|
|
|
|
// https://unicode.org/reports/tr35/tr35-dates.html#Calendar_Fields
|
|
|
|
Optional<CalendarPatternStyle> era {};
|
|
|
|
Optional<CalendarPatternStyle> year {};
|
|
|
|
Optional<CalendarPatternStyle> month {};
|
|
|
|
Optional<CalendarPatternStyle> weekday {};
|
|
|
|
Optional<CalendarPatternStyle> day {};
|
|
|
|
Optional<CalendarPatternStyle> day_period {};
|
|
|
|
Optional<CalendarPatternStyle> hour {};
|
|
|
|
Optional<CalendarPatternStyle> minute {};
|
|
|
|
Optional<CalendarPatternStyle> second {};
|
|
|
|
Optional<u8> fractional_second_digits {};
|
|
|
|
Optional<CalendarPatternStyle> time_zone_name {};
|
|
|
|
};
|
|
|
|
|
2021-12-08 22:07:30 +00:00
|
|
|
struct CalendarRangePattern : public CalendarPattern {
|
|
|
|
enum class Field {
|
|
|
|
Era,
|
|
|
|
Year,
|
|
|
|
Month,
|
|
|
|
Day,
|
|
|
|
AmPm,
|
|
|
|
DayPeriod,
|
|
|
|
Hour,
|
|
|
|
Minute,
|
|
|
|
Second,
|
|
|
|
FractionalSecondDigits,
|
|
|
|
};
|
|
|
|
|
|
|
|
Optional<Field> field {};
|
|
|
|
String start_range {};
|
|
|
|
StringView separator {};
|
|
|
|
String end_range {};
|
|
|
|
};
|
|
|
|
|
2021-11-27 19:54:48 +00:00
|
|
|
enum class CalendarFormatType : u8 {
|
|
|
|
Date,
|
|
|
|
Time,
|
|
|
|
DateTime,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CalendarFormat {
|
|
|
|
CalendarPattern full_format {};
|
|
|
|
CalendarPattern long_format {};
|
|
|
|
CalendarPattern medium_format {};
|
|
|
|
CalendarPattern short_format {};
|
|
|
|
};
|
|
|
|
|
2021-12-11 20:31:33 +00:00
|
|
|
enum class CalendarSymbol : u8 {
|
|
|
|
DayPeriod,
|
|
|
|
Era,
|
|
|
|
Month,
|
|
|
|
Weekday,
|
|
|
|
};
|
|
|
|
|
LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
1. Check if the locale itself is assigned hour cycles.
2. If the locale has a region, check if that region is assigned hour
cycles.
3. Otherwise, maximize that locale, and if the maximized locale has
a region, check if that region is assigned hour cycles.
4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
2021-11-28 01:57:21 +00:00
|
|
|
HourCycle hour_cycle_from_string(StringView hour_cycle);
|
|
|
|
StringView hour_cycle_to_string(HourCycle hour_cycle);
|
2021-11-27 19:54:48 +00:00
|
|
|
CalendarPatternStyle calendar_pattern_style_from_string(StringView style);
|
|
|
|
StringView calendar_pattern_style_to_string(CalendarPatternStyle style);
|
LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
1. Check if the locale itself is assigned hour cycles.
2. If the locale has a region, check if that region is assigned hour
cycles.
3. Otherwise, maximize that locale, and if the maximized locale has
a region, check if that region is assigned hour cycles.
4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
2021-11-28 01:57:21 +00:00
|
|
|
Vector<Unicode::HourCycle> get_regional_hour_cycles(StringView locale);
|
|
|
|
Optional<Unicode::HourCycle> get_default_regional_hour_cycle(StringView locale);
|
2021-12-09 00:52:48 +00:00
|
|
|
String combine_skeletons(StringView first, StringView second);
|
2021-11-27 19:54:48 +00:00
|
|
|
Optional<CalendarFormat> get_calendar_format(StringView locale, StringView calendar, CalendarFormatType type);
|
2021-11-27 22:31:31 +00:00
|
|
|
Vector<CalendarPattern> get_calendar_available_formats(StringView locale, StringView calendar);
|
2021-12-08 22:07:30 +00:00
|
|
|
Optional<Unicode::CalendarRangePattern> get_calendar_default_range_format(StringView locale, StringView calendar);
|
|
|
|
Vector<Unicode::CalendarRangePattern> get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton);
|
|
|
|
Vector<Unicode::CalendarRangePattern> get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton);
|
2021-12-06 17:22:39 +00:00
|
|
|
Optional<StringView> get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Era value);
|
|
|
|
Optional<StringView> get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Month value);
|
|
|
|
Optional<StringView> get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::Weekday value);
|
|
|
|
Optional<StringView> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Unicode::DayPeriod value);
|
2021-12-10 17:57:17 +00:00
|
|
|
Optional<StringView> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
|
2021-12-06 20:46:49 +00:00
|
|
|
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style);
|
2021-11-27 19:54:48 +00:00
|
|
|
|
|
|
|
}
|