mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 11:27:35 +00:00
LibJS: Update for structured headers added to various Temporal AOs
This is an editorial change in the Temporal spec.
See: e6a15a5
This commit is contained in:
parent
9a3014c91a
commit
70593b7448
15 changed files with 64 additions and 69 deletions
|
@ -226,7 +226,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(GlobalObject& glo
|
|||
// a. Set timeZone to ? ToString(timeZone).
|
||||
time_zone = TRY(time_zone_value.to_string(global_object));
|
||||
|
||||
// b. If the result of ! IsValidTimeZoneName(timeZone) is false, then
|
||||
// b. If the result of IsValidTimeZoneName(timeZone) is false, then
|
||||
if (!Temporal::is_valid_time_zone_name(time_zone)) {
|
||||
// i. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, time_zone, vm.names.timeZone);
|
||||
|
|
|
@ -84,7 +84,7 @@ static Vector<StringView> available_time_zones()
|
|||
|
||||
// 3. For each element name of names, do
|
||||
for (auto name : names) {
|
||||
// a. Assert: ! IsValidTimeZoneName( name ) is true.
|
||||
// a. Assert: IsValidTimeZoneName( name ) is true.
|
||||
// b. Let canonical be ! CanonicalizeTimeZoneName( name ).
|
||||
auto canonical = TimeZone::canonicalize_time_zone(name).value();
|
||||
|
||||
|
|
|
@ -680,7 +680,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
|
|||
if (time_zone_name.has_value()) {
|
||||
// i. If ParseText(StringToCodePoints(timeZoneName), TimeZoneNumericUTCOffset) is a List of errors, then
|
||||
if (!is_valid_time_zone_numeric_utc_offset_syntax(*time_zone_name)) {
|
||||
// 1. If ! IsValidTimeZoneName(timeZoneName) is false, throw a RangeError exception.
|
||||
// 1. If IsValidTimeZoneName(timeZoneName) is false, throw a RangeError exception.
|
||||
if (!is_valid_time_zone_name(*time_zone_name))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidTimeZoneName, *time_zone_name);
|
||||
|
||||
|
@ -1187,11 +1187,11 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
|
|||
nanosecond = 0;
|
||||
}
|
||||
|
||||
// 18. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception.
|
||||
// 18. If IsValidISODate(year, month, day) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(year, month, day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidISODate);
|
||||
|
||||
// 19. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
// 19. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidTime);
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
|
|||
// 4. Assert: offsetString is not undefined.
|
||||
VERIFY(offset_string.has_value());
|
||||
|
||||
// 5. Let utc be ! GetEpochFromISOParts(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
|
||||
// 5. Let utc be GetEpochFromISOParts(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
|
||||
auto* utc = get_epoch_from_iso_parts(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond);
|
||||
|
||||
// 6. If utc < −8.64 × 10^21 or utc > 8.64 × 10^21, then
|
||||
|
|
|
@ -46,11 +46,11 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(GlobalObject& global_object,
|
|||
// 3. Assert: isoDay is an integer.
|
||||
// 4. Assert: Type(calendar) is Object.
|
||||
|
||||
// 5. If ! IsValidISODate(isoYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
// 5. If IsValidISODate(isoYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(iso_year, iso_month, iso_day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
|
||||
|
||||
// 6. If ! ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, 12, 0, 0, 0, 0, 0) is false, throw a RangeError exception.
|
||||
// 6. If ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, 12, 0, 0, 0, 0, 0) is false, throw a RangeError exception.
|
||||
if (!iso_date_time_within_limits(global_object, iso_year, iso_month, iso_day, 12, 0, 0, 0, 0, 0))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
|
||||
|
||||
|
@ -128,7 +128,7 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject& global_object, Valu
|
|||
// 6. Let result be ? ParseTemporalDateString(string).
|
||||
auto result = TRY(parse_temporal_date_string(global_object, string));
|
||||
|
||||
// 7. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
// 7. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
|
||||
|
||||
// 8. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
|
||||
|
@ -339,7 +339,7 @@ ThrowCompletionOr<ISODate> regulate_iso_date(GlobalObject& global_object, double
|
|||
auto y = static_cast<i32>(year);
|
||||
auto m = static_cast<u8>(month);
|
||||
auto d = static_cast<u8>(day);
|
||||
// a. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception.
|
||||
// a. If IsValidISODate(year, month, day) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(y, m, d))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
|
||||
|
||||
|
|
|
@ -49,27 +49,22 @@ BigInt* get_epoch_from_iso_parts(GlobalObject& global_object, i32 year, u8 month
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: year, month, day, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
|
||||
|
||||
// 2. Assert: ! IsValidISODate(year, month, day) is true.
|
||||
// 1. Assert: IsValidISODate(year, month, day) is true.
|
||||
VERIFY(is_valid_iso_date(year, month, day));
|
||||
|
||||
// 3. Assert: ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is true.
|
||||
VERIFY(is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond));
|
||||
|
||||
// 4. Let date be MakeDay(𝔽(year), 𝔽(month − 1), 𝔽(day)).
|
||||
// 2. Let date be MakeDay(𝔽(year), 𝔽(month − 1), 𝔽(day)).
|
||||
auto date = make_day(global_object, Value(year), Value(month - 1), Value(day));
|
||||
|
||||
// 5. Let time be MakeTime(𝔽(hour), 𝔽(minute), 𝔽(second), 𝔽(millisecond)).
|
||||
// 3. Let time be MakeTime(𝔽(hour), 𝔽(minute), 𝔽(second), 𝔽(millisecond)).
|
||||
auto time = make_time(global_object, Value(hour), Value(minute), Value(second), Value(millisecond));
|
||||
|
||||
// 6. Let ms be MakeDate(date, time).
|
||||
// 4. Let ms be MakeDate(date, time).
|
||||
auto ms = make_date(date, time);
|
||||
|
||||
// 7. Assert: ms is finite.
|
||||
// 5. Assert: ms is finite.
|
||||
VERIFY(ms.is_finite_number());
|
||||
|
||||
// 8. Return ℝ(ms) × 10^6 + microsecond × 10^3 + nanosecond.
|
||||
// 6. Return ℝ(ms) × 10^6 + microsecond × 10^3 + nanosecond.
|
||||
return js_bigint(vm, Crypto::SignedBigInteger::create_from(static_cast<i64>(ms.as_double())).multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }).plus(Crypto::SignedBigInteger::create_from((i64)microsecond * 1000)).plus(Crypto::SignedBigInteger(nanosecond)));
|
||||
}
|
||||
|
||||
|
@ -81,23 +76,21 @@ auto const DATETIME_NANOSECONDS_MAX = "8640000086400000000000"_sbigint;
|
|||
// 5.5.2 ISODateTimeWithinLimits ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetimewithinlimits
|
||||
bool iso_date_time_within_limits(GlobalObject& global_object, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
|
||||
{
|
||||
// 1. Assert: year, month, day, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
|
||||
|
||||
// 2. Let ns be ! GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
|
||||
// 1. Let ns be GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
|
||||
auto ns = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
|
||||
|
||||
// 3. If ns ≤ -8.64 × 10^21 - 8.64 × 10^13, then
|
||||
// 2. If ns ≤ -8.64 × 10^21 - 8.64 × 10^13, then
|
||||
if (ns->big_integer() <= DATETIME_NANOSECONDS_MIN) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. If ns ≥ 8.64 × 10^21 + 8.64 × 10^13, then
|
||||
// 3. If ns ≥ 8.64 × 10^21 + 8.64 × 10^13, then
|
||||
if (ns->big_integer() >= DATETIME_NANOSECONDS_MAX) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
// 5. Return true.
|
||||
// 4. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -193,10 +186,10 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj
|
|||
// c. Let result be ? ParseTemporalDateTimeString(string).
|
||||
result = TRY(parse_temporal_date_time_string(global_object, string));
|
||||
|
||||
// d. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
// d. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
|
||||
|
||||
// e. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// e. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// f. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
|
||||
|
@ -234,15 +227,15 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject& global
|
|||
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
|
||||
// 2. Assert: Type(calendar) is Object.
|
||||
|
||||
// 3. If ! IsValidISODate(isoYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
// 3. If IsValidISODate(isoYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(iso_year, iso_month, iso_day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
|
||||
// 4. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
// 4. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
|
||||
// 5. If ! ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond) is false, then
|
||||
// 5. If ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond) is false, then
|
||||
if (!iso_date_time_within_limits(global_object, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond)) {
|
||||
// a. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
|
|
|
@ -395,10 +395,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with)
|
|||
// 12. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
|
||||
auto result = TRY(interpret_temporal_date_time_fields(global_object, calendar, *fields, *options));
|
||||
|
||||
// 13. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
// 13. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
|
||||
|
||||
// 14. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// 14. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// 15. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
|
||||
|
@ -474,10 +474,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::add)
|
|||
// 5. Let result be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], options).
|
||||
auto result = TRY(add_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), date_time->calendar(), duration.years, duration.months, duration.weeks, duration.days, duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, duration.nanoseconds, options));
|
||||
|
||||
// 6. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
// 6. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
|
||||
|
||||
// 7. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// 7. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// 8. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], dateTime.[[Calendar]]).
|
||||
|
@ -500,10 +500,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::subtract)
|
|||
// 5. Let result be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], −duration.[[Years]], −duration.[[Months]], −duration.[[Weeks]], −duration.[[Days]], −duration.[[Hours]], −duration.[[Minutes]], −duration.[[Seconds]], −duration.[[Milliseconds]], −duration.[[Microseconds]], −duration.[[Nanoseconds]], options).
|
||||
auto result = TRY(add_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), date_time->calendar(), -duration.years, -duration.months, -duration.weeks, -duration.days, -duration.hours, -duration.minutes, -duration.seconds, -duration.milliseconds, -duration.microseconds, -duration.nanoseconds, options));
|
||||
|
||||
// 6. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
// 6. Assert: IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
|
||||
|
||||
// 7. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// 7. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// 8. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], dateTime.[[Calendar]]).
|
||||
|
|
|
@ -151,7 +151,7 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject& global
|
|||
// 1. Assert: isoMonth, isoDay, and referenceISOYear are integers.
|
||||
// 2. Assert: Type(calendar) is Object.
|
||||
|
||||
// 3. If ! IsValidISODate(referenceISOYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
// 3. If IsValidISODate(referenceISOYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(reference_iso_year, iso_month, iso_day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainMonthDay);
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ ThrowCompletionOr<PlainTime*> to_temporal_time(GlobalObject& global_object, Valu
|
|||
// b. Let result be ? ParseTemporalTimeString(string).
|
||||
result = TRY(parse_temporal_time_string(global_object, string));
|
||||
|
||||
// c. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// c. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result->hour, result->minute, result->second, result->millisecond, result->microsecond, result->nanosecond));
|
||||
|
||||
// d. If result.[[Calendar]] is not one of undefined or "iso8601", then
|
||||
|
@ -213,7 +213,7 @@ ThrowCompletionOr<TemporalTime> regulate_time(GlobalObject& global_object, doubl
|
|||
|
||||
// 4. If overflow is "reject", then
|
||||
if (overflow == "reject"sv) {
|
||||
// a. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
// a. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainTime);
|
||||
|
||||
|
@ -227,45 +227,43 @@ ThrowCompletionOr<TemporalTime> regulate_time(GlobalObject& global_object, doubl
|
|||
// 4.5.5 IsValidTime ( hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-isvalidtime
|
||||
bool is_valid_time(double hour, double minute, double second, double millisecond, double microsecond, double nanosecond)
|
||||
{
|
||||
// 1. Assert: hour, minute, second, millisecond, microsecond, and nanosecond are integers.
|
||||
|
||||
// 2. If hour < 0 or hour > 23, then
|
||||
// 1. If hour < 0 or hour > 23, then
|
||||
if (hour > 23) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. If minute < 0 or minute > 59, then
|
||||
// 2. If minute < 0 or minute > 59, then
|
||||
if (minute > 59) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. If second < 0 or second > 59, then
|
||||
// 3. If second < 0 or second > 59, then
|
||||
if (second > 59) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. If millisecond < 0 or millisecond > 999, then
|
||||
// 4. If millisecond < 0 or millisecond > 999, then
|
||||
if (millisecond > 999) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 6. If microsecond < 0 or microsecond > 999, then
|
||||
// 5. If microsecond < 0 or microsecond > 999, then
|
||||
if (microsecond > 999) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 7. If nanosecond < 0 or nanosecond > 999, then
|
||||
// 6. If nanosecond < 0 or nanosecond > 999, then
|
||||
if (nanosecond > 999) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 8. Return true.
|
||||
// 7. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -357,7 +355,7 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(GlobalObject& global_object,
|
|||
|
||||
// 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers.
|
||||
|
||||
// 2. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
// 2. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainTime);
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::add)
|
|||
// 4. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
|
||||
auto result = add_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), duration.hours, duration.minutes, duration.seconds, duration.milliseconds, duration.microseconds, duration.nanoseconds);
|
||||
|
||||
// 5. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// 5. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// 6. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
|
||||
|
@ -173,7 +173,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::subtract)
|
|||
// 4. Let result be ! AddTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], −duration.[[Hours]], −duration.[[Minutes]], −duration.[[Seconds]], −duration.[[Milliseconds]], −duration.[[Microseconds]], −duration.[[Nanoseconds]]).
|
||||
auto result = add_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), -duration.hours, -duration.minutes, -duration.seconds, -duration.milliseconds, -duration.microseconds, -duration.nanoseconds);
|
||||
|
||||
// 5. Assert: ! IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
// 5. Assert: IsValidTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]) is true.
|
||||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// 6. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
|
||||
|
|
|
@ -203,7 +203,7 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject& glob
|
|||
// 1. Assert: isoYear, isoMonth, and referenceISODay are integers.
|
||||
// 2. Assert: Type(calendar) is Object.
|
||||
|
||||
// 3. If ! IsValidISODate(isoYear, isoMonth, referenceISODay) is false, throw a RangeError exception.
|
||||
// 3. If IsValidISODate(isoYear, isoMonth, referenceISODay) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(iso_year, iso_month, reference_iso_day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainYearMonth);
|
||||
|
||||
|
|
|
@ -149,8 +149,9 @@ ISODateTime get_iso_parts_from_epoch(GlobalObject& global_object, Crypto::Signed
|
|||
// 11.6.3 GetIANATimeZoneEpochValue ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneepochvalue
|
||||
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject& global_object, [[maybe_unused]] StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
|
||||
{
|
||||
// The abstract operation GetIANATimeZoneEpochValue is an implementation-defined algorithm that returns a List of integers. Each integer in the List represents a number of nanoseconds since the Unix epoch in UTC that may correspond to the given calendar date and wall-clock time in the IANA time zone identified by timeZoneIdentifier.
|
||||
// When the input represents a local time repeating multiple times at a negative time zone transition (e.g. when the daylight saving time ends or the time zone offset is decreased due to a time zone rule change), the returned List will have more than one element. When the input represents a skipped local time at a positive time zone transition (e.g. when the daylight saving time starts or the time zone offset is increased due to a time zone rule change), the returned List will be empty. Otherwise, the returned List will have one element.
|
||||
// The implementation-defined abstract operation GetIANATimeZoneEpochValue takes arguments timeZoneIdentifier (a String), year (an integer), month (an integer between 1 and 12 inclusive), day (an integer between 1 and 31 inclusive), hour (an integer between 0 and 23 inclusive), minute (an integer between 0 and 59 inclusive), second (an integer between 0 and 59 inclusive), millisecond (an integer between 0 and 999 inclusive), microsecond (an integer between 0 and 999 inclusive), and nanosecond (an integer between 0 and 999 inclusive) and returns a List of BigInts.
|
||||
// Each value in the returned List represents a number of nanoseconds since the Unix epoch in UTC that corresponds to the given ISO 8601 calendar date and wall-clock time in the IANA time zone identified by timeZoneIdentifier.
|
||||
// When the input represents a local time repeating multiple times at a negative time zone transition (e.g. when the daylight saving time ends or the time zone offset is decreased due to a time zone rule change), the returned List will have more than one element. The elements are sorted in numerical order. When the input represents a skipped local time at a positive time zone transition (e.g. when the daylight saving time starts or the time zone offset is increased due to a time zone rule change), the returned List will be empty. Otherwise, the returned List will have one element.
|
||||
|
||||
// FIXME: Implement this properly for non-UTC timezones.
|
||||
auto& vm = global_object.vm();
|
||||
|
@ -162,7 +163,8 @@ MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject& global_object
|
|||
// 11.6.4 GetIANATimeZoneOffsetNanoseconds ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneoffsetnanoseconds
|
||||
i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier)
|
||||
{
|
||||
// The abstract operation GetIANATimeZoneOffsetNanoseconds is an implementation-defined algorithm that returns an integer representing the offset of the IANA time zone identified by timeZoneIdentifier from UTC, at the instant corresponding to epochNanoseconds.
|
||||
// The implementation-defined abstract operation GetIANATimeZoneOffsetNanoseconds takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns an integer.
|
||||
// The returned integer represents the offset of the IANA time zone identified by timeZoneIdentifier from UTC, at the instant corresponding to epochNanoseconds.
|
||||
// Given the same values of epochNanoseconds and timeZoneIdentifier, the result must be the same for the lifetime of the surrounding agent.
|
||||
|
||||
// Only called with validated TimeZone [[Identifier]] as argument.
|
||||
|
@ -193,7 +195,8 @@ i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, Strin
|
|||
// 11.6.5 GetIANATimeZoneNextTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezonenexttransition
|
||||
BigInt* get_iana_time_zone_next_transition(GlobalObject&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
|
||||
{
|
||||
// The abstract operation GetIANATimeZoneNextTransition is an implementation-defined algorithm that returns an integer representing the number of nanoseconds since the Unix epoch in UTC that corresponds to the first time zone transition after epochNanoseconds in the IANA time zone identified by timeZoneIdentifier or null if no such transition exists.
|
||||
// The implementation-defined abstract operation GetIANATimeZoneNextTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null.
|
||||
// The returned value represents the number of nanoseconds since the Unix epoch in UTC that corresponds to the first time zone transition after epochNanoseconds in the IANA time zone identified by timeZoneIdentifier, or null if no such transition exists.
|
||||
|
||||
// TODO: Implement this
|
||||
return nullptr;
|
||||
|
@ -202,7 +205,8 @@ BigInt* get_iana_time_zone_next_transition(GlobalObject&, [[maybe_unused]] BigIn
|
|||
// 11.6.6 GetIANATimeZonePreviousTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneprevioustransition
|
||||
BigInt* get_iana_time_zone_previous_transition(GlobalObject&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
|
||||
{
|
||||
// The abstract operation GetIANATimeZonePreviousTransition is an implementation-defined algorithm that returns an integer representing the number of nanoseconds since the Unix epoch in UTC that corresponds to the last time zone transition before epochNanoseconds in the IANA time zone identified by timeZoneIdentifier or null if no such transition exists.
|
||||
// The implementation-defined abstract operation GetIANATimeZonePreviousTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null.
|
||||
// The returned value represents the number of nanoseconds since the Unix epoch in UTC that corresponds to the last time zone transition before epochNanoseconds in the IANA time zone identified by timeZoneIdentifier, or null if no such transition exists.
|
||||
|
||||
// TODO: Implement this
|
||||
return nullptr;
|
||||
|
@ -446,7 +450,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
|
|||
}
|
||||
// b. Else,
|
||||
else {
|
||||
// i. If ! IsValidTimeZoneName(parseResult.[[Name]]) is false, throw a RangeError exception.
|
||||
// i. If IsValidTimeZoneName(parseResult.[[Name]]) is false, throw a RangeError exception.
|
||||
if (!is_valid_time_zone_name(*parse_result.name))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidTimeZoneName, *parse_result.name);
|
||||
}
|
||||
|
@ -579,7 +583,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalDisambiguatePossibleInstantsRejectZero);
|
||||
}
|
||||
|
||||
// 7. Let epochNanoseconds be ! GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
// 7. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
|
||||
|
||||
// 8. Let dayBefore be ! CreateTemporalInstant(epochNanoseconds − 8.64 × 10^13).
|
||||
|
|
|
@ -53,7 +53,7 @@ ThrowCompletionOr<Object*> TimeZoneConstructor::construct(FunctionObject& new_ta
|
|||
// 3. Let parseResult be ParseText(StringToCodePoints(identifier), TimeZoneNumericUTCOffset).
|
||||
// 4. If parseResult is a List of errors, then
|
||||
if (!is_valid_time_zone_numeric_utc_offset_syntax(identifier)) {
|
||||
// a. If ! IsValidTimeZoneName(identifier) is false, then
|
||||
// a. If IsValidTimeZoneName(identifier) is false, then
|
||||
if (!is_valid_time_zone_name(identifier)) {
|
||||
// i. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidTimeZoneName, identifier);
|
||||
|
|
|
@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_nanoseconds_for)
|
|||
if (time_zone->offset_nanoseconds().has_value())
|
||||
return Value(*time_zone->offset_nanoseconds());
|
||||
|
||||
// 5. Return 𝔽(! GetIANATimeZoneOffsetNanoseconds(instant.[[Nanoseconds]], timeZone.[[Identifier]])).
|
||||
// 5. Return 𝔽(GetIANATimeZoneOffsetNanoseconds(instant.[[Nanoseconds]], timeZone.[[Identifier]])).
|
||||
return Value((double)get_iana_time_zone_offset_nanoseconds(instant->nanoseconds(), time_zone->identifier()));
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
|
|||
|
||||
// 4. If timeZone.[[OffsetNanoseconds]] is not undefined, then
|
||||
if (time_zone->offset_nanoseconds().has_value()) {
|
||||
// a. Let epochNanoseconds be ! GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
// a. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
|
||||
|
||||
// b. Let instant be ! CreateTemporalInstant(ℤ(epochNanoseconds − timeZone.[[OffsetNanoseconds]])).
|
||||
|
@ -147,7 +147,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
|
|||
return Array::create_from(global_object, { instant });
|
||||
}
|
||||
|
||||
// 5. Let possibleEpochNanoseconds be ? GetIANATimeZoneEpochValue(timeZone.[[Identifier]], dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
// 5. Let possibleEpochNanoseconds be GetIANATimeZoneEpochValue(timeZone.[[Identifier]], dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
auto possible_epoch_nanoseconds = get_iana_time_zone_epoch_value(global_object, time_zone->identifier(), date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond());
|
||||
|
||||
// 6. Let possibleInstants be a new empty List.
|
||||
|
@ -180,7 +180,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_next_transition)
|
|||
if (!time_zone->offset_nanoseconds().has_value())
|
||||
return js_null();
|
||||
|
||||
// 5. Let transition be ? GetIANATimeZoneNextTransition(startingPoint.[[Nanoseconds]], timeZone.[[Identifier]]).
|
||||
// 5. Let transition be GetIANATimeZoneNextTransition(startingPoint.[[Nanoseconds]], timeZone.[[Identifier]]).
|
||||
auto* transition = get_iana_time_zone_next_transition(global_object, starting_point->nanoseconds(), time_zone->identifier());
|
||||
|
||||
// 6. If transition is null, return null.
|
||||
|
@ -205,7 +205,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_previous_transition)
|
|||
if (!time_zone->offset_nanoseconds().has_value())
|
||||
return js_null();
|
||||
|
||||
// 5. Let transition be ? GetIANATimeZonePreviousTransition(startingPoint.[[Nanoseconds]], timeZone.[[Identifier]]).
|
||||
// 5. Let transition be GetIANATimeZonePreviousTransition(startingPoint.[[Nanoseconds]], timeZone.[[Identifier]]).
|
||||
auto* transition = get_iana_time_zone_previous_transition(global_object, starting_point->nanoseconds(), time_zone->identifier());
|
||||
|
||||
// 6. If transition is null, return null.
|
||||
|
|
|
@ -58,7 +58,7 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& gl
|
|||
|
||||
// 4. If offsetBehaviour is exact, or offsetOption is "use", then
|
||||
if (offset_behavior == OffsetBehavior::Exact || offset_option == "use"sv) {
|
||||
// a. Let epochNanoseconds be ! GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
|
||||
// a. Let epochNanoseconds be GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
|
||||
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
|
||||
|
||||
// b. Return epochNanoseconds − offsetNanoseconds.
|
||||
|
@ -199,7 +199,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
|
|||
|
||||
// f. If ParseText(StringToCodePoints(timeZoneName), TimeZoneNumericUTCOffset) is a List of errors, then
|
||||
if (!is_valid_time_zone_numeric_utc_offset_syntax(*time_zone_name)) {
|
||||
// i. If ! IsValidTimeZoneName(timeZoneName) is false, throw a RangeError exception.
|
||||
// i. If IsValidTimeZoneName(timeZoneName) is false, throw a RangeError exception.
|
||||
if (!is_valid_time_zone_name(*time_zone_name))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidTimeZoneName, *time_zone_name);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue