Skip to content

Commit

Permalink
fix Duration::round bug with relativeTo:ZDT and smallestUnit<day
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Apr 13, 2024
1 parent 69ec763 commit 9e00104
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
# "Fix Duration rounding relative to ZonedDateTime"
# (refactors Duration::round/total to be more DRY with since/until)
#
built-ins/Temporal/Duration/prototype/round/dst-rounding-result.js
built-ins/Temporal/Duration/prototype/round/dst-rounding-result-fullcalendar.js
# ^see built-ins/Temporal/Duration/prototype/round/dst-rounding-result-fullcalendar.js
built-ins/Temporal/Duration/prototype/total/dst-rounding-result.js
# ^see built-ins/Temporal/Duration/prototype/total/dst-rounding-result-fullcalendar.js
intl402/Temporal/Duration/prototype/round/relativeto-string-datetime.js
built-ins/Temporal/Duration/prototype/round/timezone-getpossibleinstantsfor-iterable.js
built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-4.js
Expand Down
7 changes: 5 additions & 2 deletions packages/temporal-polyfill/src/internal/durationMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
createMarkerToEpochNano,
createMoveMarker,
isUniformUnit,
isZonedEpochSlots,
} from './markerSystem'
import { Overflow } from './options'
import {
Expand Down Expand Up @@ -115,7 +116,7 @@ export function addDurations<RA, C, T>(
addDayTimeDurations(
slots,
otherSlots,
maxUnit as DayTimeUnit,
maxUnit as DayTimeUnit, // largestUnit
doSubtract,
),
),
Expand Down Expand Up @@ -186,7 +187,9 @@ export function roundDuration<RA, C, T>(

const maxUnit = Math.max(durationLargestUnit, largestUnit)

if (isUniformUnit(maxUnit, relativeToSlots)) {
// Don't do nanosecond-only rounding if ZDT because rounding hours/mins/etc
// could balance-up to days, which could vary based on time zone
if (!isZonedEpochSlots(relativeToSlots) && maxUnit <= Unit.Day) {
return createDurationSlots(
checkDurationUnits(
roundDayTimeDuration(
Expand Down
2 changes: 1 addition & 1 deletion test262
Submodule test262 updated 19 files
+0 −21 test/annexB/language/eval-code/direct/script-decl-lex-collision-in-sloppy-mode.js
+14 −2 test/annexB/language/eval-code/direct/script-decl-lex-no-collision.js
+1 −1 test/built-ins/Map/groupBy/string.js
+1 −1 test/built-ins/Object/groupBy/string.js
+1 −1 test/built-ins/Temporal/Duration/prototype/round/calendar-dateadd-called-with-options-undefined.js
+0 −116 test/built-ins/Temporal/Duration/prototype/round/dst-rounding-result-fullcalendar.js
+55 −2 test/built-ins/Temporal/Duration/prototype/round/dst-rounding-result.js
+20 −2 test/built-ins/Temporal/Duration/prototype/total/dst-rounding-result.js
+8 −2 test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-non-integer.js
+8 −2 test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-non-integer.js
+62 −0 test/intl402/DurationFormat/prototype/format/fractions-of-subsecond-units-en.js
+34 −0 test/intl402/DurationFormat/prototype/format/mixed-short-and-numeric.js
+11 −3 test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined-en.js
+0 −26 test/language/expressions/assignment/S11.13.1_A7_T3.js
+40 −0 test/language/expressions/assignment/target-member-computed-reference.js
+47 −0 test/language/expressions/assignment/target-super-computed-reference.js
+0 −30 test/language/global-code/script-decl-lex-var-declared-via-eval-sloppy.js
+14 −2 test/language/global-code/script-decl-lex-var-declared-via-eval.js
+261 −77 test/staging/Intl402/Temporal/old/non-iso-calendars.js

0 comments on commit 9e00104

Please sign in to comment.