mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
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.
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021-2024, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Runtime/NativeFunction.h>
|
|
|
|
namespace JS::Intl {
|
|
|
|
class DateTimeFormatConstructor final : public NativeFunction {
|
|
JS_OBJECT(DateTimeFormatConstructor, NativeFunction);
|
|
GC_DECLARE_ALLOCATOR(DateTimeFormatConstructor);
|
|
|
|
public:
|
|
virtual void initialize(Realm&) override;
|
|
virtual ~DateTimeFormatConstructor() override = default;
|
|
|
|
virtual ThrowCompletionOr<Value> call() override;
|
|
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
|
|
|
|
private:
|
|
explicit DateTimeFormatConstructor(Realm&);
|
|
|
|
virtual bool has_constructor() const override { return true; }
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);
|
|
};
|
|
|
|
enum class OptionRequired {
|
|
Any,
|
|
Date,
|
|
Time,
|
|
YearMonth,
|
|
MonthDay,
|
|
};
|
|
|
|
enum class OptionDefaults {
|
|
All,
|
|
Date,
|
|
Time,
|
|
YearMonth,
|
|
MonthDay,
|
|
ZonedDateTime,
|
|
};
|
|
|
|
enum class OptionInherit {
|
|
All,
|
|
Relevant,
|
|
};
|
|
|
|
ThrowCompletionOr<GC::Ref<DateTimeFormat>> create_date_time_format(VM&, FunctionObject& new_target, Value locales_value, Value options_value, OptionRequired, OptionDefaults, Optional<String> const& to_locale_string_time_zone = {});
|
|
String format_offset_time_zone_identifier(double offset_minutes);
|
|
|
|
}
|