extern structstd.os.uefi.Time[src]

This structure represents time information.

Fields

year: u16

1900 - 9999

month: u8

1 - 12

day: u8

1 - 31

hour: u8

0 - 23

minute: u8

0 - 59

second: u8

0 - 59

_pad1: u8
nanosecond: u32

0 - 999999999

timezone: i16

The 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

Values

Constantunspecified_timezone[src]

Time is to be interpreted as local time

Source Code

Source code
pub const unspecified_timezone: i16 = 0x7ff

Functions

FunctiontoEpoch[src]

pub fn toEpoch(self: std.os.uefi.Time) u64

Parameters

self: std.os.uefi.Time

Source Code

Source code
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);
}

Source Code

Source code
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 {
        const leap_year: std.time.epoch.YearLeapKind = if (std.time.epoch.isLeapYear(year)) .leap else .not_leap;
        var days: u9 = 0;
        var month: u4 = 0;
        while (month < max_month) : (month += 1) {
            days += std.time.epoch.getDaysInMonth(leap_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);
    }
}