Skip to content

Test coverage missing for roundingMode: 'halfExpand' in since for negative numbers with 0.5 remainders #1111

@justingrant

Description

@justingrant

Looks like rounding using the 'nearest' mode isn't doing away-from-zero rounding for negative 0.5 remainders. It seems to be rounding towards zero, i.e. same behavior as Math.round() which isn't correct per the proposal. From #827:

5.4.4 'nearest' - round to nearest integer, with 0.5 rounded away from zero.

Repro:

Temporal.Instant.fromEpochMilliseconds(0).subtract({milliseconds: 500}).round({smallestUnit: 'seconds'}).toString()
// => "1970-01-01T00:00:00Z" - OK (rounding towards beginning of time)

Temporal.Duration.from('-PT0.5S').round({smallestUnit: 'seconds'}).toString()
// => "-PT1S" - OK (rounds away from zero)

Temporal.DateTime.from('2020-01-01').subtract({milliseconds: 500}).since('2020-01-01', {smallestUnit: 'seconds'}).toString()
// actual: "PT0S"
// expected: "-PT1S"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions