Core.Int64.t to Core.Time.t?

I’d like to convert a unix timestamp (represented as a Core.Int64.t) to a Core.Time.t. This seems like it should be easy, and I feel embarrassed even asking, but there’s no obvious Core.Time.of_int64 function, or something similar.

My guess is that I can hack this functionality by using the binary serialization interface… but that doesn’t feel very idiomatic. Is there a better way?

Just to be clear, I’m looking for some function f such that:

f (Int64.of_string "1527809341") : Core.Time.t

What is the semantics of the transformation you’re looking for? Do you want to count the integer number of seconds since the epoch? The answer to that determines how you do the transformation.

y

Yes, I think that’s right. I have an integer, n, which is the output of:

date +%s

and I’d like to get a Core.Time.t which represents the time exactly n seconds after 00:00:00 UTC.

I understand that time is a tricky business, so maybe this isn’t a precise enough semantics.

This should do it.

let cvt x =
  Time.of_span_since_epoch (Time.Span.of_sec (Int64.to_float x));;

Brilliant, thanks! :+1:t5: Wasn’t paying enough attention to Time.Span.