r-lib / clock

A Date-Time Library for R
https://clock.r-lib.org
Other
97 stars 4 forks source link

How to construct `clock_time_point` class objects from two internal numbers (lower and upper)? #365

Open eitsupi opened 4 months ago

eitsupi commented 4 months ago

I would like to implement interconversion with the clock_time_point class in the polars package. (clock -> polars is here pola-rs/r-polars#861)

Polars holds the datetime as an Int64 type, so I am thinking that the conversion to clock_time_point needs to be converted to two UInt64 types in Rust and then passed to two double in R.

I am wondering if there is a way to create an clock_time_point class object from two R's double.

I am not familiar with the vctrs package and C++, so do not fully understand how the clock_time_point class is constructed.

Thanks in advance.

DavisVaughan commented 4 months ago

I have not yet exposed a way to convert from low level types (like a C int64_t) to the pair of doubles that clock expects.

I think you found it already but the key bit is https://github.com/r-lib/clock/blob/adc01b61670b18463cc3087f1e58acf59ddc3915/src/duration.h#L133-L184

It makes me fairly nervous for polars to rely on these internal details since I haven't exposed anything for it yet. In fact, I only somewhat recently changed to this approach, and made massive internal changes in the underlying storage model. I would not have been able to do that as easily if polars was relying on the previous internal storage model.

Would it be possible for you to use an exposed API to go polars <-> string <-> clock for now? I don't have the time right now, but when I next do a sizable release of clock I can try and expose some developer facing interface to help you out.

eitsupi commented 4 months ago

Thanks, that sounds good. The polars package is not released in CRAN so I don't think it will be a problem if it breaks with the clock update, but I will try to update it to use string.