How to convert a `Timestamp` into `SystemTime`?
Closed this issue · 6 comments
Is it possible to convert Timestamp
into SystemTime
? Seems like UniFFI works with SystemTime
for binding to other languages, so even though my code uses Timestamp
internally, for the UniFFI binding layer I need to convert the Timestamp
into SystemTime
.
SystemTime::UNIX_EPOCH + your_timestamp.duration_since(Timestamp::UNIX_EPOCH)
would be the easiest way to convert them. I'll add a From
impl soon that'll do that.
This operation can be quite inefficient given the different representations, though, so keep that in mind.
EDIT: Added From<Timestamp> for SystemTime
in 0.2.14
Nice! Thanks!
Would it be useful for you to have uniffi_core::FfiConverter
implemented for Timestamp
instead? Likely more efficient than converting entirely to SystemTime
. I've already prototyped it.
Huh, turns out there's a bug in uniffi's SystemTime
handling where it'll lose precision between the unix epoch and one second before the unix epoch. Negative nanoseconds with zero whole seconds is unrepresentable.
@novacrazy yes that would be helpful!
I dont care a lot about precision for my particular usecase, so the bug you found will not affect me.