-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shiftTo and shiftToAll deliver unexpected output #1634
Comments
Unfortunately I do not think this is solvable. Example: This can be anything from 2 months and 6 days (which it will be, because Duration assumes a month is 30 days), but it might also be 2 months and 8 days, if the month you're talking about would be February. But Duration has no way of knowing this. In your first example, you are taking the diff in milliseconds (the default). This is 31536000000ms. Then you're asking Luxon to convert this into all units. Now it depends on if you start filling up "from the bottom" or "from the top" which result you get. In this case Luxon fills up the units "from the bottom". The milliseconds go into seconds, then minutes, etc. In this case you eventually end up with 365 days and then 52 weeks and 1 day - so far everything is unambiguous. But you can already tell that things have gone awry, because suddenly we have "an extra day" (because don't years have 52 weeks exactly? Well, no they do not). Luxon 3.3.0 had a different algorithm for |
But it looks really weird: const yearInMs = Duration.fromObject({ year: 1 }).toMillis();
Duration.fromMillis(yearInMs).rescale().toHuman(); // => 1 year, 1 month, 1 day IMO the correct logic should be the following:
And looks like this logic was used in Luxon <= 3.4.1 as those versions return correct results. |
Unfortunately your algorithm falls apart very quickly. Take this example:
|
Yep, and that's exactly what previous versions of Luxon resulted with. That's ok as we treat one month to be ~30 days and it's explained in details in Luxon docs. |
The code you shared is not the same conversation that I posted about. You shifted milliseconds to months, not years to months. I am talking about |
Ah, ok, sorry. But what was the problem in the previous algorithm? |
Mostly negative numbers: #1233 |
Describe the bug
If we have a span of exactly one year,
shiftTo
adds several days even though it should not.shiftToAll
adds one month.This worked fine in version 3.3.0 and seems to be broken since 3.4.0.
To Reproduce
Please share a minimal code example that triggers the problem:
Actual vs Expected behavior
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: