|
@@ -47,6 +47,7 @@ void PlainTimePrototype::initialize(GlobalObject& global_object)
|
|
|
define_native_function(vm.names.subtract, subtract, 1, attr);
|
|
|
define_native_function(vm.names.with, with, 1, attr);
|
|
|
define_native_function(vm.names.until, until, 1, attr);
|
|
|
+ define_native_function(vm.names.since, since, 1, attr);
|
|
|
define_native_function(vm.names.round, round, 1, attr);
|
|
|
define_native_function(vm.names.equals, equals, 1, attr);
|
|
|
define_native_function(vm.names.toPlainDateTime, to_plain_date_time, 1, attr);
|
|
@@ -295,6 +296,53 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::until)
|
|
|
return TRY(create_temporal_duration(global_object, 0, 0, 0, 0, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
|
|
|
}
|
|
|
|
|
|
+// 4.3.14 Temporal.PlainTime.prototype.since ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.since
|
|
|
+JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::since)
|
|
|
+{
|
|
|
+ // 1. Let temporalTime be the this value.
|
|
|
+ // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
|
|
+ auto* temporal_time = TRY(typed_this_object(global_object));
|
|
|
+
|
|
|
+ // 3. Set other to ? ToTemporalTime(other).
|
|
|
+ auto* other = TRY(to_temporal_time(global_object, vm.argument(0)));
|
|
|
+
|
|
|
+ // 4. Set options to ? GetOptionsObject(options).
|
|
|
+ auto* options = TRY(get_options_object(global_object, vm.argument(1)));
|
|
|
+
|
|
|
+ // 5. Let smallestUnit be ? ToSmallestTemporalUnit(options, « "year", "month", "week", "day" », "nanosecond").
|
|
|
+ auto smallest_unit = TRY(to_smallest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "nanosecond"sv));
|
|
|
+
|
|
|
+ // 6. Let largestUnit be ? ToLargestTemporalUnit(options, « "year", "month", "week", "day" », "auto", "hour").
|
|
|
+ auto largest_unit = TRY(to_largest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "auto"sv, "hour"sv));
|
|
|
+
|
|
|
+ // 7. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit).
|
|
|
+ TRY(validate_temporal_unit_range(global_object, largest_unit, *smallest_unit));
|
|
|
+
|
|
|
+ // 8. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
|
|
|
+ auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *options, "trunc"sv));
|
|
|
+
|
|
|
+ // 9. Set roundingMode to ! NegateTemporalRoundingMode(roundingMode).
|
|
|
+ rounding_mode = negate_temporal_rounding_mode(rounding_mode);
|
|
|
+
|
|
|
+ // 10. Let maximum be ! MaximumTemporalDurationRoundingIncrement(smallestUnit).
|
|
|
+ auto maximum = maximum_temporal_duration_rounding_increment(*smallest_unit);
|
|
|
+
|
|
|
+ // 11. Let roundingIncrement be ? ToTemporalRoundingIncrement(options, maximum, false).
|
|
|
+ auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *options, maximum.has_value() ? *maximum : Optional<double> {}, false));
|
|
|
+
|
|
|
+ // 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).
|
|
|
+ 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));
|
|
|
+
|
|
|
+ // 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, *js_bigint(vm, { (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]]).
|
|
|
+ return TRY(create_temporal_duration(global_object, 0, 0, 0, 0, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds));
|
|
|
+}
|
|
|
+
|
|
|
// 4.3.15 Temporal.PlainTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round
|
|
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
|
|
|
{
|