Skip to content
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

Fractional milliseconds lost in unexpected ways #1529

Open
arseniybanayev opened this issue Oct 24, 2023 · 1 comment
Open

Fractional milliseconds lost in unexpected ways #1529

arseniybanayev opened this issue Oct 24, 2023 · 1 comment

Comments

@arseniybanayev
Copy link

arseniybanayev commented Oct 24, 2023

Describe the bug
Fractional milliseconds are dropped by plus and minus.

To Reproduce

const luxon = require("luxon")
const endOfDay = luxon.DateTime.now().endOf("day").plus({ milliseconds: .999 })
assert(endOfDay.toMillis() % 1 !== 0)  // Passes
const prevEndOfDay = endOfDay.minus({ days: 1 })
assert(prevEndOfDay.toMillis() % 1 !== 0)  // Fails

Actual vs Expected behavior
Expected the second assertion to pass because I added a fractional amount of milliseconds at the end of the second line, but the fourth line dropped the fractional milliseconds. If fractional milliseconds are unsupported, then plus({ milliseconds: .999 }) should throw an exception or (worse) drop the fractional milliseconds from the return value to be consistent with the later minus({ days: 1}).

@diesieben07
Copy link
Collaborator

diesieben07 commented Oct 24, 2023

Luxon is not designed to work with units smaller than a millisecond or fractional milliseconds. Ideally, this should be enforced and always yield invalid datetimes.
There is no support for sub-millisecond accuracy in the underlying platform (JavaScript) anyways.
Ideally this should also be stated in the docs clearly, if it isn't in there already.

See also #909, which I honestly forgot about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants