diff options
Diffstat (limited to 'lib/std/time/epoch.zig')
| -rw-r--r-- | lib/std/time/epoch.zig | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/std/time/epoch.zig b/lib/std/time/epoch.zig index b409d3e9eb..fa7499aec7 100644 --- a/lib/std/time/epoch.zig +++ b/lib/std/time/epoch.zig @@ -64,8 +64,6 @@ pub fn getDaysInYear(year: Year) u9 { return if (isLeapYear(year)) 366 else 365; } -pub const YearLeapKind = enum(u1) { not_leap, leap }; - pub const Month = enum(u4) { jan = 1, feb, @@ -87,13 +85,13 @@ pub const Month = enum(u4) { } }; -/// Get the number of days in the given month -pub fn getDaysInMonth(leap_year: YearLeapKind, month: Month) u5 { +/// Get the number of days in the given month and year +pub fn getDaysInMonth(year: Year, month: Month) u5 { return switch (month) { .jan => 31, - .feb => @as(u5, switch (leap_year) { - .leap => 29, - .not_leap => 28, + .feb => @as(u5, switch (isLeapYear(year)) { + true => 29, + false => 28, }), .mar => 31, .apr => 30, @@ -116,9 +114,8 @@ pub const YearAndDay = struct { 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); + const days_in_month = getDaysInMonth(self.year, month); if (days_left < days_in_month) break; days_left -= days_in_month; |
