structstd.time.epoch.YearAndDay[src]

Fields

year: Year
day: u9

The number of days into the year (0 to 365)

Functions

FunctioncalculateMonthDay[src]

pub fn calculateMonthDay(self: YearAndDay) MonthAndDay

Parameters

Source Code

Source code
pub fn calculateMonthDay(self: YearAndDay) MonthAndDay {
    var month: Month = .jan;
    var days_left = self.day;
    const leap_kind: YearLeapKind = if (isLeapYear(self.year)) .leap else .not_leap;
    while (true) {
        const days_in_month = getDaysInMonth(leap_kind, month);
        if (days_left < days_in_month)
            break;
        days_left -= days_in_month;
        month = @as(Month, @enumFromInt(@intFromEnum(month) + 1));
    }
    return .{ .month = month, .day_index = @as(u5, @intCast(days_left)) };
}

Source Code

Source code
pub const YearAndDay = struct {
    year: Year,
    /// The number of days into the year (0 to 365)
    day: u9,

    pub fn calculateMonthDay(self: YearAndDay) MonthAndDay {
        var month: Month = .jan;
        var days_left = self.day;
        const leap_kind: YearLeapKind = if (isLeapYear(self.year)) .leap else .not_leap;
        while (true) {
            const days_in_month = getDaysInMonth(leap_kind, month);
            if (days_left < days_in_month)
                break;
            days_left -= days_in_month;
            month = @as(Month, @enumFromInt(@intFromEnum(month) + 1));
        }
        return .{ .month = month, .day_index = @as(u5, @intCast(days_left)) };
    }
}