mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
LibJS: Implement a nearly empty Intl.DateTimeFormat object
This adds plumbing for the Intl.DateTimeFormat object, constructor, and prototype. Note that unlike other Intl objects, the Intl.DateTimeFormat object has a LibUnicode structure as a base. This is to prevent wild amounts of code duplication between LibUnicode, Intl.DateTimeFormat, and other not-yet-defined Intl structures, because there's 12 fields shared between them.
This commit is contained in:
committed by
Linus Groh
parent
6dbdfb6ba1
commit
75b2a09a2f
Notes:
sideshowbarker
2024-07-17 23:22:24 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/75b2a09a2f3 Pull-request: https://github.com/SerenityOS/serenity/pull/11128 Reviewed-by: https://github.com/linusg ✅
54
Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
Normal file
54
Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Intl/DateTimeFormat.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
Vector<StringView> const& DateTimeFormat::relevant_extension_keys()
|
||||
{
|
||||
// 11.3.3 Internal slots, https://tc39.es/ecma402/#sec-intl.datetimeformat-internal-slots
|
||||
// The value of the [[RelevantExtensionKeys]] internal slot is « "ca", "hc", "nu" ».
|
||||
static Vector<StringView> relevant_extension_keys { "ca"sv, "hc"sv, "nu"sv };
|
||||
return relevant_extension_keys;
|
||||
}
|
||||
|
||||
// 11 DateTimeFormat Objects, https://tc39.es/ecma402/#datetimeformat-objects
|
||||
DateTimeFormat::DateTimeFormat(Object& prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
}
|
||||
|
||||
DateTimeFormat::Style DateTimeFormat::style_from_string(StringView style)
|
||||
{
|
||||
if (style == "full"sv)
|
||||
return Style::Full;
|
||||
if (style == "long"sv)
|
||||
return Style::Long;
|
||||
if (style == "medium"sv)
|
||||
return Style::Medium;
|
||||
if (style == "short"sv)
|
||||
return Style::Short;
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
StringView DateTimeFormat::style_to_string(Style style)
|
||||
{
|
||||
switch (style) {
|
||||
case Style::Full:
|
||||
return "full"sv;
|
||||
case Style::Long:
|
||||
return "long"sv;
|
||||
case Style::Medium:
|
||||
return "medium"sv;
|
||||
case Style::Short:
|
||||
return "short"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user