Skip to content

Commit adcc7cd

Browse files
committed
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 epochs 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-01 00:00:00+00:00 fixes this problem. There are other ways to solve this, such as adding new vtable functions 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 for OSes like Windows that use non-POSIX/Unix epochs.
1 parent 1cf746b commit adcc7cd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/std/Io.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,19 @@ 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
741741
/// 00:00:00 Coordinated Universal Time (UTC) except that it ignores
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 this implementations of this clock are
746+
/// relative to the POSIX/Unix epoch 1970-01-01 00:00:00+00:00
747+
/// (colloquially referred to as "Unix time"). If the underlying OS
748+
/// uses a different epoch for timestamp values (e.g., Windows, which
749+
/// 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.

0 commit comments

Comments
 (0)