mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-09 15:19:07 +00:00
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.
This commit is contained in:
parent
ed7f2588e4
commit
5f1392247d
1 changed files with 6 additions and 3 deletions
|
|
@ -734,7 +734,7 @@ pub const Clock = enum {
|
||||||
/// A settable system-wide clock that measures real (i.e. wall-clock)
|
/// A settable system-wide clock that measures real (i.e. wall-clock)
|
||||||
/// time. This clock is affected by discontinuous jumps in the system
|
/// time. This clock is affected by discontinuous jumps in the system
|
||||||
/// time (e.g., if the system administrator manually changes the
|
/// time (e.g., if the system administrator manually changes the
|
||||||
/// clock), and by frequency adjust‐ ments performed by NTP and similar
|
/// clock), and by frequency adjustments performed by NTP and similar
|
||||||
/// applications.
|
/// applications.
|
||||||
///
|
///
|
||||||
/// This clock normally counts the number of seconds since 1970-01-01
|
/// This clock normally counts the number of seconds since 1970-01-01
|
||||||
|
|
@ -742,8 +742,11 @@ pub const Clock = enum {
|
||||||
/// leap seconds; near a leap second it is typically adjusted by NTP to
|
/// leap seconds; near a leap second it is typically adjusted by NTP to
|
||||||
/// stay roughly in sync with UTC.
|
/// stay roughly in sync with UTC.
|
||||||
///
|
///
|
||||||
/// The epoch is implementation-defined. For example NTFS/Windows uses
|
/// Timestamps returned by implementations of this clock represent time
|
||||||
/// 1601-01-01.
|
/// elapsed since 1970-01-01T00:00:00Z, the POSIX/Unix epoch, ignoring
|
||||||
|
/// leap seconds. This is colloquially known as "Unix time". If the
|
||||||
|
/// underlying OS uses a different epoch for native timestamps (e.g.,
|
||||||
|
/// Windows, which uses 1601-01-01) they are translated accordingly.
|
||||||
real,
|
real,
|
||||||
/// A nonsettable system-wide clock that represents time since some
|
/// A nonsettable system-wide clock that represents time since some
|
||||||
/// unspecified point in the past.
|
/// unspecified point in the past.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue