extern struct Time [src]
This structure represents time information.
Fields
year: u161900 - 9999
month: u81 - 12
day: u81 - 31
hour: u80 - 23
minute: u80 - 59
second: u80 - 59
_pad1: u8
nanosecond: u320 - 999999999
timezone: i16The time's offset in minutes from UTC.
Allowed values are -1440 to 1440 or unspecified_timezone
daylight: packed struct(u8) {
/// If true, the time has been adjusted for daylight savings time.
in_daylight: bool,
/// If true, the time is affected by daylight savings time.
adjust_daylight: bool,
_: u6,
}
_pad2: u8
Members
- toEpoch (Function)
- unspecified_timezone (Constant)
Source
pub const Time = extern struct {
/// 1900 - 9999
year: u16,
/// 1 - 12
month: u8,
/// 1 - 31
day: u8,
/// 0 - 23
hour: u8,
/// 0 - 59
minute: u8,
/// 0 - 59
second: u8,
_pad1: u8,
/// 0 - 999999999
nanosecond: u32,
/// The time's offset in minutes from UTC.
/// Allowed values are -1440 to 1440 or unspecified_timezone
timezone: i16,
daylight: packed struct(u8) {
/// If true, the time has been adjusted for daylight savings time.
in_daylight: bool,
/// If true, the time is affected by daylight savings time.
adjust_daylight: bool,
_: u6,
},
_pad2: u8,
comptime {
std.debug.assert(@sizeOf(Time) == 16);
}
/// Time is to be interpreted as local time
pub const unspecified_timezone: i16 = 0x7ff;
fn daysInYear(year: u16, max_month: u4) u9 {
var days: u9 = 0;
var month: u4 = 0;
while (month < max_month) : (month += 1) {
days += std.time.epoch.getDaysInMonth(year, @enumFromInt(month + 1));
}
return days;
}
pub fn toEpoch(self: std.os.uefi.Time) u64 {
var year: u16 = 0;
var days: u32 = 0;
while (year < (self.year - 1971)) : (year += 1) {
days += daysInYear(year + 1970, 12);
}
days += daysInYear(self.year, @as(u4, @intCast(self.month)) - 1) + self.day;
const hours: u64 = self.hour + (days * 24);
const minutes: u64 = self.minute + (hours * 60);
const seconds: u64 = self.second + (minutes * std.time.s_per_min);
return self.nanosecond + (seconds * std.time.ns_per_s);
}
}