| ... | @@ -131,6 +131,30 @@ pub const Time = extern struct { | ... | @@ -131,6 +131,30 @@ pub const Time = extern struct { |
| 131 | | 131 | |
| 132 | /// Time is to be interpreted as local time | 132 | /// 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 | }; |
| 135 | | 159 | |
| 136 | /// Capabilities of the clock device | 160 | /// Capabilities of the clock device |