authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-11-05 00:51:09+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-11-10 22:12:40+01:00
log5f1392247d8bb0c6355f2986ff6fbf09a0885b6f
treef2de8d88232d06748a01af9df1228e17911b3ddc
parented7f2588e409b6d154f4a08bd0029ef1e7beb06b

io: Redefine `Clock.real` to return timestamps relative to the POSIX/Unix epoch

`Clock.real` being defined to return timestamps relative to an implementation-specific epoch means that there's currently no way for the user to translate returned timestamps to actual calendar dates without digging into implementation details of any particular `Io` implementation. Redefining it to return timestamps relative to 1970-01-01T00:00:00Z fixes this problem. There are other ways to solve this, such as adding a new vtable function for returning the implementation-specific epoch, but in terms of complexity this redefinition is by far the simplest solution and only amounts to a simple 96-bit integer addition's worth of overhead on OSes like Windows that use non-POSIX/Unix epochs.

1 files changed, 6 insertions(+), 3 deletions(-)

lib/std/Io.zig+6-3
......@@ -734,7 +734,7 @@ pub const Clock = enum {
734734 /// A settable system-wide clock that measures real (i.e. wall-clock)
735735 /// time. This clock is affected by discontinuous jumps in the system
736736 /// time (e.g., if the system administrator manually changes the
737 /// clock), and by frequency adjust‐ ments performed by NTP and similar
737 /// clock), and by frequency adjustments performed by NTP and similar
738738 /// applications.
739739 ///
740740 /// This clock normally counts the number of seconds since 1970-01-01
......@@ -742,8 +742,11 @@ pub const Clock = enum {
742742 /// leap seconds; near a leap second it is typically adjusted by NTP to
743743 /// stay roughly in sync with UTC.
744744 ///
745 /// The epoch is implementation-defined. For example NTFS/Windows uses
746 /// 1601-01-01.
745 /// Timestamps returned by implementations of this clock represent time
746 /// elapsed since 1970-01-01T00:00:00Z, the POSIX/Unix epoch, ignoring
747 /// leap seconds. This is colloquially known as "Unix time". If the
748 /// underlying OS uses a different epoch for native timestamps (e.g.,
749 /// Windows, which uses 1601-01-01) they are translated accordingly.
747750 real,
748751 /// A nonsettable system-wide clock that represents time since some
749752 /// unspecified point in the past.