fix: windows current ns
This commit is contained in:
parent
f302c55135
commit
c99ecad5c2
1 changed files with 17 additions and 8 deletions
11
src/Now.zig
11
src/Now.zig
|
|
@ -1,3 +1,4 @@
|
|||
const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const Instant = @import("Instant.zig");
|
||||
const PlainDate = @import("PlainDate.zig");
|
||||
|
|
@ -134,6 +135,12 @@ fn currentParts(io: std.Io) CurrentParts {
|
|||
}
|
||||
|
||||
fn currentEpochNanoseconds() i128 {
|
||||
return switch (builtin.os.tag) {
|
||||
.windows => blk: {
|
||||
const epoch_ns = std.time.epoch.windows * std.time.ns_per_s;
|
||||
break :blk @as(i128, @intCast(std.os.windows.ntdll.RtlGetSystemTimePrecise())) * 100 + epoch_ns;
|
||||
},
|
||||
else => blk: {
|
||||
var timespec: std.posix.timespec = undefined;
|
||||
switch (std.posix.errno(std.posix.system.clock_gettime(.REALTIME, ×pec))) {
|
||||
.SUCCESS => {},
|
||||
|
|
@ -142,7 +149,9 @@ fn currentEpochNanoseconds() i128 {
|
|||
|
||||
const seconds: i128 = @intCast(timespec.sec);
|
||||
const nanos: i128 = @intCast(timespec.nsec);
|
||||
return seconds * std.time.ns_per_s + nanos;
|
||||
break :blk seconds * std.time.ns_per_s + nanos;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- Tests ---------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue