zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d6632b1dd281149a7219f910e90072a098cc5345 (tree)
parent 58890066d9caec3d421afe7465a2586668442982
Author: squidy239 <sachabarsayuracko@gmail.com>
Date:   Thu, 12 Mar 2026 01:34:40 +0100

std.Io: added missing toMicroseconds and fromMicroseconds functions (#30099)

added toMicroseconds and fromMicroseconds functions to std.Io.Duration and toMicroseconds to std.Io.Timestamp

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30099
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: squidy239 <sachabarsayuracko@gmail.com>
Co-committed-by: squidy239 <sachabarsayuracko@gmail.com>

Diffstat:
Mlib/std/Io.zig | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/lib/std/Io.zig b/lib/std/Io.zig @@ -925,6 +925,10 @@ pub const Timestamp = struct { return .{ .nanoseconds = x }; } + pub fn toMicroseconds(t: Timestamp) i64 { + return @intCast(@divTrunc(t.nanoseconds, std.time.ns_per_us)); + } + pub fn toMilliseconds(t: Timestamp) i64 { return @intCast(@divTrunc(t.nanoseconds, std.time.ns_per_ms)); } @@ -964,6 +968,10 @@ pub const Duration = struct { return .{ .nanoseconds = x }; } + pub fn fromMicroseconds(x: i64) Duration { + return .{ .nanoseconds = @as(i96, x) * std.time.ns_per_us }; + } + pub fn fromMilliseconds(x: i64) Duration { return .{ .nanoseconds = @as(i96, x) * std.time.ns_per_ms }; } @@ -972,6 +980,10 @@ pub const Duration = struct { return .{ .nanoseconds = @as(i96, x) * std.time.ns_per_s }; } + pub fn toMicroseconds(d: Duration) i64 { + return @intCast(@divTrunc(d.nanoseconds, std.time.ns_per_us)); + } + pub fn toMilliseconds(d: Duration) i64 { return @intCast(@divTrunc(d.nanoseconds, std.time.ns_per_ms)); }