authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2023-12-19 23:42:47-08:00
committergravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2023-12-19 23:42:47-08:00
loga86cd9138960fc3d229d8aad3daa6d7f350e2a21
tree6a93edd8182a5a5716c8291ed5834e236d3669d3
parentf36ac227b13884f42f259bc38c5b0aa012273799
signaturelock-open Commit is signed but in an unrecognized format.

os.uefi: add time to epoch conversion


1 files changed, 24 insertions(+), 0 deletions(-)

lib/std/os/uefi.zig+24
...@@ -131,6 +131,30 @@ pub const Time = extern struct {...@@ -131,6 +131,30 @@ pub const Time = extern struct {
131131
132 /// Time is to be interpreted as local time132 /// Time is to be interpreted as local time
133 pub const unspecified_timezone: i16 = 0x7ff;133 pub const unspecified_timezone: i16 = 0x7ff;
134
135 fn daysInYear(year: u16, maxMonth: u4) u32 {
136 const leapYear: std.time.epoch.YearLeapKind = if (std.time.epoch.isLeapYear(year)) .leap else .not_leap;
137 var days: u32 = 0;
138 var month: u4 = 0;
139 while (month < maxMonth) : (month += 1) {
140 days += std.time.epoch.getDaysInMonth(leapYear, @enumFromInt(month + 1));
141 }
142 return days;
143 }
144
145 pub fn toEpoch(self: std.os.uefi.Time) u64 {
146 var year: u16 = 0;
147 var days: u32 = 0;
148
149 while (year < (self.year - 1971)) : (year += 1) {
150 days += daysInYear(year + 1970, 12);
151 }
152
153 days += daysInYear(self.year, @as(u4, @intCast(self.month)) - 1) + self.day;
154 const hours = self.hour + (days * 24);
155 const minutes = self.minute + (hours * 60);
156 return self.second + (minutes * 60);
157 }
134};158};
135159
136/// Capabilities of the clock device160/// Capabilities of the clock device