1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

LibJS: Add a bunch of Temporal Abstract Operations

These will allow us to (partially) implement
Temporal.Instant.prototype.{until, since}
This commit is contained in:
Idan Horowitz 2021-09-06 21:21:57 +03:00 committed by Linus Groh
parent bcdad57670
commit 24b78fff7d
8 changed files with 373 additions and 1 deletions

View file

@ -191,6 +191,18 @@ BigInt* add_instant(GlobalObject& global_object, BigInt const& epoch_nanoseconds
return result;
}
// 8.5.7 DifferenceInstant ( ns1, ns2, roundingIncrement, smallestUnit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-differenceinstant
BigInt* difference_instant(GlobalObject& global_object, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode)
{
auto& vm = global_object.vm();
// 1. Assert: Type(ns1) is BigInt.
// 2. Assert: Type(ns2) is BigInt.
// 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);
}
// 8.5.8 RoundTemporalInstant ( ns, increment, unit, roundingMode ), https://tc39.es/proposal-temporal/#sec-temporal-roundtemporalinstant
BigInt* round_temporal_instant(GlobalObject& global_object, BigInt const& nanoseconds, u64 increment, String const& unit, String const& rounding_mode)
{