1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

LibJS: Implement a nearly empty Intl.RelativeTimeFormat object

This adds plumbing for the Intl.RelativeTimeFormat object, constructor,
and prototype.
This commit is contained in:
Timothy Flynn 2022-01-25 10:41:57 -05:00 committed by Linus Groh
parent 0865f71d37
commit 79fdec85de
12 changed files with 271 additions and 1 deletions

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Intl/RelativeTimeFormat.h>
namespace JS::Intl {
// 17 RelativeTimeFormat Objects, https://tc39.es/ecma402/#relativetimeformat-objects
RelativeTimeFormat::RelativeTimeFormat(Object& prototype)
: Object(prototype)
{
}
void RelativeTimeFormat::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
if (m_number_format)
visitor.visit(m_number_format);
}
void RelativeTimeFormat::set_numeric(StringView numeric)
{
if (numeric == "always"sv) {
m_numeric = Numeric::Always;
} else if (numeric == "auto"sv) {
m_numeric = Numeric::Auto;
} else {
VERIFY_NOT_REACHED();
}
}
StringView RelativeTimeFormat::numeric_string() const
{
switch (m_numeric) {
case Numeric::Always:
return "always"sv;
case Numeric::Auto:
return "auto"sv;
default:
VERIFY_NOT_REACHED();
}
}
}