diff --git a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 2b13e50c03c..6fc6a482d2a 100644 --- a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index a91f95f80f3..316751566bd 100644 --- a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -134,25 +134,6 @@ struct RelativeTo { GC::Ptr zoned_relative_to; // [[ZonedRelativeTo]] }; -// 13.31 ISO String Time Zone Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-string-time-zone-parse-records -struct ParsedISOTimeZone { - bool z_designator { false }; - Optional offset_string; - Optional time_zone_annotation; -}; - -// 13.32 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records -struct ParsedISODateTime { - struct StartOfDay { }; - - Optional year { 0 }; - u8 month { 0 }; - u8 day { 0 }; - Variant time; - ParsedISOTimeZone time_zone; - Optional calendar; -}; - struct DifferenceSettings { Unit smallest_unit; Unit largest_unit; diff --git a/Libraries/LibJS/Runtime/Temporal/Duration.h b/Libraries/LibJS/Runtime/Temporal/Duration.h index 70697331d9a..13aaf86821d 100644 --- a/Libraries/LibJS/Runtime/Temporal/Duration.h +++ b/Libraries/LibJS/Runtime/Temporal/Duration.h @@ -10,10 +10,10 @@ #include #include -#include #include #include #include +#include #include namespace JS::Temporal { @@ -89,10 +89,6 @@ struct PartialDuration { Optional nanoseconds; }; -// A time duration is an integer in the inclusive interval from -maxTimeDuration to maxTimeDuration, where -// maxTimeDuration = 2**53 × 10**9 - 1 = 9,007,199,254,740,991,999,999,999. It represents the portion of a -// Temporal.Duration object that deals with time units, but as a combined value of total nanoseconds. -using TimeDuration = Crypto::SignedBigInteger; extern TimeDuration const MAX_TIME_DURATION; // 7.5.3 Internal Duration Records, https://tc39.es/proposal-temporal/#sec-temporal-internal-duration-records diff --git a/Libraries/LibJS/Runtime/Temporal/ISORecords.h b/Libraries/LibJS/Runtime/Temporal/ISORecords.h new file mode 100644 index 00000000000..f7c9b017eff --- /dev/null +++ b/Libraries/LibJS/Runtime/Temporal/ISORecords.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +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 }; +}; + +// 4.5.1 Time Records, https://tc39.es/proposal-temporal/#sec-temporal-time-records +struct Time { + double days { 0 }; + u8 hour { 0 }; + u8 minute { 0 }; + u8 second { 0 }; + u16 millisecond { 0 }; + u16 microsecond { 0 }; + u16 nanosecond { 0 }; +}; + +// 5.5.1 ISO Date-Time Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-records +struct ISODateTime { + ISODate iso_date; + Time time; +}; + +// 7.5.3 Internal Duration Records, https://tc39.es/proposal-temporal/#sec-temporal-internal-duration-records +// A time duration is an integer in the inclusive interval from -maxTimeDuration to maxTimeDuration, where +// maxTimeDuration = 2**53 × 10**9 - 1 = 9,007,199,254,740,991,999,999,999. It represents the portion of a +// Temporal.Duration object that deals with time units, but as a combined value of total nanoseconds. +using TimeDuration = Crypto::SignedBigInteger; + +// 9.5.1 ISO Year-Month Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-year-month-records +struct ISOYearMonth { + i32 year { 0 }; + u8 month { 0 }; +}; + +// 13.31 ISO String Time Zone Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-string-time-zone-parse-records +struct ParsedISOTimeZone { + bool z_designator { false }; + Optional offset_string; + Optional time_zone_annotation; +}; + +// 13.32 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records +struct ParsedISODateTime { + struct StartOfDay { }; + + Optional year { 0 }; + u8 month { 0 }; + u8 day { 0 }; + Variant time; + ParsedISOTimeZone time_zone; + Optional calendar; +}; + +} diff --git a/Libraries/LibJS/Runtime/Temporal/PlainDate.h b/Libraries/LibJS/Runtime/Temporal/PlainDate.h index 2aa248ac5b8..694a3ed7590 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainDate.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainDate.h @@ -13,16 +13,10 @@ #include #include #include +#include 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 }; -}; - class PlainDate final : public Object { JS_OBJECT(PlainDate, Object); GC_DECLARE_ALLOCATOR(PlainDate); diff --git a/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h b/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h index cea62f83237..134f7fe6c61 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainDateTime.h @@ -8,17 +8,10 @@ #pragma once -#include -#include +#include namespace JS::Temporal { -// 5.5.1 ISO Date-Time Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-records -struct ISODateTime { - ISODate iso_date; - Time time; -}; - ISODateTime combine_iso_date_and_time_record(ISODate, Time); bool iso_date_time_within_limits(ISODateTime); ISODateTime balance_iso_date_time(double year, double month, double day, double hour, double minute, double second, double millisecond, double microsecond, double nanosecond); diff --git a/Libraries/LibJS/Runtime/Temporal/PlainTime.h b/Libraries/LibJS/Runtime/Temporal/PlainTime.h index eec0c0cb2a6..3b1a22f0ea3 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainTime.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainTime.h @@ -8,21 +8,10 @@ #pragma once -#include +#include namespace JS::Temporal { -// 4.5.1 Time Records, https://tc39.es/proposal-temporal/#sec-temporal-time-records -struct Time { - double days { 0 }; - u8 hour { 0 }; - u8 minute { 0 }; - u8 second { 0 }; - u16 millisecond { 0 }; - u16 microsecond { 0 }; - u16 nanosecond { 0 }; -}; - Time create_time_record(double hour, double minute, double second, double millisecond, double microsecond, double nanosecond, double delta_days = 0); Time midnight_time_record(); Time noon_time_record(); diff --git a/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h b/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h index a505a33868d..fe54d60b667 100644 --- a/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h +++ b/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace JS::Temporal { @@ -32,12 +33,6 @@ private: String m_calendar; // [[Calendar]] }; -// 9.5.1 ISO Year-Month Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-year-month-records -struct ISOYearMonth { - i32 year { 0 }; - u8 month { 0 }; -}; - ThrowCompletionOr> to_temporal_year_month(VM&, Value item, Value options = js_undefined()); bool iso_year_month_within_limits(ISODate); ISOYearMonth balance_iso_year_month(double year, double month);