| ... | ... | @@ -7,6 +7,7 @@ const testing = std.testing; |
| 7 | 7 | const windows = std.os.windows; |
| 8 | 8 | const linux = std.os.linux; |
| 9 | 9 | const darwin = std.os.darwin; |
| 10 | const wasi = std.os.wasi; |
| 10 | 11 | const posix = std.os.posix; |
| 11 | 12 | |
| 12 | 13 | pub const epoch = @import("epoch.zig"); |
| ... | ... | @@ -64,9 +65,21 @@ pub const milliTimestamp = switch (builtin.os) { |
| 64 | 65 | Os.windows => milliTimestampWindows, |
| 65 | 66 | Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix, |
| 66 | 67 | Os.macosx, Os.ios => milliTimestampDarwin, |
| 68 | Os.wasi => milliTimestampWasi, |
| 67 | 69 | else => @compileError("Unsupported OS"), |
| 68 | 70 | }; |
| 69 | 71 | |
| 72 | fn milliTimestampWasi() u64 { |
| 73 | var ns: wasi.timestamp_t = undefined; |
| 74 | |
| 75 | // TODO: Verify that precision is ignored |
| 76 | const err = wasi.clock_time_get(wasi.CLOCK_REALTIME, 1, &ns); |
| 77 | debug.assert(err == wasi.ESUCCESS); |
| 78 | |
| 79 | const ns_per_ms = 1000; |
| 80 | return @divFloor(ns, ns_per_ms); |
| 81 | } |
| 82 | |
| 70 | 83 | fn milliTimestampWindows() u64 { |
| 71 | 84 | //FileTime has a granularity of 100 nanoseconds |
| 72 | 85 | // and uses the NTFS/Windows epoch |