Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Duration.diff returns negative number #1165

@joshua0308

Description

@joshua0308

Describe the bug
I get a negative number for a diff although the end date is after the start date.

To Reproduce

const start = DateTime.fromISO("2022-05-05T23:00", { zone: "UTC" });
const end = DateTime.fromISO("2022-05-10T00:00", { zone: "Europe/Madrid" }); // 2022-05-09T22:00Z
const diff = end.diff(start, ['days', 'hours', 'minutes']).toObject();

// diff === { days: 4, hours: -1, minutes: 0 }

Actual vs Expected behavior
I expect the diff to equal { days: 3, hours: 23, minutes: 0} instead of { days: 4, hours: -1, minutes: 0 }. It seems unintuitive to me that I have to think about adding and then subtracting to get to the diff.

Desktop (please complete the following information):

  • OS: Mac OS
  • Browser Chrome 99
  • Luxon version 2.3.1
  • Your timezone "America/New_York"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions