What happened to Timestamp and what actually is Clock?

Hello everyone!

I tried to reuse some of my 0.15 code for the 0.16-master to time a program and to create a file with the timestamp on it to be surprised at the function std.time.timesamp() not existing anymore. Checking the implementation of Io I’ve discovered that Timestamp is there, but there is also Io.Clock, which seems to be what Timestamp used to be?

I understand this behavior falling under the Io umbrella, but why Clock returns a timestamp?

    const real_clock = Io.Clock.real;
    const timestamp = Io.Clock.now(real_clock, init.io);

And what’s Io.Timestamp used for now? Will the std.time just contain time change constants as it does now? I am a little bit confused haha

Thank you :slight_smile:

A Clock defines where/how to get the timestamp. Different operating systems offer different kinds of clocks that have different behaviors. Essentially, it tells Io how to look up the timestamp.
For example, Clock.real attempts to map to a real wall clock style time, however it is not strictly increasing as the OS internal clock can be adjusted by things like NTP or a cli tool. This can cause a weird behavior. So letting the user decide which Clock to use allows them to use the clock appropriate for their use case instead of whatever was chosen in std.time.timestamp()

Not an answer to your full question, but this can be simplified to:

const timestamp = Io.Clock.now(.real, init.io);`
// or:
const timestamp = Io.Clock.real.now(init.io);
1 Like

There is also std.epoch now in case you want to convert the timestamp into regular human format. This is my timestamp.zig what is currently working on 0.16 latest. It is essentially @ehrktia’s showcase that I saw and refactored a bit.

1 Like