@@ -47,6 +47,7 @@ void DurationPrototype::initialize(GlobalObject& global_object)
47
47
define_native_function (vm.names .negated , negated, 0 , attr);
48
48
define_native_function (vm.names .abs , abs, 0 , attr);
49
49
define_native_function (vm.names .add , add, 1 , attr);
50
+ define_native_function (vm.names .subtract , subtract, 1 , attr);
50
51
define_native_function (vm.names .round , round, 1 , attr);
51
52
define_native_function (vm.names .total , total, 1 , attr);
52
53
define_native_function (vm.names .toString , to_string, 0 , attr);
@@ -313,6 +314,29 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::add)
313
314
return TRY (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 ));
314
315
}
315
316
317
+ // 7.3.19 Temporal.Duration.prototype.subtract ( other [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.subtract
318
+ JS_DEFINE_NATIVE_FUNCTION (DurationPrototype::subtract)
319
+ {
320
+ // 1. Let duration be the this value.
321
+ // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
322
+ auto * duration = TRY (typed_this_object (global_object));
323
+
324
+ // 3. Set other to ? ToLimitedTemporalDuration(other, « »).
325
+ auto other = TRY (to_limited_temporal_duration (global_object, vm.argument (0 ), {}));
326
+
327
+ // 4. Set options to ? GetOptionsObject(options).
328
+ auto * options = TRY (get_options_object (global_object, vm.argument (1 )));
329
+
330
+ // 5. Let relativeTo be ? ToRelativeTemporalObject(options).
331
+ auto relative_to = TRY (to_relative_temporal_object (global_object, *options));
332
+
333
+ // 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).
334
+ 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));
335
+
336
+ // 7. Return ? CreateTemporalDuration(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]]).
337
+ return TRY (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 ));
338
+ }
339
+
316
340
// 7.3.20 Temporal.Duration.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.round
317
341
JS_DEFINE_NATIVE_FUNCTION (DurationPrototype::round)
318
342
{
0 commit comments