Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Duration::shiftTo does not convert to years correctly #1604

Open
wb459 opened this issue Mar 18, 2024 · 1 comment
Open

Duration::shiftTo does not convert to years correctly #1604

wb459 opened this issue Mar 18, 2024 · 1 comment

Comments

@wb459
Copy link

wb459 commented Mar 18, 2024

Describe the bug
Duration::shiftTo does not convert to years correctly. A value in milliseconds less than 1 year results in a new duration that is longer than a year.

To Reproduce

var luxon = require("luxon")
const result = luxon.Duration.fromObject({"millisecond": 31535940000});
result.shiftTo('year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond');

Actual vs Expected behavior
Actual:
{years: 1, months: 0, days: 4, hours: 23, minutes: 59, seconds: 0, milliseconds: 0}

Expected:
According to https://github.com/moment/luxon/blob/master/docs/math.md a year is considered to be 365 days or 31536000000 milliseconds (365 * 24 * 60 * 60 * 1000).

Desktop:

  • OS: macOS
  • Browser: Chrome
  • Luxon version: 3.4.4
  • Your timezone: UTC
@e965
Copy link

e965 commented May 8, 2024

For some reason, I'm also getting a very strange result:

console.log(
  Duration.fromObject({ days: 365 * 2 }) // 2 years
    .shiftToAll()
    .toHuman(), // toObject does return the same results
); // output - 2 years, 2 months, 0 weeks, 2 days, 0 hours, 0 minutes, 0 seconds, 0 milliseconds

I have no idea where another two months and two days came from.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants