LibJS+LibUnicode: Integrate Temporal into Intl.DateTimeFormat

The gist is that we need to construct an ICU date-time formatter for
each possible Temporal type. This is of course going to be expensive.
So instead, we construct the configurations needed for the ICU objects
in the Intl.DateTimeFormat constructor, and defer creating the actual
ICU objects until they are needed.

Each formatting prototype can also now accept either a number (as they
already did), or any of the supported Temporal objects. These types may
not be mixed, and their properties (namely, their calendar) must align
with the Intl.DateTimeFormat object.
This commit is contained in:
Timothy Flynn 2024-11-27 16:09:41 -05:00 committed by Andreas Kling
commit ea503a4f68
Notes: github-actions[bot] 2024-11-29 08:53:47 +00:00
12 changed files with 1348 additions and 210 deletions

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/IterationDecision.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
@ -60,9 +61,60 @@ CalendarPatternStyle calendar_pattern_style_from_string(StringView style);
StringView calendar_pattern_style_to_string(CalendarPatternStyle style);
struct CalendarPattern {
enum class Field {
Era,
Year,
Month,
Weekday,
Day,
DayPeriod,
Hour,
Minute,
Second,
FractionalSecondDigits,
TimeZoneName,
};
static CalendarPattern create_from_pattern(StringView);
String to_pattern() const;
template<typename Callback>
void for_each_calendar_field_zipped_with(CalendarPattern& other, ReadonlySpan<Field> filter, Callback&& callback) const
{
auto invoke_callback_for_field = [&](auto field) {
switch (field) {
case Field::Era:
return callback(era, other.era);
case Field::Year:
return callback(year, other.year);
case Field::Month:
return callback(month, other.month);
case Field::Weekday:
return callback(weekday, other.weekday);
case Field::Day:
return callback(day, other.day);
case Field::DayPeriod:
return callback(day_period, other.day_period);
case Field::Hour:
return callback(hour, other.hour);
case Field::Minute:
return callback(minute, other.minute);
case Field::Second:
return callback(second, other.second);
case Field::FractionalSecondDigits:
return callback(fractional_second_digits, other.fractional_second_digits);
case Field::TimeZoneName:
return callback(time_zone_name, other.time_zone_name);
}
VERIFY_NOT_REACHED();
};
for (auto field : filter) {
if (invoke_callback_for_field(field) == IterationDecision::Break)
break;
}
}
Optional<HourCycle> hour_cycle;
Optional<bool> hour12;