LibJS: Replace U+2212 MINUS SIGN with U+002D HYPHEN-MINUS

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/bbcd37b
This commit is contained in:
Linus Groh 2022-04-29 21:09:10 +02:00
parent df1f81ba90
commit 27793bf76c
20 changed files with 102 additions and 102 deletions

View file

@ -320,7 +320,7 @@ ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject& global_objec
}
// 3. Else if dividend is more than 1, then
else if (*dividend > 1) {
// a. Let maximum be 𝔽(dividend 1).
// a. Let maximum be 𝔽(dividend - 1).
maximum = *dividend - 1;
}
// 4. Else,
@ -444,20 +444,20 @@ ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(GlobalObje
// 11. If digits is 1, 2, or 3, then
if (digits == 1 || digits == 2 || digits == 3) {
// a. Return the Record { [[Precision]]: digits, [[Unit]]: "millisecond", [[Increment]]: 10^(3 digits) }.
// a. Return the Record { [[Precision]]: digits, [[Unit]]: "millisecond", [[Increment]]: 10^(3 - digits) }.
return SecondsStringPrecision { .precision = digits, .unit = "millisecond"sv, .increment = (u32)pow(10, 3 - digits) };
}
// 12. If digits is 4, 5, or 6, then
if (digits == 4 || digits == 5 || digits == 6) {
// a. Return the Record { [[Precision]]: digits, [[Unit]]: "microsecond", [[Increment]]: 10^(6 digits) }.
// a. Return the Record { [[Precision]]: digits, [[Unit]]: "microsecond", [[Increment]]: 10^(6 - digits) }.
return SecondsStringPrecision { .precision = digits, .unit = "microsecond"sv, .increment = (u32)pow(10, 6 - digits) };
}
// 13. Assert: digits is 7, 8, or 9.
VERIFY(digits == 7 || digits == 8 || digits == 9);
// 14. Return the Record { [[Precision]]: digits, [[Unit]]: "nanosecond", [[Increment]]: 10^(9 digits) }.
// 14. Return the Record { [[Precision]]: digits, [[Unit]]: "nanosecond", [[Increment]]: 10^(9 - digits) }.
return SecondsStringPrecision { .precision = digits, .unit = "nanosecond"sv, .increment = (u32)pow(10, 9 - digits) };
}
@ -997,7 +997,7 @@ i64 round_number_to_increment(double x, u64 increment, StringView rounding_mode)
// 4. If roundingMode is "ceil", then
if (rounding_mode == "ceil"sv) {
// a. Let rounded be floor(quotient).
// a. Let rounded be -floor(-quotient).
rounded = -floor(-quotient);
}
// 5. Else if roundingMode is "floor", then
@ -1044,7 +1044,7 @@ BigInt* round_number_to_increment(GlobalObject& global_object, BigInt const& x,
Crypto::SignedBigInteger rounded = move(division_result.quotient);
// 4. If roundingMode is "ceil", then
if (rounding_mode == "ceil"sv) {
// a. Let rounded be floor(quotient).
// a. Let rounded be -floor(-quotient).
if (!division_result.remainder.is_negative())
rounded = rounded.plus(Crypto::UnsignedBigInteger { 1 });
}
@ -1466,7 +1466,7 @@ ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(GlobalObject& g
// 18. If sign contains the code point 0x002D (HYPHEN-MINUS) or 0x2212 (MINUS SIGN), then
if (sign_part.has_value() && sign_part->is_one_of("-", "\u2212")) {
// a. Let factor be 1.
// a. Let factor be -1.
factor = -1;
}
// 19. Else,

View file

@ -152,7 +152,7 @@ ThrowCompletionOr<double> to_integer_throw_on_infinity(GlobalObject& global_obje
// 1. Let integer be ? ToIntegerOrInfinity(argument).
auto integer = TRY(argument.to_integer_or_infinity(global_object));
// 2. If integer is ∞ or +∞ , then
// 2. If integer is -∞ or +∞ , then
if (Value(integer).is_infinity()) {
// a. Throw a RangeError exception.
return vm.template throw_completion<RangeError>(global_object, error_type, args...);
@ -171,7 +171,7 @@ ThrowCompletionOr<double> to_integer_without_rounding(GlobalObject& global_objec
// 1. Let number be ? ToNumber(argument).
auto number = TRY(argument.to_number(global_object));
// 2. If number is NaN, +0𝔽, or 0𝔽 return 0.
// 2. If number is NaN, +0𝔽, or -0𝔽 return 0.
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
return 0;

View file

@ -200,7 +200,7 @@ i8 duration_sign(double years, double months, double weeks, double days, double
{
// 1. For each value v of « years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds », do
for (auto& v : { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds }) {
// a. If v < 0, return 1.
// a. If v < 0, return -1.
if (v < 0)
return -1;
@ -361,7 +361,7 @@ ThrowCompletionOr<Duration*> create_temporal_duration(GlobalObject& global_objec
// 7.5.15 CreateNegatedTemporalDuration ( duration ), https://tc39.es/proposal-temporal/#sec-temporal-createnegatedtemporalduration
Duration* create_negated_temporal_duration(GlobalObject& global_object, Duration const& duration)
{
// 1. Return ! CreateTemporalDuration(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
// 1. Return ! CreateTemporalDuration(-duration.[[Years]], -duration.[[Months]], -duration.[[Weeks]], -duration.[[Days]], -duration.[[Hours]], -duration.[[Minutes]], -duration.[[Seconds]], -duration.[[Milliseconds]], -duration.[[Microseconds]], -duration.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, -duration.years(), -duration.months(), -duration.weeks(), -duration.days(), -duration.hours(), -duration.minutes(), -duration.seconds(), -duration.milliseconds(), -duration.microseconds(), -duration.nanoseconds()));
}
@ -389,7 +389,7 @@ ThrowCompletionOr<double> calculate_offset_shift(GlobalObject& global_object, Va
// 6. Let offsetAfter be ? GetOffsetNanosecondsFor(relativeTo.[[TimeZone]], instantAfter).
auto offset_after = TRY(get_offset_nanoseconds_for(global_object, &relative_to.time_zone(), *instant_after));
// 7. Return offsetAfter offsetBefore.
// 7. Return offsetAfter - offsetBefore.
return offset_after - offset_before;
}
@ -406,7 +406,7 @@ Crypto::SignedBigInteger total_duration_nanoseconds(double days, double hours, d
// 2. If days ≠ 0, then
if (days != 0) {
// a. Set nanoseconds to nanoseconds offsetShift.
// a. Set nanoseconds to nanoseconds - offsetShift.
result_nanoseconds = result_nanoseconds.minus(Crypto::SignedBigInteger::create_from(offset_shift));
}
// 3. Set hours to (hours) + (days) × 24.
@ -436,7 +436,7 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_obje
// a. Let endNs be ? AddZonedDateTime(relativeTo.[[Nanoseconds]], relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
auto* end_ns = TRY(add_zoned_date_time(global_object, relative_to_zoned_date_time.nanoseconds(), &relative_to_zoned_date_time.time_zone(), relative_to_zoned_date_time.calendar(), 0, 0, 0, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds.to_double()));
// b. Set nanoseconds to (endNs relativeTo.[[Nanoseconds]]).
// b. Set nanoseconds to (endNs - relativeTo.[[Nanoseconds]]).
total_nanoseconds = end_ns->big_integer().minus(relative_to_zoned_date_time.nanoseconds().big_integer());
}
// 3. Else,
@ -468,7 +468,7 @@ ThrowCompletionOr<TimeDurationRecord> balance_duration(GlobalObject& global_obje
milliseconds = 0;
microseconds = 0;
// 7. If nanoseconds < 0, let sign be 1; else, let sign be 1.
// 7. If nanoseconds < 0, let sign be -1; else, let sign be 1.
i8 sign = total_nanoseconds.is_negative() ? -1 : 1;
// 8. Set nanoseconds to abs(nanoseconds).
@ -641,7 +641,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// vi. Set relativeTo to newRelativeTo.
relative_to = new_relative_to;
// vii. Set years to years sign.
// vii. Set years to years - sign.
years -= sign;
// viii. Set months to months + oneYearMonths.
@ -667,7 +667,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// iii. Set days to days + moveResult.[[Days]].
days += move_result.days;
// iv. Set years to years sign.
// iv. Set years to years - sign.
years -= sign;
}
@ -682,7 +682,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// iii. Set days to days + moveResult.[[Days]].
days += move_result.days;
// iv. Set months to months sign.
// iv. Set months to months - sign.
months -= sign;
}
}
@ -707,7 +707,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// 3. Set days to days + moveResult.[[Days]].
days += move_result.days;
// 4. Set years to years sign.
// 4. Set years to years - sign.
years -= sign;
}
@ -722,7 +722,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// 3. Set days to days +moveResult.[[Days]].
days += move_result.days;
// 4. Set months to months sign.
// 4. Set months to months - sign.
months -= sign;
}
@ -737,7 +737,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(GlobalObject&
// 3. Set days to days + moveResult.[[Days]].
days += move_result.days;
// 4. Set weeks to weeks sign.
// 4. Set weeks to weeks - sign.
weeks -= sign;
}
}
@ -795,7 +795,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// d. Repeat, while abs(days) ≥ abs(oneYearDays),
while (fabs(days) >= fabs(one_year_days)) {
// i. Set days to days oneYearDays.
// i. Set days to days - oneYearDays.
days -= one_year_days;
// ii. Set years to years + sign.
@ -822,7 +822,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// h. Repeat, while abs(days) ≥ abs(oneMonthDays),
while (fabs(days) >= fabs(one_month_days)) {
// i. Set days to days oneMonthDays.
// i. Set days to days - oneMonthDays.
days -= one_month_days;
// ii. Set months to months + sign.
@ -861,7 +861,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// p. Repeat, while abs(months) ≥ abs(oneYearMonths),
while (fabs(months) >= fabs(one_year_months)) {
// i. Set months to months oneYearMonths.
// i. Set months to months - oneYearMonths.
months -= one_year_months;
// ii. Set years to years + sign.
@ -899,7 +899,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// d. Repeat, while abs(days) ≥ abs(oneMonthDays),
while (fabs(days) >= fabs(one_month_days)) {
// i. Set days to days oneMonthDays.
// i. Set days to days - oneMonthDays.
days -= one_month_days;
// ii. Set months to months + sign.
@ -931,7 +931,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(GlobalObject& gl
// e. Repeat, while abs(days) ≥ abs(oneWeekDays),
while (fabs(days) >= fabs(one_week_days)) {
// i. Set days to days oneWeekDays.
// i. Set days to days - oneWeekDays.
days -= one_week_days;
// ii. Set weeks to weeks + sign.
@ -1164,7 +1164,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
}
// 8. Else,
else {
// a. Let fractionalSeconds be nanoseconds × 10^9 + microseconds × 10^6 + milliseconds × 10^3 + seconds.
// a. Let fractionalSeconds be nanoseconds × 10^-9 + microseconds × 10^-6 + milliseconds × 10^-3 + seconds.
fractional_seconds = nanoseconds * 0.000000001 + microseconds * 0.000001 + milliseconds * 0.001 + seconds;
}
@ -1235,7 +1235,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
// t. Set days to days - daysPassed.
days -= days_passed;
// u. If days < 0, let sign be 1; else, let sign be 1.
// u. If days < 0, let sign be -1; else, let sign be 1.
auto sign = days < 0 ? -1 : 1;
// v. Let oneYear be ! CreateTemporalDuration(sign, 0, 0, 0, 0, 0, 0, 0, 0, 0).
@ -1289,7 +1289,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
// h. Let days be days + weeksInDays.
days += weeks_in_days;
// i. If days < 0, let sign be 1; else, let sign be 1.
// i. If days < 0, let sign be -1; else, let sign be 1.
auto sign = days < 0 ? -1 : 1;
// j. Let oneMonth be ! CreateTemporalDuration(0, sign, 0, 0, 0, 0, 0, 0, 0, 0).
@ -1309,7 +1309,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
// i. Set months to months + sign.
months += sign;
// ii. Set days to days oneMonthDays.
// ii. Set days to days - oneMonthDays.
days -= one_month_days;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneMonth).
@ -1339,7 +1339,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
else if (unit == "week"sv) {
VERIFY(relative_to);
// a. If days < 0, let sign be 1; else, let sign be 1.
// a. If days < 0, let sign be -1; else, let sign be 1.
auto sign = days < 0 ? -1 : 1;
// b. Let oneWeek be ! CreateTemporalDuration(0, 0, sign, 0, 0, 0, 0, 0, 0, 0).
@ -1359,7 +1359,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
// i. Set weeks to weeks + sign.
weeks += sign;
// ii. Set days to days oneWeekDays.
// ii. Set days to days - oneWeekDays.
days -= one_week_days;
// iii. Set moveResult to ? MoveRelativeDate(calendar, relativeTo, oneWeek).
@ -1445,7 +1445,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
}
// 17. Else if unit is "millisecond", then
else if (unit == "millisecond"sv) {
// a. Let fractionalMilliseconds be nanoseconds × 10^6 + microseconds × 10^3 + milliseconds.
// a. Let fractionalMilliseconds be nanoseconds × 10^-6 + microseconds × 10^-3 + milliseconds.
auto fractional_milliseconds = nanoseconds * 0.000001 + microseconds * 0.001 + milliseconds;
// b. Set milliseconds to ! RoundNumberToIncrement(fractionalMilliseconds, increment, roundingMode).
@ -1460,7 +1460,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
}
// 18. Else if unit is "microsecond", then
else if (unit == "microsecond"sv) {
// a. Let fractionalMicroseconds be nanoseconds × 10^3 + microseconds.
// a. Let fractionalMicroseconds be nanoseconds × 10^-3 + microseconds.
auto fractional_microseconds = nanoseconds * 0.001 + microseconds;
// b. Set microseconds to ! RoundNumberToIncrement(fractionalMicroseconds, increment, roundingMode).
@ -1483,7 +1483,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(GlobalObject& global_object, d
// c. Set nanoseconds to ! RoundNumberToIncrement(nanoseconds, increment, roundingMode).
nanoseconds = (double)round_number_to_increment(nanoseconds, increment, rounding_mode);
// d. Set remainder to remainder nanoseconds.
// d. Set remainder to remainder - nanoseconds.
remainder -= nanoseconds;
}
@ -1515,7 +1515,7 @@ ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& glo
// 3. If timeRemainderNs = 0, let direction be 0.
if (time_remainder_ns == "0"_bigint)
direction = 0;
// 4. Else if timeRemainderNs < 0, let direction be 1.
// 4. Else if timeRemainderNs < 0, let direction be -1.
else if (time_remainder_ns.is_negative())
direction = -1;
// 5. Else, let direction be 1.
@ -1528,16 +1528,16 @@ ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(GlobalObject& glo
// 7. Let dayEnd be ? AddZonedDateTime(dayStart, relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, direction, 0, 0, 0, 0, 0, 0).
auto* day_end = TRY(add_zoned_date_time(global_object, *day_start, &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, direction, 0, 0, 0, 0, 0, 0));
// 8. Let dayLengthNs be (dayEnd dayStart).
// 8. Let dayLengthNs be (dayEnd - dayStart).
auto day_length_ns = day_end->big_integer().minus(day_start->big_integer());
// 9. If (timeRemainderNs dayLengthNs) × direction < 0, then
// 9. If (timeRemainderNs - dayLengthNs) × direction < 0, then
if (time_remainder_ns.minus(day_length_ns).multiplied_by(Crypto::SignedBigInteger { direction }).is_negative()) {
// a. Return ! CreateDurationRecord(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
return create_duration_record(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
// 10. Set timeRemainderNs to ! RoundTemporalInstant((timeRemainderNs dayLengthNs), increment, unit, roundingMode).
// 10. Set timeRemainderNs to ! RoundTemporalInstant((timeRemainderNs - dayLengthNs), increment, unit, roundingMode).
time_remainder_ns = round_temporal_instant(global_object, *js_bigint(vm, time_remainder_ns.minus(day_length_ns)), increment, unit, rounding_mode)->big_integer();
// 11. Let adjustedDateDuration be ? AddDuration(years, months, weeks, days, 0, 0, 0, 0, 0, 0, 0, 0, 0, direction, 0, 0, 0, 0, 0, 0, relativeTo).

View file

@ -159,7 +159,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationConstructor::compare)
if (ns1 > ns2)
return Value(1);
// 12. If ns1 < ns2, return 1𝔽.
// 12. If ns1 < ns2, return -1𝔽.
if (ns1 < ns2)
return Value(-1);

View file

@ -330,7 +330,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::subtract)
// 5. Let relativeTo be ? ToRelativeTemporalObject(options).
auto relative_to = TRY(to_relative_temporal_object(global_object, *options));
// 6. Let result be ? AddDuration(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], other.[[Years]], other.[[Months]], other.[[Weeks]], other.[[Days]], other.[[Hours]], other.[[Minutes]], other.[[Seconds]], other.[[Milliseconds]], other.[[Microseconds]], other.[[Nanoseconds]], relativeTo).
// 6. Let result be ? AddDuration(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], -other.[[Years]], -other.[[Months]], -other.[[Weeks]], -other.[[Days]], -other.[[Hours]], -other.[[Minutes]], -other.[[Seconds]], -other.[[Milliseconds]], -other.[[Microseconds]], -other.[[Nanoseconds]], relativeTo).
auto result = TRY(add_duration(global_object, duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), -other.years, -other.months, -other.weeks, -other.days, -other.hours, -other.minutes, -other.seconds, -other.milliseconds, -other.microseconds, -other.nanoseconds, relative_to));
// 7. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).

View file

@ -39,7 +39,7 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds)
{
// 1. Assert: Type(epochNanoseconds) is BigInt.
// 2. If epochNanoseconds < 86400 × 10^17 or epochNanoseconds > 86400 × 10^17, then
// 2. If epochNanoseconds < -86400 × 10^17 or epochNanoseconds > 86400 × 10^17, then
if (epoch_nanoseconds.big_integer() < INSTANT_NANOSECONDS_MIN || epoch_nanoseconds.big_integer() > INSTANT_NANOSECONDS_MAX) {
// a. Return false.
return false;
@ -118,7 +118,7 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
// 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
// 6. If (utc) < -8.64 × 10^21 or (utc) > 8.64 × 10^21, then
if (utc->big_integer() < INSTANT_NANOSECONDS_MIN || utc->big_integer() > INSTANT_NANOSECONDS_MAX) {
// a. Throw a RangeError exception.
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidEpochNanoseconds);
@ -127,7 +127,7 @@ ThrowCompletionOr<BigInt*> parse_temporal_instant(GlobalObject& global_object, S
// 7. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
auto offset_nanoseconds = TRY(parse_time_zone_offset_string(global_object, *offset_string));
// 8. Let result be utc (offsetNanoseconds).
// 8. Let result be utc - (offsetNanoseconds).
auto* result_ns = js_bigint(vm, utc->big_integer().minus(Crypto::SignedBigInteger::create_from(offset_nanoseconds)));
// 9. If ! IsValidEpochNanoseconds(result) is false, then
@ -189,7 +189,7 @@ BigInt* difference_instant(GlobalObject& global_object, BigInt const& nanosecond
// 1. Assert: Type(ns1) is BigInt.
// 2. Assert: Type(ns2) is BigInt.
// 3. Return ! RoundTemporalInstant(ns2 ns1, roundingIncrement, smallestUnit, roundingMode).
// 3. Return ! RoundTemporalInstant(ns2 - ns1, roundingIncrement, smallestUnit, roundingMode).
return round_temporal_instant(global_object, *js_bigint(vm, nanoseconds2.big_integer().minus(nanoseconds1.big_integer())), rounding_increment, smallest_unit, rounding_mode);
}

View file

@ -148,7 +148,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::subtract)
// 3. Let duration be ? ToLimitedTemporalDuration(temporalDurationLike, « "years", "months", "weeks", "days" »).
auto duration = TRY(to_limited_temporal_duration(global_object, temporal_duration_like, { "years"sv, "months"sv, "weeks"sv, "days"sv }));
// 4. Let ns be ? AddInstant(instant.[[Nanoseconds]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
// 4. Let ns be ? AddInstant(instant.[[Nanoseconds]], -duration.[[Hours]], -duration.[[Minutes]], -duration.[[Seconds]], -duration.[[Milliseconds]], -duration.[[Microseconds]], -duration.[[Nanoseconds]]).
auto* ns = TRY(add_instant(global_object, instant->nanoseconds(), -duration.hours, -duration.minutes, -duration.seconds, -duration.milliseconds, -duration.microseconds, -duration.nanoseconds));
// 5. Return ! CreateTemporalInstant(ns).

View file

@ -164,8 +164,8 @@ BigInt* system_utc_epoch_nanoseconds(GlobalObject& global_object)
auto now = Time::now_realtime().to_nanoseconds();
auto ns = Crypto::SignedBigInteger::create_from(now);
// 2. Set ns to the result of clamping ns between 8.64 × 10^21 and 8.64 × 10^21.
// NOTE: Time::to_nanoseconds() already clamps between (2^63) and 2^63 1, the range of an i64,
// 2. Set ns to the result of clamping ns between -8.64 × 10^21 and 8.64 × 10^21.
// NOTE: Time::to_nanoseconds() already clamps between -(2^63) and 2^63 - 1, the range of an i64,
// if an overflow occurs during seconds -> nanoseconds conversion.
// 3. Return (ns).

View file

@ -159,7 +159,7 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
// d. Let end be the Record { [[Year]]: y2, [[Month]]: m2, [[Day]]: d2 }.
auto end = ISODate { .year = year2, .month = month2, .day = day2 };
// e. Let years be end.[[Year]] start.[[Year]].
// e. Let years be end.[[Year]] - start.[[Year]].
double years = end.year - start.year;
// f. Let mid be ! AddISODate(y1, m1, d1, years, 0, 0, 0, "constrain").
@ -178,7 +178,7 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
return create_date_duration_record(0, years * 12, 0, 0);
}
// i. Let months be end.[[Month]] start.[[Month]].
// i. Let months be end.[[Month]] - start.[[Month]].
double months = end.month - start.month;
// j. If midSign is not equal to sign, then
@ -281,11 +281,11 @@ DateDurationRecord difference_iso_date(GlobalObject& global_object, i32 year1, u
// ii. Let greater be the Record { [[Year]]: y1, [[Month]]: m1, [[Day]]: d1 }.
greater = { .year = year1, .month = month1, .day = day1 };
// iii. Let sign be 1.
// iii. Let sign be -1.
sign = -1;
}
// c. Let days be ! ToISODayOfYear(greater.[[Year]], greater.[[Month]], greater.[[Day]]) ! ToISODayOfYear(smaller.[[Year]], smaller.[[Month]], smaller.[[Day]]).
// c. Let days be ! ToISODayOfYear(greater.[[Year]], greater.[[Month]], greater.[[Day]]) - ! ToISODayOfYear(smaller.[[Year]], smaller.[[Month]], smaller.[[Day]]).
double days = to_iso_day_of_year(greater.year, greater.month, greater.day) - to_iso_day_of_year(smaller.year, smaller.month, smaller.day);
// d. Let year be smaller.[[Year]].
@ -409,7 +409,7 @@ ISODate balance_iso_date(double year_, double month_, double day)
// 4. Set year to balancedYearMonth.[[Year]].
auto year = balanced_year_month.year;
// 5. NOTE: To deal with negative numbers of days whose absolute value is greater than the number of days in a year, the following section subtracts years and adds days until the number of days is greater than 366 or 365.
// 5. NOTE: To deal with negative numbers of days whose absolute value is greater than the number of days in a year, the following section subtracts years and adds days until the number of days is greater than -366 or -365.
i32 test_year;
@ -420,19 +420,19 @@ ISODate balance_iso_date(double year_, double month_, double day)
}
// 7. Else,
else {
// a. Let testYear be year 1.
// a. Let testYear be year - 1.
test_year = year - 1;
}
// 8. Repeat, while day < 1 × ! ISODaysInYear(testYear),
// 8. Repeat, while day < -1 × ! ISODaysInYear(testYear),
while (day < -1 * iso_days_in_year(test_year)) {
// a. Set day to day + !ISODaysInYear(testYear).
day += iso_days_in_year(test_year);
// b. Set year to year 1.
// b. Set year to year - 1.
year--;
// c. Set testYear to testYear 1.
// c. Set testYear to testYear - 1.
test_year--;
}
@ -443,7 +443,7 @@ ISODate balance_iso_date(double year_, double month_, double day)
// 11. Repeat, while day > ! ISODaysInYear(testYear),
while (day > iso_days_in_year(test_year)) {
// a. Set day to day ! ISODaysInYear(testYear).
// a. Set day to day - ! ISODaysInYear(testYear).
day -= iso_days_in_year(test_year);
// b. Set year to year + 1.
@ -457,7 +457,7 @@ ISODate balance_iso_date(double year_, double month_, double day)
// 13. Repeat, while day < 1,
while (day < 1) {
// a. Set balancedYearMonth to ! BalanceISOYearMonth(year, month 1).
// a. Set balancedYearMonth to ! BalanceISOYearMonth(year, month - 1).
balanced_year_month = balance_iso_year_month(year, month - 1);
// b. Set year to balancedYearMonth.[[Year]].
@ -474,7 +474,7 @@ ISODate balance_iso_date(double year_, double month_, double day)
// 15. Repeat, while day > ! ISODaysInMonth(year, month),
while (day > iso_days_in_month(year, month)) {
// a. Set day to day ! ISODaysInMonth(year, month).
// a. Set day to day - ! ISODaysInMonth(year, month).
day -= iso_days_in_month(year, month);
// b. Set balancedYearMonth to ! BalanceISOYearMonth(year, month + 1).

View file

@ -549,7 +549,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::since)
result = TRY(round_duration(global_object, result.years, result.months, result.weeks, result.days, 0, 0, 0, 0, 0, 0, rounding_increment, *smallest_unit, rounding_mode, temporal_date)).duration_record;
}
// 17. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], 0, 0, 0, 0, 0, 0).
// 17. Return ! CreateTemporalDuration(-result.[[Years]], -result.[[Months]], -result.[[Weeks]], -result.[[Days]], 0, 0, 0, 0, 0, 0).
return TRY(create_temporal_duration(global_object, -result.years, -result.months, -result.weeks, -result.days, 0, 0, 0, 0, 0, 0));
}

View file

@ -52,7 +52,7 @@ BigInt* get_epoch_from_iso_parts(GlobalObject& global_object, i32 year, u8 month
// 1. Assert: IsValidISODate(year, month, day) is true.
VERIFY(is_valid_iso_date(year, month, day));
// 2. 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));
// 3. Let time be MakeTime(𝔽(hour), 𝔽(minute), 𝔽(second), 𝔽(millisecond)).

View file

@ -497,7 +497,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::subtract)
// 4. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
// 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).
// 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.
@ -617,7 +617,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::since)
// 17. Let result be ! BalanceDuration(roundResult.[[Days]], roundResult.[[Hours]], roundResult.[[Minutes]], roundResult.[[Seconds]], roundResult.[[Milliseconds]], roundResult.[[Microseconds]], roundResult.[[Nanoseconds]], largestUnit).
auto result = MUST(balance_duration(global_object, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, Crypto::SignedBigInteger::create_from((i64)round_result.nanoseconds), *largest_unit));
// 18. Return ? CreateTemporalDuration(roundResult.[[Years]], roundResult.[[Months]], roundResult.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
// 18. Return ? CreateTemporalDuration(-roundResult.[[Years]], -roundResult.[[Months]], -roundResult.[[Weeks]], -result.[[Days]], -result.[[Hours]], -result.[[Minutes]], -result.[[Seconds]], -result.[[Milliseconds]], -result.[[Microseconds]], -result.[[Nanoseconds]]).
return TRY(create_temporal_duration(global_object, -round_result.years, -round_result.months, -round_result.weeks, -result.days, -result.hours, -result.minutes, -result.seconds, -result.milliseconds, -result.microseconds, -result.nanoseconds));
}

View file

@ -42,22 +42,22 @@ void PlainTime::visit_edges(Visitor& visitor)
// 4.5.1 DifferenceTime ( h1, min1, s1, ms1, mus1, ns1, h2, min2, s2, ms2, mus2, ns2 ), https://tc39.es/proposal-temporal/#sec-temporal-differencetime
TimeDurationRecord difference_time(u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2)
{
// 1. Let hours be h2 h1.
// 1. Let hours be h2 - h1.
auto hours = hour2 - hour1;
// 2. Let minutes be min2 min1.
// 2. Let minutes be min2 - min1.
auto minutes = minute2 - minute1;
// 3. Let seconds be s2 s1.
// 3. Let seconds be s2 - s1.
auto seconds = second2 - second1;
// 4. Let milliseconds be ms2 ms1.
// 4. Let milliseconds be ms2 - ms1.
auto milliseconds = millisecond2 - millisecond1;
// 5. Let microseconds be mus2 mus1.
// 5. Let microseconds be mus2 - mus1.
auto microseconds = microsecond2 - microsecond1;
// 6. Let nanoseconds be ns2 ns1.
// 6. Let nanoseconds be ns2 - ns1.
auto nanoseconds = nanosecond2 - nanosecond1;
// 7. Let sign be ! DurationSign(0, 0, 0, 0, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
@ -525,7 +525,7 @@ DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 micro
{
// 1. Assert: hour, minute, second, millisecond, microsecond, nanosecond, and increment are integers.
// 2. Let fractionalSecond be nanosecond × 109 + microsecond × 106 + millisecond × 103 + second.
// 2. Let fractionalSecond be nanosecond × 10-9 + microsecond × 10-6 + millisecond × 10-3 + second.
double fractional_second = nanosecond * 0.000000001 + microsecond * 0.000001 + millisecond * 0.001 + second;
double quantity;
@ -555,12 +555,12 @@ DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 micro
}
// 7. Else if unit is "millisecond", then
else if (unit == "millisecond"sv) {
// a. Let quantity be nanosecond × 106 + microsecond × 103 + millisecond.
// a. Let quantity be nanosecond × 10-6 + microsecond × 10-3 + millisecond.
quantity = nanosecond * 0.000001 + 0.001 * microsecond + millisecond;
}
// 8. Else if unit is "microsecond", then
else if (unit == "microsecond"sv) {
// a. Let quantity be nanosecond × 103 + microsecond.
// a. Let quantity be nanosecond × 10-3 + microsecond.
quantity = nanosecond * 0.001 + microsecond;
}
// 9. Else,

View file

@ -170,7 +170,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::subtract)
// 3. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
auto duration = TRY(to_temporal_duration_record(global_object, temporal_duration_like));
// 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]]).
// 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.
@ -333,10 +333,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::since)
// 12. Let result be ! DifferenceTime(other.[[ISOHour]], other.[[ISOMinute]], other.[[ISOSecond]], other.[[ISOMillisecond]], other.[[ISOMicrosecond]], other.[[ISONanosecond]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]]).
auto result = difference_time(other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond());
// 13. Set result to (? RoundDuration(0, 0, 0, 0, result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]], roundingIncrement, smallestUnit, roundingMode)).[[DurationRecord]].
// 13. Set result to (? RoundDuration(0, 0, 0, 0, -result.[[Hours]], -result.[[Minutes]], -result.[[Seconds]], -result.[[Milliseconds]], -result.[[Microseconds]], -result.[[Nanoseconds]], roundingIncrement, smallestUnit, roundingMode)).[[DurationRecord]].
auto rounded_result = TRY(round_duration(global_object, 0, 0, 0, 0, -result.hours, -result.minutes, -result.seconds, -result.milliseconds, -result.microseconds, -result.nanoseconds, rounding_increment, *smallest_unit, rounding_mode)).duration_record;
// 14. Set result to ! BalanceDuration(0, result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]], largestUnit).
// 14. Set result to ! BalanceDuration(0, -result.[[Hours]], -result.[[Minutes]], -result.[[Seconds]], -result.[[Milliseconds]], -result.[[Microseconds]], -result.[[Nanoseconds]], largestUnit).
result = MUST(balance_duration(global_object, 0, -rounded_result.hours, -rounded_result.minutes, -rounded_result.seconds, -rounded_result.milliseconds, -rounded_result.microseconds, Crypto::SignedBigInteger { (i32)-rounded_result.nanoseconds }, *largest_unit));
// 15. Return ? CreateTemporalDuration(0, 0, 0, 0, result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).

View file

@ -143,13 +143,13 @@ bool iso_year_month_within_limits(i32 year, u8 month)
{
// 1. Assert: year and month are integers.
// 2. If year < 271821 or year > 275760, then
// 2. If year < -271821 or year > 275760, then
if (year < -271821 || year > 275760) {
// a. Return false.
return false;
}
// 3. If year is 271821 and month < 4, then
// 3. If year is -271821 and month < 4, then
if (year == -271821 && month < 4) {
// a. Return false.
return false;
@ -174,7 +174,7 @@ ISOYearMonth balance_iso_year_month(double year, double month)
// 2. Set year to year + floor((month - 1) / 12).
year += floor((month - 1) / 12);
// 3. Set month to (month 1) modulo 12 + 1.
// 3. Set month to (month - 1) modulo 12 + 1.
month = modulo(month - 1, 12) + 1;
// 4. Return the Record { [[Year]]: year, [[Month]]: month }.

View file

@ -547,14 +547,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::since)
// 23. If smallestUnit is "month" and roundingIncrement = 1, then
if (smallest_unit == "month"sv && rounding_increment == 1) {
// a. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0).
// a. Return ! CreateTemporalDuration(-result.[[Years]], -result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0).
return MUST(create_temporal_duration(global_object, -result->years(), -result->months(), 0, 0, 0, 0, 0, 0, 0, 0));
}
// 24. Let result be (? RoundDuration(result.[[Years]], result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0, roundingIncrement, smallestUnit, roundingMode, thisDate)).[[DurationRecord]].
auto round_result = TRY(round_duration(global_object, result->years(), result->months(), 0, 0, 0, 0, 0, 0, 0, 0, rounding_increment, *smallest_unit, rounding_mode, this_date)).duration_record;
// 25. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0).
// 25. Return ! CreateTemporalDuration(-result.[[Years]], -result.[[Months]], 0, 0, 0, 0, 0, 0, 0, 0).
return MUST(create_temporal_duration(global_object, -round_result.years, -round_result.months, 0, 0, 0, 0, 0, 0, 0, 0));
}

View file

@ -111,7 +111,7 @@ ISODateTime get_iso_parts_from_epoch(GlobalObject& global_object, Crypto::Signed
auto remainder_ns_bigint = modulo(epoch_nanoseconds, Crypto::UnsignedBigInteger { 1'000'000 });
auto remainder_ns = remainder_ns_bigint.to_double();
// 3. Let epochMilliseconds be 𝔽((epochNanoseconds remainderNs) / 10^6).
// 3. Let epochMilliseconds be 𝔽((epochNanoseconds - remainderNs) / 10^6).
auto epoch_milliseconds_bigint = epoch_nanoseconds.minus(remainder_ns_bigint).divided_by(Crypto::UnsignedBigInteger { 1'000'000 }).quotient;
auto epoch_milliseconds = epoch_milliseconds_bigint.to_double();
@ -282,7 +282,7 @@ ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject& global_obj
double sign;
// 6. If sign is the code unit 0x002D (HYPHEN-MINUS) or 0x2212 (MINUS SIGN), then
if (sign_part.is_one_of("-", "\xE2\x88\x92")) {
// a. Set sign to 1.
// a. Set sign to -1.
sign = -1;
}
// 7. Else,
@ -565,7 +565,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
// b. If disambiguation is "later", then
if (disambiguation == "later"sv) {
// i. Return possibleInstants[n 1].
// i. Return possibleInstants[n - 1].
return possible_instants[n - 1];
}
@ -588,7 +588,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
// 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).
// 8. Let dayBefore be ! CreateTemporalInstant(epochNanoseconds - 8.64 × 10^13).
auto* day_before = MUST(create_temporal_instant(global_object, *js_bigint(vm, epoch_nanoseconds->big_integer().minus("86400000000000"_sbigint))));
// 9. Let dayAfter be ! CreateTemporalInstant(epochNanoseconds + 8.64 × 10^13).
@ -600,12 +600,12 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
// 11. Let offsetAfter be ? GetOffsetNanosecondsFor(timeZone, dayAfter).
auto offset_after = TRY(get_offset_nanoseconds_for(global_object, time_zone, *day_after));
// 12. Let nanoseconds be offsetAfter offsetBefore.
// 12. Let nanoseconds be offsetAfter - offsetBefore.
auto nanoseconds = offset_after - offset_before;
// 13. If disambiguation is "earlier", then
if (disambiguation == "earlier"sv) {
// a. Let earlier be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, undefined).
// a. Let earlier be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, undefined).
auto earlier = 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(), 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, nullptr));
// b. Let earlierDateTime be ! CreateTemporalDateTime(earlier.[[Year]], earlier.[[Month]], earlier.[[Day]], earlier.[[Hour]], earlier.[[Minute]], earlier.[[Second]], earlier.[[Millisecond]], earlier.[[Microsecond]], earlier.[[Nanosecond]], dateTime.[[Calendar]]).
@ -641,7 +641,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
if (n == 0)
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalDisambiguatePossibleInstantsZero);
// 20. Return possibleInstants[n 1].
// 20. Return possibleInstants[n - 1].
return possible_instants_[n - 1];
}

View file

@ -140,7 +140,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
// 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]])).
// b. Let instant be ! CreateTemporalInstant(epochNanoseconds - (timeZone.[[OffsetNanoseconds]])).
auto* instant = MUST(create_temporal_instant(global_object, *js_bigint(vm, epoch_nanoseconds->big_integer().minus(Crypto::SignedBigInteger::create_from(*time_zone->offset_nanoseconds())))));
// c. Return CreateArrayFromList(« instant »).

View file

@ -61,7 +61,7 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(GlobalObject& gl
// 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).
// b. Return epochNanoseconds - (offsetNanoseconds).
auto offset_nanoseconds_bigint = Crypto::SignedBigInteger::create_from((i64)offset_nanoseconds);
return js_bigint(vm, epoch_nanoseconds->big_integer().minus(offset_nanoseconds_bigint));
}
@ -418,7 +418,7 @@ ThrowCompletionOr<DurationRecord> difference_zoned_date_time(GlobalObject& globa
// 7. Let intermediateNs be ? AddZonedDateTime(ns1, timeZone, calendar, dateDifference.[[Years]], dateDifference.[[Months]], dateDifference.[[Weeks]], 0, 0, 0, 0, 0, 0, 0).
auto* intermediate_ns = TRY(add_zoned_date_time(global_object, nanoseconds1, &time_zone, calendar, date_difference.years, date_difference.months, date_difference.weeks, 0, 0, 0, 0, 0, 0, 0));
// 8. Let timeRemainderNs be ns2 intermediateNs.
// 8. Let timeRemainderNs be ns2 - intermediateNs.
auto time_remainder_ns = nanoseconds2.big_integer().minus(intermediate_ns->big_integer());
// 9. Let intermediate be ! CreateTemporalZonedDateTime(intermediateNs, timeZone, calendar).
@ -448,7 +448,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
return NanosecondsToDaysResult { .days = 0, .nanoseconds = "0"_sbigint, .day_length = day_length_ns.to_double() };
}
// 3. If nanoseconds < 0, let sign be 1; else, let sign be 1.
// 3. If nanoseconds < 0, let sign be -1; else, let sign be 1.
auto sign = nanoseconds.is_negative() ? -1 : 1;
// 4. If Type(relativeTo) is not Object or relativeTo does not have an [[InitializedTemporalZonedDateTime]] internal slot, then
@ -494,7 +494,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
if (sign == 1) {
// a. Repeat, while days > 0 and intermediateNs > endNs,
while (days > 0 && intermediate_ns > end_ns) {
// i. Set days to days 1.
// i. Set days to days - 1.
days--;
// ii. Set intermediateNs to (? AddZonedDateTime((startNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, days, 0, 0, 0, 0, 0, 0)).
@ -502,7 +502,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
}
}
// 15. Set nanoseconds to endNs intermediateNs.
// 15. Set nanoseconds to endNs - intermediateNs.
nanoseconds = end_ns.minus(intermediate_ns);
// 16. Let done be false.
@ -511,12 +511,12 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(GlobalObject& glo
// a. Let oneDayFartherNs be (? AddZonedDateTime((intermediateNs), relativeTo.[[TimeZone]], relativeTo.[[Calendar]], 0, 0, 0, sign, 0, 0, 0, 0, 0, 0)).
auto one_day_farther_ns = TRY(add_zoned_date_time(global_object, *js_bigint(vm, intermediate_ns), &relative_to.time_zone(), relative_to.calendar(), 0, 0, 0, sign, 0, 0, 0, 0, 0, 0))->big_integer();
// b. Set dayLengthNs to oneDayFartherNs intermediateNs.
// b. Set dayLengthNs to oneDayFartherNs - intermediateNs.
day_length_ns = one_day_farther_ns.minus(intermediate_ns);
// c. If (nanoseconds dayLengthNs) × sign ≥ 0, then
// c. If (nanoseconds - dayLengthNs) × sign ≥ 0, then
if (nanoseconds.minus(day_length_ns).multiplied_by(Crypto::SignedBigInteger { (i32)sign }) >= "0"_sbigint) {
// i. Set nanoseconds to nanoseconds dayLengthNs.
// i. Set nanoseconds to nanoseconds - dayLengthNs.
nanoseconds = nanoseconds.minus(day_length_ns);
// ii. Set intermediateNs to oneDayFartherNs.

View file

@ -516,7 +516,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::hours_in_day_getter)
// 14. Let tomorrowInstant be ? BuiltinTimeZoneGetInstantFor(timeZone, tomorrow, "compatible").
auto* tomorrow_instant = TRY(builtin_time_zone_get_instant_for(global_object, &time_zone, *tomorrow, "compatible"sv));
// 15. Let diffNs be tomorrowInstant.[[Nanoseconds]] todayInstant.[[Nanoseconds]].
// 15. Let diffNs be tomorrowInstant.[[Nanoseconds]] - todayInstant.[[Nanoseconds]].
auto diff_ns = tomorrow_instant->nanoseconds().big_integer().minus(today_instant->nanoseconds().big_integer());
// 16. Return 𝔽(diffNs / (3.6 × 10^12)).
@ -937,7 +937,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::subtract)
// 6. Let calendar be zonedDateTime.[[Calendar]].
auto& calendar = zoned_date_time->calendar();
// 7. Let epochNanoseconds be ? AddZonedDateTime(zonedDateTime.[[Nanoseconds]], timeZone, calendar, duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], options).
// 7. Let epochNanoseconds be ? AddZonedDateTime(zonedDateTime.[[Nanoseconds]], timeZone, calendar, -duration.[[Years]], -duration.[[Months]], -duration.[[Weeks]], -duration.[[Days]], -duration.[[Hours]], -duration.[[Minutes]], -duration.[[Seconds]], -duration.[[Milliseconds]], -duration.[[Microseconds]], -duration.[[Nanoseconds]], options).
auto* epoch_nanoseconds = TRY(add_zoned_date_time(global_object, zoned_date_time->nanoseconds(), &time_zone, calendar, -duration.years, -duration.months, -duration.weeks, -duration.days, -duration.hours, -duration.minutes, -duration.seconds, -duration.milliseconds, -duration.microseconds, -duration.nanoseconds, options));
// 8. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
@ -1069,7 +1069,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since)
// b. Let balanceResult be ! BalanceDuration(0, 0, 0, 0, 0, 0, differenceNs, largestUnit).
auto balance_result = MUST(balance_duration(global_object, 0, 0, 0, 0, 0, 0, difference_ns->big_integer(), *largest_unit));
// c. Return ? CreateTemporalDuration(0, 0, 0, 0, balanceResult.[[Hours]], balanceResult.[[Minutes]], balanceResult.[[Seconds]], balanceResult.[[Milliseconds]], balanceResult.[[Microseconds]], balanceResult.[[Nanoseconds]]).
// c. Return ? CreateTemporalDuration(0, 0, 0, 0, -balanceResult.[[Hours]], -balanceResult.[[Minutes]], -balanceResult.[[Seconds]], -balanceResult.[[Milliseconds]], -balanceResult.[[Microseconds]], -balanceResult.[[Nanoseconds]]).
return TRY(create_temporal_duration(global_object, 0, 0, 0, 0, -balance_result.hours, -balance_result.minutes, -balance_result.seconds, -balance_result.milliseconds, -balance_result.microseconds, -balance_result.nanoseconds));
}
@ -1091,7 +1091,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since)
// 19. Let result be ? AdjustRoundedDurationDays(roundResult.[[Years]], roundResult.[[Months]], roundResult.[[Weeks]], roundResult.[[Days]], roundResult.[[Hours]], roundResult.[[Minutes]], roundResult.[[Seconds]], roundResult.[[Milliseconds]], roundResult.[[Microseconds]], roundResult.[[Nanoseconds]], roundingIncrement, smallestUnit, roundingMode, zonedDateTime).
auto result = TRY(adjust_rounded_duration_days(global_object, round_result.years, round_result.months, round_result.weeks, round_result.days, round_result.hours, round_result.minutes, round_result.seconds, round_result.milliseconds, round_result.microseconds, round_result.nanoseconds, rounding_increment, *smallest_unit, rounding_mode, zoned_date_time));
// 20. Return ! CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
// 20. Return ! CreateTemporalDuration(-result.[[Years]], -result.[[Months]], -result.[[Weeks]], -result.[[Days]], -result.[[Hours]], -result.[[Minutes]], -result.[[Seconds]], -result.[[Milliseconds]], -result.[[Microseconds]], -result.[[Nanoseconds]]).
return MUST(create_temporal_duration(global_object, -result.years, -result.months, -result.weeks, -result.days, -result.hours, -result.minutes, -result.seconds, -result.milliseconds, -result.microseconds, -result.nanoseconds));
}
@ -1170,7 +1170,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
// TODO: Shouldn't `zonedDateTime.[[Calendar]]` be `calendar` for consistency?
auto* end_ns = TRY(add_zoned_date_time(global_object, start_ns, &time_zone, zoned_date_time->calendar(), 0, 0, 0, 1, 0, 0, 0, 0, 0, 0));
// 19. Let dayLengthNs be (endNs startNs).
// 19. Let dayLengthNs be (endNs - startNs).
auto day_length_ns = end_ns->big_integer().minus(start_ns.big_integer()).to_double();
// 20. If dayLengthNs is 0, then