| ... | @@ -7,6 +7,7 @@ const testing = std.testing; | ... | @@ -7,6 +7,7 @@ const testing = std.testing; |
| 7 | const windows = std.os.windows; | 7 | const windows = std.os.windows; |
| 8 | const linux = std.os.linux; | 8 | const linux = std.os.linux; |
| 9 | const darwin = std.os.darwin; | 9 | const darwin = std.os.darwin; |
| | 10 | const wasi = std.os.wasi; |
| 10 | const posix = std.os.posix; | 11 | const posix = std.os.posix; |
| 11 | | 12 | |
| 12 | pub const epoch = @import("epoch.zig"); | 13 | pub const epoch = @import("epoch.zig"); |
| ... | @@ -64,9 +65,21 @@ pub const milliTimestamp = switch (builtin.os) { | ... | @@ -64,9 +65,21 @@ pub const milliTimestamp = switch (builtin.os) { |
| 64 | Os.windows => milliTimestampWindows, | 65 | Os.windows => milliTimestampWindows, |
| 65 | Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix, | 66 | Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix, |
| 66 | Os.macosx, Os.ios => milliTimestampDarwin, | 67 | Os.macosx, Os.ios => milliTimestampDarwin, |
| | 68 | Os.wasi => milliTimestampWasi, |
| 67 | else => @compileError("Unsupported OS"), | 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 | fn milliTimestampWindows() u64 { | 83 | fn milliTimestampWindows() u64 { |
| 71 | //FileTime has a granularity of 100 nanoseconds | 84 | //FileTime has a granularity of 100 nanoseconds |
| 72 | // and uses the NTFS/Windows epoch | 85 | // and uses the NTFS/Windows epoch |