Coverage Report

Created: 2025-08-28 06:26

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