1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
* Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <LibLocale/Forward.h>
#include <LibTimeZone/TimeZone.h>
namespace Locale {
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,
Noon,
Morning1,
Morning2,
Afternoon1,
Afternoon2,
Evening1,
Evening2,
Night1,
Night2,
};
enum class HourCycle : u8 {
H11,
H12,
H23,
H24,
};
enum class CalendarPatternStyle : u8 {
Narrow,
Short,
Long,
Numeric,
TwoDigit,
ShortOffset,
LongOffset,
ShortGeneric,
LongGeneric,
};
struct CalendarPattern {
enum class Field {
Era,
Year,
Month,
Weekday,
Day,
DayPeriod,
Hour,
Minute,
Second,
FractionalSecondDigits,
TimeZoneName,
};
template<typename Callback>
void for_each_calendar_field_zipped_with(CalendarPattern const& other, Callback&& callback)
{
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);
}
String skeleton {};
String pattern {};
Optional<String> pattern12 {};
Optional<HourCycle> hour_cycle {};
// 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 {};
};
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 {};
};
enum class CalendarFormatType : u8 {
Date,
Time,
DateTime,
};
struct CalendarFormat {
CalendarPattern full_format {};
CalendarPattern long_format {};
CalendarPattern medium_format {};
CalendarPattern short_format {};
};
enum class CalendarSymbol : u8 {
DayPeriod,
Era,
Month,
Weekday,
};
struct TimeZoneFormat {
StringView symbol_ahead_sign {};
StringView symbol_ahead_separator {};
StringView symbol_behind_sign {};
StringView symbol_behind_separator {};
StringView gmt_format {};
StringView gmt_zero_format {};
};
HourCycle hour_cycle_from_string(StringView hour_cycle);
StringView hour_cycle_to_string(HourCycle hour_cycle);
CalendarPatternStyle calendar_pattern_style_from_string(StringView style);
StringView calendar_pattern_style_to_string(CalendarPatternStyle style);
Optional<HourCycleRegion> hour_cycle_region_from_string(StringView hour_cycle_region);
ErrorOr<Vector<HourCycle>> get_regional_hour_cycles(StringView region);
ErrorOr<Vector<HourCycle>> get_locale_hour_cycles(StringView locale);
ErrorOr<Optional<HourCycle>> get_default_regional_hour_cycle(StringView locale);
Optional<MinimumDaysRegion> minimum_days_region_from_string(StringView minimum_days_region);
Optional<u8> get_regional_minimum_days(StringView region);
ErrorOr<Optional<u8>> get_locale_minimum_days(StringView locale);
Optional<FirstDayRegion> first_day_region_from_string(StringView first_day_region);
Optional<Weekday> get_regional_first_day(StringView region);
ErrorOr<Optional<Weekday>> get_locale_first_day(StringView locale);
Optional<WeekendStartRegion> weekend_start_region_from_string(StringView weekend_start_region);
Optional<Weekday> get_regional_weekend_start(StringView region);
ErrorOr<Optional<Weekday>> get_locale_weekend_start(StringView locale);
Optional<WeekendEndRegion> weekend_end_region_from_string(StringView weekend_end_region);
Optional<Weekday> get_regional_weekend_end(StringView region);
ErrorOr<Optional<Weekday>> get_locale_weekend_end(StringView locale);
ErrorOr<String> combine_skeletons(StringView first, StringView second);
ErrorOr<Optional<CalendarFormat>> get_calendar_date_format(StringView locale, StringView calendar);
ErrorOr<Optional<CalendarFormat>> get_calendar_time_format(StringView locale, StringView calendar);
ErrorOr<Optional<CalendarFormat>> get_calendar_date_time_format(StringView locale, StringView calendar);
ErrorOr<Optional<CalendarFormat>> get_calendar_format(StringView locale, StringView calendar, CalendarFormatType type);
ErrorOr<Vector<CalendarPattern>> get_calendar_available_formats(StringView locale, StringView calendar);
ErrorOr<Optional<CalendarRangePattern>> get_calendar_default_range_format(StringView locale, StringView calendar);
ErrorOr<Vector<CalendarRangePattern>> get_calendar_range_formats(StringView locale, StringView calendar, StringView skeleton);
ErrorOr<Vector<CalendarRangePattern>> get_calendar_range12_formats(StringView locale, StringView calendar, StringView skeleton);
ErrorOr<Optional<StringView>> get_calendar_era_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Era value);
ErrorOr<Optional<StringView>> get_calendar_month_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Month value);
ErrorOr<Optional<StringView>> get_calendar_weekday_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, Weekday value);
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Duration time);
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style, TimeZone::InDST in_dst);
Optional<TimeZoneFormat> get_time_zone_format(StringView locale);
}
|