uptime: fix math

This commit is contained in:
Jeeves 2024-03-15 20:42:20 -06:00
parent c57cd52e84
commit 5c1fd21a84

View file

@ -23,13 +23,13 @@ pub fn getJson(module: *const Module) !Module.JSON {
var uptime_split = std.mem.splitScalar(u8, uptime_string[0 .. uptime_string.len - 1], ' '); var uptime_split = std.mem.splitScalar(u8, uptime_string[0 .. uptime_string.len - 1], ' ');
var uptime = try std.fmt.parseFloat(f32, uptime_split.first()); var uptime = try std.fmt.parseFloat(f32, uptime_split.first());
const days = uptime / std.time.s_per_day; uptime /= 60;
uptime -= std.time.s_per_day * @floor(days); const mins = @mod(uptime, 60);
const hours = uptime / std.time.s_per_hour; uptime /= 60;
uptime -= std.time.s_per_hour * @floor(hours); const hours = @mod(uptime, 24);
const mins = uptime / std.time.s_per_min; uptime /= 24;
return .{ return .{
.full_text = try std.fmt.allocPrint(self.module.allocator, "{d:0>1.0}d {d:0>1.0}h {d:.0}m", .{ days, hours, mins }), .full_text = try std.fmt.allocPrint(self.module.allocator, "{d:0>1.0}d {d:0>1.0}h {d:.0}m", .{ uptime, hours, mins }),
}; };
} }