Skip to content

Incorrect rounding result with RelativeTo::ZonedDateTime and increment #689

@ptomato

Description

@ptomato

I've run into a JS case that gives incorrect results with V8, but not with Boa. I'm not sure what Boa is doing differently to avoid the bug, but I can reproduce it when writing Rust code directly, so the underlying issue must be with temporal_rs.

Reproducer:

let duration = Duration::new(0, 0, 0, 0, 48, 0, 0, 0, 0, 0).unwrap();
let relative_to = ZonedDateTime::try_new(0_i128, TimeZone::utc(), Calendar::ISO).unwrap();
let result = duration.round_with_provider(
    RoundingOptions {
        smallest_unit: Some(Unit::Day),
        increment: Some(RoundingIncrement::new_unchecked(NonZeroU32::new(2).unwrap())),
        ..Default::default()
    },
    Some(RelativeTo::ZonedDateTime(relative_to)),
    &*crate::builtins::TZ_PROVIDER,
).unwrap();
assert_eq!(result.days(), 2);

JS code that triggers the bug:

const d = new Temporal.Duration(0, 0, 0, 0, 48);
d.round({ smallestUnit: 'days', roundingIncrement: 2 }).toString() // "P2D"
d.round({ smallestUnit: 'days', roundingIncrement: 2, relativeTo: new Temporal.ZonedDateTime(0n, 'UTC') }).toString()
  // "P4D", should be "P2D"

The inclusion of relativeTo here should make no difference, since UTC has no time zone transitions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions