|
@@ -409,7 +409,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
|
|
|
auto fractional_days = total_time_duration(internal_duration.time, Unit::Day);
|
|
|
|
|
|
// b. Let days be RoundNumberToIncrement(fractionalDays, roundingIncrement, roundingMode).
|
|
|
- auto days = round_number_to_increment(fractional_days, rounding_increment, rounding_mode);
|
|
|
+ auto days = round_number_to_increment(fractional_days.to_double(), rounding_increment, rounding_mode);
|
|
|
|
|
|
// c. Let dateDuration be ? CreateDateDurationRecord(0, 0, 0, days).
|
|
|
auto date_duration = TRY(create_date_duration_record(vm, 0, 0, 0, days));
|
|
@@ -470,12 +470,12 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
|
|
|
// 7. Let relativeToRecord be ? GetTemporalRelativeToOption(totalOf).
|
|
|
// 8. Let zonedRelativeTo be relativeToRecord.[[ZonedRelativeTo]].
|
|
|
// 9. Let plainRelativeTo be relativeToRecord.[[PlainRelativeTo]].
|
|
|
- auto [zoned_relative_to, plain_relative_to] = TRY(get_temporal_relative_to_option(vm, *total_of));
|
|
|
+ auto [plain_relative_to, zoned_relative_to] = TRY(get_temporal_relative_to_option(vm, *total_of));
|
|
|
|
|
|
// 10. Let unit be ? GetTemporalUnitValuedOption(totalOf, "unit", DATETIME, REQUIRED).
|
|
|
auto unit = TRY(get_temporal_unit_valued_option(vm, *total_of, vm.names.unit, UnitGroup::DateTime, Required {})).get<Unit>();
|
|
|
|
|
|
- double total = 0;
|
|
|
+ Crypto::BigFraction total;
|
|
|
|
|
|
// 11. If zonedRelativeTo is not undefined, then
|
|
|
if (zoned_relative_to) {
|
|
@@ -488,14 +488,29 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
|
|
|
}
|
|
|
// 12. Else if plainRelativeTo is not undefined, then
|
|
|
else if (plain_relative_to) {
|
|
|
- // FIXME: a. Let internalDuration be ToInternalDurationRecordWith24HourDays(duration).
|
|
|
- // FIXME: b. Let targetTime be AddTime(MidnightTimeRecord(), internalDuration.[[Time]]).
|
|
|
- // FIXME: c. Let calendar be plainRelativeTo.[[Calendar]].
|
|
|
- // FIXME: d. Let dateDuration be ! AdjustDateDurationRecord(internalDuration.[[Date]], targetTime.[[Days]]).
|
|
|
- // FIXME: e. Let targetDate be ? CalendarDateAdd(calendar, plainRelativeTo.[[ISODate]], dateDuration, constrain).
|
|
|
- // FIXME: f. Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).
|
|
|
- // FIXME: g. Let targetDateTime be CombineISODateAndTimeRecord(targetDate, targetTime).
|
|
|
- // FIXME: h. Let total be ? DifferencePlainDateTimeWithTotal(isoDateTime, targetDateTime, calendar, unit).
|
|
|
+ // a. Let internalDuration be ToInternalDurationRecordWith24HourDays(duration).
|
|
|
+ auto internal_duration = to_internal_duration_record_with_24_hour_days(vm, duration);
|
|
|
+
|
|
|
+ // b. Let targetTime be AddTime(MidnightTimeRecord(), internalDuration.[[Time]]).
|
|
|
+ auto target_time = add_time(midnight_time_record(), internal_duration.time);
|
|
|
+
|
|
|
+ // c. Let calendar be plainRelativeTo.[[Calendar]].
|
|
|
+ auto const& calendar = plain_relative_to->calendar();
|
|
|
+
|
|
|
+ // d. Let dateDuration be ! AdjustDateDurationRecord(internalDuration.[[Date]], targetTime.[[Days]]).
|
|
|
+ auto date_duration = MUST(adjust_date_duration_record(vm, internal_duration.date, target_time.days));
|
|
|
+
|
|
|
+ // e. Let targetDate be ? CalendarDateAdd(calendar, plainRelativeTo.[[ISODate]], dateDuration, CONSTRAIN).
|
|
|
+ auto target_date = TRY(calendar_date_add(vm, calendar, plain_relative_to->iso_date(), date_duration, Overflow::Constrain));
|
|
|
+
|
|
|
+ // f. Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).
|
|
|
+ auto iso_date_time = combine_iso_date_and_time_record(plain_relative_to->iso_date(), midnight_time_record());
|
|
|
+
|
|
|
+ // g. Let targetDateTime be CombineISODateAndTimeRecord(targetDate, targetTime).
|
|
|
+ auto target_date_time = combine_iso_date_and_time_record(target_date, target_time);
|
|
|
+
|
|
|
+ // h. Let total be ? DifferencePlainDateTimeWithTotal(isoDateTime, targetDateTime, calendar, unit).
|
|
|
+ total = TRY(difference_plain_date_time_with_total(vm, iso_date_time, target_date_time, calendar, unit));
|
|
|
}
|
|
|
// 13. Else,
|
|
|
else {
|
|
@@ -516,7 +531,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total)
|
|
|
}
|
|
|
|
|
|
// 14. Return 𝔽(total).
|
|
|
- return total;
|
|
|
+ return total.to_double();
|
|
|
}
|
|
|
|
|
|
// 7.3.22 Temporal.Duration.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.tostring
|