| author | |
| committer | |
| log | 801a95035c4562bea1c8b80ae5fc8e05b9b22a2d |
| tree | 23f746e1ff2938b0ada6ad8621c47c559484e9e6 |
| parent | a5900e310e6424d32c641cacd2007cc504e8caf6 |
3 files changed, 8 insertions(+), 13 deletions(-)
lib/std/crypto/Certificate.zig+1-2| ... | ... | @@ -607,11 +607,10 @@ const Date = struct { |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | { |
| 610 | const is_leap = std.time.epoch.isLeapYear(date.year); | |
| 611 | 610 | var month: u4 = 1; |
| 612 | 611 | while (month < date.month) : (month += 1) { |
| 613 | 612 | const days: u64 = std.time.epoch.getDaysInMonth( |
| 614 | @as(std.time.epoch.YearLeapKind, @enumFromInt(@intFromBool(is_leap))), | |
| 613 | date.year, | |
| 615 | 614 | @as(std.time.epoch.Month, @enumFromInt(month)), |
| 616 | 615 | ); |
| 617 | 616 | sec += days * std.time.epoch.secs_per_day; |
lib/std/os/uefi.zig+1-2| ... | ... | @@ -141,11 +141,10 @@ pub const Time = extern struct { |
| 141 | 141 | pub const unspecified_timezone: i16 = 0x7ff; |
| 142 | 142 | |
| 143 | 143 | fn daysInYear(year: u16, max_month: u4) u9 { |
| 144 | const leap_year: std.time.epoch.YearLeapKind = if (std.time.epoch.isLeapYear(year)) .leap else .not_leap; | |
| 145 | 144 | var days: u9 = 0; |
| 146 | 145 | var month: u4 = 0; |
| 147 | 146 | while (month < max_month) : (month += 1) { |
| 148 | days += std.time.epoch.getDaysInMonth(leap_year, @enumFromInt(month + 1)); | |
| 147 | days += std.time.epoch.getDaysInMonth(year, @enumFromInt(month + 1)); | |
| 149 | 148 | } |
| 150 | 149 | return days; |
| 151 | 150 | } |
lib/std/time/epoch.zig+6-9| ... | ... | @@ -64,8 +64,6 @@ pub fn getDaysInYear(year: Year) u9 { |
| 64 | 64 | return if (isLeapYear(year)) 366 else 365; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | pub const YearLeapKind = enum(u1) { not_leap, leap }; | |
| 68 | ||
| 69 | 67 | pub const Month = enum(u4) { |
| 70 | 68 | jan = 1, |
| 71 | 69 | feb, |
| ... | ... | @@ -87,13 +85,13 @@ pub const Month = enum(u4) { |
| 87 | 85 | } |
| 88 | 86 | }; |
| 89 | 87 | |
| 90 | /// Get the number of days in the given month | |
| 91 | pub fn getDaysInMonth(leap_year: YearLeapKind, month: Month) u5 { | |
| 88 | /// Get the number of days in the given month and year | |
| 89 | pub fn getDaysInMonth(year: Year, month: Month) u5 { | |
| 92 | 90 | return switch (month) { |
| 93 | 91 | .jan => 31, |
| 94 | .feb => @as(u5, switch (leap_year) { | |
| 95 | .leap => 29, | |
| 96 | .not_leap => 28, | |
| 92 | .feb => @as(u5, switch (isLeapYear(year)) { | |
| 93 | true => 29, | |
| 94 | false => 28, | |
| 97 | 95 | }), |
| 98 | 96 | .mar => 31, |
| 99 | 97 | .apr => 30, |
| ... | ... | @@ -116,9 +114,8 @@ pub const YearAndDay = struct { |
| 116 | 114 | pub fn calculateMonthDay(self: YearAndDay) MonthAndDay { |
| 117 | 115 | var month: Month = .jan; |
| 118 | 116 | var days_left = self.day; |
| 119 | const leap_kind: YearLeapKind = if (isLeapYear(self.year)) .leap else .not_leap; | |
| 120 | 117 | while (true) { |
| 121 | const days_in_month = getDaysInMonth(leap_kind, month); | |
| 118 | const days_in_month = getDaysInMonth(self.year, month); | |
| 122 | 119 | if (days_left < days_in_month) |
| 123 | 120 | break; |
| 124 | 121 | days_left -= days_in_month; |