Skip to content

Duration::round with ZonedDateTime relativeTo conflicts with ZonedDateTime::until results #2742

@arshaw

Description

@arshaw

Apologies for this rounding/diffing nitpicking. Repro:

const duration = new Temporal.Duration(1, 0, 0, 0, 24)
const past = Temporal.ZonedDateTime.from("2019-11-01T00:00[America/Vancouver]")
const future = past.add(duration)

const durationViaUntil = past.until(future, {
  largestUnit: 'years',
})
console.log(durationViaUntil.toString())
// "P1YT24H" (desired b/c of DST)

const durationViaRound = duration.round({
  largestUnit: 'years',
  relativeTo: past,
})
console.log(durationViaRound.toString())
// "P1Y1D" (undesired)

Precedents:

  • ZonedDateTime::add adds Y/M/W/D before time parts
  • ZonedDateTime::until diffs Y/M/W/D before time parts

It would make sense to have Duration::round effectively add Y/M/W/D to relativeTo before balancing time parts up to days (NanosecondsToDays). This is currently not possible because the Duration::round methods calls BalanceTimeDurationRelative before BalanceDateDurationRelative. (see here)

Encountered while working with this test:
intl402/Temporal/Duration/prototype/round/relativeto-string-datetime.js

Similar to:
#2563
#2715

Metadata

Metadata

Assignees

Labels

non-prod-polyfillTHIS POLYFILL IS NOT FOR PRODUCTION USE!normativeWould be a normative change to the proposalspec-textSpecification text involved

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions