LibJS+LibUnicode: Migrate some Temporal calendar types to LibUnicode
These will be needed for calendar operations involving ICU.
This commit is contained in:
parent
b322d0fe84
commit
a41f2f56a8
8 changed files with 66 additions and 37 deletions
|
|
@ -313,11 +313,9 @@ JS_ENUMERATE_TEMPORAL_OBJECTS
|
|||
class Now;
|
||||
class Temporal;
|
||||
|
||||
struct CalendarDate;
|
||||
struct CalendarFields;
|
||||
struct DateDuration;
|
||||
struct InternalDuration;
|
||||
struct ISODate;
|
||||
struct ISODateTime;
|
||||
struct ISOYearMonth;
|
||||
struct ParseResult;
|
||||
|
|
|
|||
|
|
@ -352,12 +352,6 @@ auto remainder(Crypto::BigInteger auto const& x, Crypto::BigInteger auto const&
|
|||
return x.divided_by(y).remainder;
|
||||
}
|
||||
|
||||
// 14.3 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type
|
||||
struct YearWeek {
|
||||
Optional<u8> week;
|
||||
Optional<i32> year;
|
||||
};
|
||||
|
||||
// 14.5.1.1 ToIntegerIfIntegral ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerifintegral
|
||||
template<typename... Args>
|
||||
ThrowCompletionOr<double> to_integer_if_integral(VM& vm, Value argument, ErrorType const& error_type, Args&&... args)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
|
||||
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
* Copyright (c) 2024-2026, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -15,34 +15,20 @@
|
|||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibUnicode/Calendar.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
||||
extern String ISO8601_CALENDAR;
|
||||
|
||||
// 12.2 Month Codes, https://tc39.es/proposal-temporal/#sec-temporal-month-codes
|
||||
struct MonthCode {
|
||||
u8 month_number { 0 };
|
||||
bool is_leap_month { false };
|
||||
};
|
||||
using MonthCode = Unicode::MonthCode;
|
||||
|
||||
// 12.3.1 Calendar Date Records, https://tc39.es/proposal-temporal/#sec-temporal-calendar-date-records
|
||||
struct CalendarDate {
|
||||
Optional<String> era;
|
||||
Optional<i32> era_year;
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
String month_code;
|
||||
u8 day { 0 };
|
||||
u8 day_of_week { 0 };
|
||||
u16 day_of_year { 0 };
|
||||
YearWeek week_of_year;
|
||||
u8 days_in_week { 0 };
|
||||
u8 days_in_month { 0 };
|
||||
u16 days_in_year { 0 };
|
||||
u8 months_in_year { 0 };
|
||||
bool in_leap_year { false };
|
||||
};
|
||||
using CalendarDate = Unicode::CalendarDate;
|
||||
|
||||
// 14.3 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type
|
||||
using YearWeek = Unicode::YearWeek;
|
||||
|
||||
// https://tc39.es/proposal-temporal/#table-temporal-calendar-fields-record-fields
|
||||
enum class CalendarField {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
* Copyright (c) 2024-2026, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -11,15 +11,12 @@
|
|||
#include <AK/Types.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
#include <LibUnicode/Calendar.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
||||
// 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
|
||||
struct ISODate {
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
u8 day { 0 };
|
||||
};
|
||||
using ISODate = Unicode::ISODate;
|
||||
|
||||
// 4.5.1 Time Records, https://tc39.es/proposal-temporal/#sec-temporal-time-records
|
||||
struct Time {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include <AK/NumericLimits.h>
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Date.h>
|
||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||
#include <LibJS/Runtime/Temporal/DateEquations.h>
|
||||
#include <LibJS/Runtime/Temporal/Duration.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||
#include <LibJS/Runtime/Temporal/ISORecords.h>
|
||||
|
||||
namespace JS::Temporal {
|
||||
|
|
|
|||
52
Libraries/LibUnicode/Calendar.h
Normal file
52
Libraries/LibUnicode/Calendar.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2026, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Unicode {
|
||||
|
||||
// 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
|
||||
struct ISODate {
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
u8 day { 0 };
|
||||
};
|
||||
|
||||
// 12.2 Month Codes, https://tc39.es/proposal-temporal/#sec-temporal-month-codes
|
||||
struct MonthCode {
|
||||
u8 month_number { 0 };
|
||||
bool is_leap_month { false };
|
||||
};
|
||||
|
||||
// 14.3 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type
|
||||
struct YearWeek {
|
||||
Optional<u8> week;
|
||||
Optional<i32> year;
|
||||
};
|
||||
|
||||
// 12.3.1 Calendar Date Records, https://tc39.es/proposal-temporal/#sec-temporal-calendar-date-records
|
||||
struct CalendarDate {
|
||||
Optional<String> era;
|
||||
Optional<i32> era_year;
|
||||
i32 year { 0 };
|
||||
u8 month { 0 };
|
||||
String month_code;
|
||||
u8 day { 0 };
|
||||
u8 day_of_week { 0 };
|
||||
u16 day_of_year { 0 };
|
||||
YearWeek week_of_year;
|
||||
u8 days_in_week { 0 };
|
||||
u8 days_in_month { 0 };
|
||||
u16 days_in_year { 0 };
|
||||
u8 months_in_year { 0 };
|
||||
bool in_leap_year { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
* Copyright (c) 2021-2026, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -14,9 +14,11 @@ namespace Unicode {
|
|||
class NumberFormat;
|
||||
class Segmenter;
|
||||
|
||||
struct CalendarDate;
|
||||
struct CalendarPattern;
|
||||
struct CurrencyCode;
|
||||
struct Emoji;
|
||||
struct ISODate;
|
||||
struct Keyword;
|
||||
struct LanguageID;
|
||||
struct ListFormatPart;
|
||||
|
|
|
|||
Loading…
Reference in a new issue