-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
DateTime + Nanosecond loses information #50785
Comments
That's because julia> Dates.toms(Nanosecond(10^6))
1
julia> Dates.toms(Nanosecond(10^6 - 1))
0 you can see we always add things in julia/stdlib/Dates/src/arithmetic.jl Lines 82 to 83 in 6dd763b
|
julia> 1 + eps(0.0)
1.0
julia> 1 + eps(0.0) === 1
false |
That's not a good analogy, DateTime can't use Nanosecond internally without using Big number, so it's actually pretty fundamental we go to ms |
Converting to milliseconds may be essential if being quantized in milliseconds is part of the API of If I'm converting into
If DateTime doesn't support what the user is asking for, it should say so, and the user can install NanoDates.jl. |
The documentation could be more explicit about Also, when constructing from a julia> DateTime( Date(now()), Time(Nanosecond(1)) )
ERROR: InexactError: DateTime(00:00:00.000000001) This behavior is explicitly implemented as well as documented. Maybe |
Even if, should:
|
Yes? Unless you want to error on DateTime + Nanosecond. If you're routinely adding less than 10^6 nanosecond, you're probably not using Julia DateTime built-in stuff anyway |
Again, Here's an example of Julia correctly refusing to lose information: julia> today()
2023-08-07
julia> today() + Hour(1)
ERROR: MethodError: no method matching +(::Date, ::Hour) For now, deprecating without removing |
This has not been fixed by #50816, I don't think. We're now inventing information out of thin air instead of losing it, by sometimes rounding up. EDIT: and we're also still losing it, by rounding down. This means there are now worse precision problems than before. |
(I agree this hasn't been closed by #50816, that's the part the thumbs-up is for.) |
Related: #35446 |
This issue came up on Slack.
DateTime
s are integral so I would expect this to promote or error, not fail silently. Floating point can lose data, but I don't think integral types do this in Julia.The text was updated successfully, but these errors were encountered: