mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
added missing toMicroseconds and fromMicroseconds functions
This commit is contained in:
parent
d73fbcc3ae
commit
43b231411d
1 changed files with 12 additions and 0 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue