Closed sorhawell closed 9 months ago
It appears "s" and "ns" somehow overflows without warning
Note that for "s" you actually put "nanosecond"
again, I imagine if you put "second"
it would work
This is really a limitation of the underlying C++ library, date. It, like many other date time libraries, uses int64_t
as the C++ representation of nanosecond time points (See std::chrono::nanoseconds
under Helper Types at https://en.cppreference.com/w/cpp/chrono/duration).
This gives the nanosecond precision a range of around +/- 292 years around the epoch year of 1970.
On one side nanoseconds is represented by a int64_t which has a range of about +/- 292 years. (https://howardhinnant.github.io/date/date.html)
We definitely don't have any overflow protection yet, but that is quite hard to get right everywhere and will take a decent amount of effort to do it in a way that won't nuke performance too
https://github.com/r-lib/clock/pull/331 is also worth a read from a technical perspective
IIUC Rust Polars also uses an i64
for their date time types, with possible precision of nano, micro, milli https://docs.rs/polars/latest/polars/datatypes/enum.DataType.html#variant.Datetime, so it probably has the same restrictions
Note that for "s" you actually put "nanosecond" again, I imagine if you put "second" it would work
@DavisVaughan Oups sorry for drama :)
Then this issue can be closed. Can I ask on side note:
I got to the unpack / pack arithmetics
Is this correctly understood?:
The R clock package stores internally a naive_time as two R doubles which represent a u32 range The two u32 representa the upper and lower part of an u64 The u64 is offset into an i64
"two R doubles which represent a u32 range" i'd say they represent an i64 range, just in a weird way
The pack/unpack helpers there are definitely the key utilities to make this work
The rest of that looks right. In particular the arithmetic shift is important because it helps retain relative ordering (i.e. you can compare one lower/upper pair to another and get the same ordering result as if you compared the original i64s together, useful for our vctrs algorithms like vec_order()
or vec_compare()
) https://github.com/r-lib/clock/blob/adc01b61670b18463cc3087f1e58acf59ddc3915/src/duration.h#L146-L148
Hi clock people :)
I was taking a first look at the clock package to write conversions to/from r-polars. Looks good!
It appears "s" and "ns" somehow overflows without warning, whereas "ms" and "us" does not. I have not come to see the arithmetics-part of upper-lower time component, but I imagined you should be able to support year 0 to 140 million with "ns" precision with two R numerics with about 2^52 range right?
best Soren
Created on 2023-12-12 with reprex v2.0.2