From 43b231411d90882f1f02bbe971e4f3b8e25c45ab Mon Sep 17 00:00:00 2001 From: squidy239 Date: Wed, 3 Dec 2025 16:51:55 -0600 Subject: [PATCH] added missing toMicroseconds and fromMicroseconds functions --- lib/std/Io.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/std/Io.zig b/lib/std/Io.zig index eb854e3eca..6b87e7c00f 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -897,6 +897,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)); } @@ -929,6 +933,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 }; } @@ -937,6 +945,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)); }