fix: windows current ns

This commit is contained in:
Nurul Huda (Apon) 2026-05-27 12:54:43 +06:00
parent f302c55135
commit c99ecad5c2
No known key found for this signature in database
GPG key ID: 5D3F1DE2855A2F79

View file

@ -1,3 +1,4 @@
const builtin = @import("builtin");
const std = @import("std"); const std = @import("std");
const Instant = @import("Instant.zig"); const Instant = @import("Instant.zig");
const PlainDate = @import("PlainDate.zig"); const PlainDate = @import("PlainDate.zig");
@ -134,15 +135,23 @@ fn currentParts(io: std.Io) CurrentParts {
} }
fn currentEpochNanoseconds() i128 { fn currentEpochNanoseconds() i128 {
var timespec: std.posix.timespec = undefined; return switch (builtin.os.tag) {
switch (std.posix.errno(std.posix.system.clock_gettime(.REALTIME, &timespec))) { .windows => blk: {
.SUCCESS => {}, const epoch_ns = std.time.epoch.windows * std.time.ns_per_s;
else => return 0, 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, &timespec))) {
.SUCCESS => {},
else => return 0,
}
const seconds: i128 = @intCast(timespec.sec); const seconds: i128 = @intCast(timespec.sec);
const nanos: i128 = @intCast(timespec.nsec); const nanos: i128 = @intCast(timespec.nsec);
return seconds * std.time.ns_per_s + nanos; break :blk seconds * std.time.ns_per_s + nanos;
},
};
} }
// ---------- Tests --------------------- // ---------- Tests ---------------------