authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-23 18:09:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-23 18:09:07 -07:00
logca473ac0fa3bea18ba33961d1001062aa81810c7
treef806aa78211c3c13aeaee25c9d2a943354b38fb9
parente9e770c300edaa63e196d99be4f0229c0f3d0dc1

add DateTime.daysInMonth


1 files changed, 8 insertions(+), 4 deletions(-)

time.zig+8-4
...@@ -169,11 +169,15 @@ pub const DateTime = struct {...@@ -169,11 +169,15 @@ pub const DateTime = struct {
169 return if (self.isLeapYear()) 366 else 365;169 return if (self.isLeapYear()) 366 else 365;
170 }170 }
171171
172 pub fn daysThisMonth(self: Self) u64 {172 pub fn daysThisMonth(self: Self) u16 {
173 const norm = [12]u64{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };173 return self.daysInMonth(self.months);
174 const leap = [12]u64{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };174 }
175
176 fn daysInMonth(self: Self, month: u16) u16 {
177 const norm = [12]u16{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
178 const leap = [12]u16{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
175 const month_days = if (!self.isLeapYear()) norm else leap;179 const month_days = if (!self.isLeapYear()) norm else leap;
176 return month_days[self.months];180 return month_days[month];
177 }181 }
178182
179 fn incrementWeekday(self: *Self, count: u64) void {183 fn incrementWeekday(self: *Self, count: u64) void {