You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The DateTime::parse_str(...) constructor supports various different formats, but millisecond-granularity timestamps are parsed incorrectly when they have a fractional part.
Analysis: the difference between the two values is 864, which is close to the fractional part .865. It seems that the fractional part of a float input is always interpreted on the seconds scale, even if the integral part of the input is interpreted on the milliseconds scale.
This is not a bug in the above timestamp_ms() helper. The same problem can be observed when accessing this functionality via Pydantic:
Originally I though this was a bug in the custom float parsing which seems to accumulate rounding errors because it skips the checks in f64::from_str(), but I now think the issue is actually in the usage of the DateTime::from_timestamp(ts, micros) constructor by the parse_bytes_with_config() constructor:
I am not sure how to fix this. It is impossible to call DateTime::from_timestamp(ts, micros) with a non-zero value for micros without already knowing how the ts part will be interpreted.
The text was updated successfully, but these errors were encountered:
* add tests for #61
* fix millisecond fraction being handled with wrong scale
* also raise error if fraction too long
* additional test cases
* update comment
* fix doctest
The
DateTime::parse_str(...)
constructor supports various different formats, but millisecond-granularity timestamps are parsed incorrectly when they have a fractional part.Testcase to reproduce:
Failure:
Analysis: the difference between the two values is
864
, which is close to the fractional part.865
. It seems that the fractional part of a float input is always interpreted on the seconds scale, even if the integral part of the input is interpreted on the milliseconds scale.This is not a bug in the above
timestamp_ms()
helper. The same problem can be observed when accessing this functionality via Pydantic:Originally I though this was a bug in the custom float parsing which seems to accumulate rounding errors because it skips the checks in
f64::from_str()
, but I now think the issue is actually in the usage of theDateTime::from_timestamp(ts, micros)
constructor by theparse_bytes_with_config()
constructor:speedate/src/datetime.rs
Lines 344 to 346 in ecbe681
I am not sure how to fix this. It is impossible to call
DateTime::from_timestamp(ts, micros)
with a non-zero value formicros
without already knowing how thets
part will be interpreted.The text was updated successfully, but these errors were encountered: