Files
ladybird/Libraries/LibJS/Runtime/Temporal/ISORecords.h
Timothy Flynn a41f2f56a8 LibJS+LibUnicode: Migrate some Temporal calendar types to LibUnicode
These will be needed for calendar operations involving ICU.
2026-03-09 11:40:59 +01:00

76 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright (c) 2024-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>
#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
using ISODate = Unicode::ISODate;
// 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.32 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<String> offset_string;
Optional<String> time_zone_annotation;
};
// 13.33 Time Zone Identifier Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-time-zone-identifier-parse-records
struct ParsedTimeZoneIdentifier {
Optional<String> name;
Optional<i64> offset_minutes;
};
// 13.34 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records
struct ParsedISODateTime {
struct StartOfDay { };
Optional<i32> year { 0 };
u8 month { 0 };
u8 day { 0 };
Variant<StartOfDay, Time> time;
ParsedISOTimeZone time_zone;
Optional<String> calendar;
};
}