kornos/kernel/src/time.zig

41 lines
902 B
Zig

const std = @import("std");
var boot_epoch: u64 = undefined;
var epoch: u64 = 0;
fn year_is_leap(y: u16) bool {
return (y%4) == 0;
}
pub const DateTime = struct {
year: u16,
month: u8,
day: u16,
hours: u8,
mins: u8,
secs: u8,
fn fromEpoch(e: u64) DateTime {
// const year = 1970;
// var yearlen = if(year_is_leap(year))
const year = 1970 + (e / 31556926);
const days = (e % 31556926) / 86400;
return .{
.secs = @intCast(u8, e % 60),
.mins = @intCast(u8, (e/60) % 60),
.hours = @intCast(u8, (e /3600) % 60),
.day = @intCast(u16, days),
.month = 0,
.year = @intCast(u16, year),
};
}
};
export fn setEpoch(e: u64) void {
boot_epoch = e;
}
pub fn displayTime(w: anytype) !void {
try w.print("{}", .{DateTime.fromEpoch(boot_epoch)});
}