Skip to content

Commit da47168

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 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 parent c2ad70d commit da47168

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 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.

0 commit comments

Comments
 (0)