diff --git a/polyfill/lib/duration.mjs b/polyfill/lib/duration.mjs
index 33eeb7cfc4..01aa154648 100644
--- a/polyfill/lib/duration.mjs
+++ b/polyfill/lib/duration.mjs
@@ -365,7 +365,9 @@ export class Duration {
({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
ES.DifferencePlainDateTimeWithRounding(
- plainRelativeTo,
+ GetSlot(plainRelativeTo, ISO_YEAR),
+ GetSlot(plainRelativeTo, ISO_MONTH),
+ GetSlot(plainRelativeTo, ISO_DAY),
0,
0,
0,
@@ -489,7 +491,9 @@ export class Duration {
const targetDate = ES.AddDate(calendarRec, plainRelativeTo, dateDuration);
const { total } = ES.DifferencePlainDateTimeWithRounding(
- plainRelativeTo,
+ GetSlot(plainRelativeTo, ISO_YEAR),
+ GetSlot(plainRelativeTo, ISO_MONTH),
+ GetSlot(plainRelativeTo, ISO_DAY),
0,
0,
0,
diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs
index 2db449e2a4..cdace99f12 100644
--- a/polyfill/lib/ecmascript.mjs
+++ b/polyfill/lib/ecmascript.mjs
@@ -4269,7 +4269,9 @@ function RoundRelativeDuration(
}
export function DifferencePlainDateTimeWithRounding(
- plainDate1,
+ y1,
+ mon1,
+ d1,
h1,
min1,
s1,
@@ -4292,9 +4294,6 @@ export function DifferencePlainDateTimeWithRounding(
roundingMode,
resolvedOptions
) {
- const y1 = GetSlot(plainDate1, ISO_YEAR);
- const mon1 = GetSlot(plainDate1, ISO_MONTH);
- const d1 = GetSlot(plainDate1, ISO_DAY);
if (CompareISODateTime(y1, mon1, d1, h1, min1, s1, ms1, µs1, ns1, y2, mon2, d2, h2, min2, s2, ms2, µs2, ns2) == 0) {
return {
years: 0,
@@ -4619,11 +4618,12 @@ export function DifferenceTemporalPlainDateTime(operation, plainDateTime, other,
return new Duration();
}
- const plainDate1 = TemporalDateTimeToDate(plainDateTime);
const calendarRec = new CalendarMethodRecord(calendar, ['dateAdd', 'dateUntil']);
const { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
DifferencePlainDateTimeWithRounding(
- plainDate1,
+ GetSlot(plainDateTime, ISO_YEAR),
+ GetSlot(plainDateTime, ISO_MONTH),
+ GetSlot(plainDateTime, ISO_DAY),
GetSlot(plainDateTime, ISO_HOUR),
GetSlot(plainDateTime, ISO_MINUTE),
GetSlot(plainDateTime, ISO_SECOND),
diff --git a/spec/duration.html b/spec/duration.html
index e22b7f3099..8824d7dffe 100644
--- a/spec/duration.html
+++ b/spec/duration.html
@@ -479,7 +479,7 @@
Temporal.Duration.prototype.round ( _roundTo_ )
1. Let _targetTime_ be AddTime(0, 0, 0, 0, 0, 0, _norm_).
1. Let _dateDuration_ be ? CreateTemporalDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]] + _targetTime_.[[Days]], 0, 0, 0, 0, 0, 0).
1. Let _targetDate_ be ? AddDate(_calendarRec_, _plainRelativeTo_, _dateDuration_).
- 1. Let _roundRecord_ be ? DifferencePlainDateTimeWithRounding(_plainRelativeTo_, 0, 0, 0, 0, 0, 0, _targetDate_.[[ISOYear]], _targetDate_.[[ISOMonth]], _targetDate_.[[ISODay]], _targetTime_.[[Hours]], _targetTime_.[[Minutes]], _targetTime_.[[Seconds]], _targetTime_.[[Milliseconds]], _targetTime_.[[Microseconds]], _targetTime_.[[Nanoseconds]], _calendarRec_, _largestUnit_, _roundingIncrement_, _smallestUnit_, _roundingMode_, _emptyOptions_).
+ 1. Let _roundRecord_ be ? DifferencePlainDateTimeWithRounding(_plainRelativeTo_.[[ISOYear]], _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, 0, 0, 0, _targetDate_.[[ISOYear]], _targetDate_.[[ISOMonth]], _targetDate_.[[ISODay]], _targetTime_.[[Hours]], _targetTime_.[[Minutes]], _targetTime_.[[Seconds]], _targetTime_.[[Milliseconds]], _targetTime_.[[Microseconds]], _targetTime_.[[Nanoseconds]], _calendarRec_, _largestUnit_, _roundingIncrement_, _smallestUnit_, _roundingMode_, _emptyOptions_).
1. Let _roundResult_ be _roundRecord_.[[DurationRecord]].
1. Else,
1. If _calendarUnitsPresent_ is *true*, or IsCalendarUnit(_largestUnit_) is *true*, or IsCalendarUnit(_smallestUnit_) is *true*, throw a *RangeError* exception.
@@ -531,7 +531,7 @@ Temporal.Duration.prototype.total ( _totalOf_ )
1. Let _targetTime_ be AddTime(0, 0, 0, 0, 0, 0, _norm_).
1. Let _dateDuration_ be ? CreateTemporalDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]] + _targetTime_.[[Days]], 0, 0, 0, 0, 0, 0).
1. Let _targetDate_ be ? AddDate(_calendarRec_, _plainRelativeTo_, _dateDuration_).
- 1. Let _roundRecord_ be ? DifferencePlainDateTimeWithRounding(_plainRelativeTo_, 0, 0, 0, 0, 0, 0, _targetDate_.[[ISOYear]], _targetDate_.[[ISOMonth]], _targetDate_.[[ISODay]], _targetTime_.[[Hours]], _targetTime_.[[Minutes]], _targetTime_.[[Seconds]], _targetTime_.[[Milliseconds]], _targetTime_.[[Microseconds]], _targetTime_.[[Nanoseconds]], _calendarRec_, _unit_, 1, _unit_, *"trunc"*, _emptyOptions_).
+ 1. Let _roundRecord_ be ? DifferencePlainDateTimeWithRounding(_plainRelativeTo_.[[ISOYear]], _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, 0, 0, 0, _targetDate_.[[ISOYear]], _targetDate_.[[ISOMonth]], _targetDate_.[[ISODay]], _targetTime_.[[Hours]], _targetTime_.[[Minutes]], _targetTime_.[[Seconds]], _targetTime_.[[Milliseconds]], _targetTime_.[[Microseconds]], _targetTime_.[[Nanoseconds]], _calendarRec_, _unit_, 1, _unit_, *"trunc"*, _emptyOptions_).
1. Else,
1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, or IsCalendarUnit(_unit_) is *true*, throw a *RangeError* exception.
1. Let _normWithDays_ be ? Add24HourDaysToNormalizedTimeDuration(_duration_.[[Days]], _norm_).
diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html
index 65e74319f7..e758df377d 100644
--- a/spec/plaindatetime.html
+++ b/spec/plaindatetime.html
@@ -1315,7 +1315,9 @@
DifferencePlainDateTimeWithRounding (
- _plainDate1_: a Temporal.PlainDate,
+ _y1_: an integer,
+ _mon1_: an integer,
+ _d1_: an integer,
_h1_: an integer in the inclusive interval from 0 to 23,
_min1_: an integer in the inclusive interval from 0 to 59,
_s1_: an integer in the inclusive interval from 0 to 59,
@@ -1344,10 +1346,8 @@
+ 1. Assert: IsValidISODate(_y1_, _mon1_, _d1_) is *true*.
1. Assert: IsValidISODate(_y2_, _mon2_, _d2_) is *true*.
- 1. Let _y1_ be _plainDate1_.[[ISOYear]].
- 1. Let _mon1_ be _plainDate1_.[[ISOMonth]].
- 1. Let _d1_ be _plainDate1_.[[ISODay]].
1. If CompareISODateTime(_y1_, _mon1_, _d1_, _h1_, _min1_, _s1_, _ms1_, _mus1_, _ns1_, _y2_, _mon2_, _d2_, _h2_, _min2_, _s2_, _ms2_, _mus2_, _ns2_) = 0, then
1. Let _durationRecord_ be CreateDurationRecord(0, 0, 0, 0, 0, 0, 0, 0, 0, 0).
1. Return the Record { [[DurationRecord]]: _durationRecord_, [[Total]]: 0 }.
@@ -1388,9 +1388,8 @@
1. Set _datePartsIdentical_ to *true*.
1. If _datePartsIdentical_ is *true*, and _dateTime_.[[ISOHour]] = _other_.[[ISOHour]], and _dateTime_.[[ISOMinute]] = _other_.[[ISOMinute]], and _dateTime_.[[ISOSecond]] = _other_.[[ISOSecond]], and _dateTime_.[[ISOMillisecond]] = _other_.[[ISOMillisecond]], and _dateTime_.[[ISOMicrosecond]] = _other_.[[ISOMicrosecond]], and _dateTime_.[[ISONanosecond]] = _other_.[[ISONanosecond]], then
1. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0).
- 1. Let _plainDate_ be ! CreateTemporalDate(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[Calendar]]).
1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « ~date-add~, ~date-until~ »).
- 1. Let _resultRecord_ be ? DifferencePlainDateTimeWithRounding(_plainDate_, _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _other_.[[ISOYear]], _other_.[[ISOMonth]], _other_.[[ISODay]], _other_.[[ISOHour]], _other_.[[ISOMinute]], _other_.[[ISOSecond]], _other_.[[ISOMillisecond]], _other_.[[ISOMicrosecond]], _other_.[[ISONanosecond]], _calendarRec_, _settings_.[[LargestUnit]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]], _resolvedOptions_).
+ 1. Let _resultRecord_ be ? DifferencePlainDateTimeWithRounding(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _other_.[[ISOYear]], _other_.[[ISOMonth]], _other_.[[ISODay]], _other_.[[ISOHour]], _other_.[[ISOMinute]], _other_.[[ISOSecond]], _other_.[[ISOMillisecond]], _other_.[[ISOMicrosecond]], _other_.[[ISONanosecond]], _calendarRec_, _settings_.[[LargestUnit]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]], _resolvedOptions_).
1. Let _result_ be _resultRecord_.[[DurationRecord]].
1. Return ? CreateTemporalDuration(_sign_ × _result_.[[Years]], _sign_ × _result_.[[Months]], _sign_ × _result_.[[Weeks]], _sign_ × _result_.[[Days]], _sign_ × _result_.[[Hours]], _sign_ × _result_.[[Minutes]], _sign_ × _result_.[[Seconds]], _sign_ × _result_.[[Milliseconds]], _sign_ × _result_.[[Microseconds]], _sign_ × _result_.[[Nanoseconds]]).