| ... | @@ -12,7 +12,6 @@ pub const DateTime = struct { | ... | @@ -12,7 +12,6 @@ pub const DateTime = struct { |
| 12 | months: u16, | 12 | months: u16, |
| 13 | years: u16, | 13 | years: u16, |
| 14 | timezone: TimeZone, | 14 | timezone: TimeZone, |
| 15 | weekday: WeekDay, | | |
| 16 | | 15 | |
| 17 | const Self = @This(); | 16 | const Self = @This(); |
| 18 | | 17 | |
| ... | @@ -48,7 +47,6 @@ pub const DateTime = struct { | ... | @@ -48,7 +47,6 @@ pub const DateTime = struct { |
| 48 | .months = 0, | 47 | .months = 0, |
| 49 | .years = 1970, | 48 | .years = 1970, |
| 50 | .timezone = .UTC, | 49 | .timezone = .UTC, |
| 51 | .weekday = .Thu, | | |
| 52 | }; | 50 | }; |
| 53 | | 51 | |
| 54 | pub fn eql(self: Self, other: Self) bool { | 52 | pub fn eql(self: Self, other: Self) bool { |
| ... | @@ -101,7 +99,6 @@ pub const DateTime = struct { | ... | @@ -101,7 +99,6 @@ pub const DateTime = struct { |
| 101 | if (input >= year_len) { | 99 | if (input >= year_len) { |
| 102 | result.years += 1; | 100 | result.years += 1; |
| 103 | input -= year_len; | 101 | input -= year_len; |
| 104 | result.incrementWeekday(year_len); | | |
| 105 | continue; | 102 | continue; |
| 106 | } | 103 | } |
| 107 | break; | 104 | break; |
| ... | @@ -111,7 +108,6 @@ pub const DateTime = struct { | ... | @@ -111,7 +108,6 @@ pub const DateTime = struct { |
| 111 | if (input >= month_len) { | 108 | if (input >= month_len) { |
| 112 | result.months += 1; | 109 | result.months += 1; |
| 113 | input -= month_len; | 110 | input -= month_len; |
| 114 | result.incrementWeekday(month_len); | | |
| 115 | | 111 | |
| 116 | if (result.months == 12) { | 112 | if (result.months == 12) { |
| 117 | result.years += 1; | 113 | result.years += 1; |
| ... | @@ -128,10 +124,8 @@ pub const DateTime = struct { | ... | @@ -128,10 +124,8 @@ pub const DateTime = struct { |
| 128 | input -= left; | 124 | input -= left; |
| 129 | result.months += 1; | 125 | result.months += 1; |
| 130 | result.days = 0; | 126 | result.days = 0; |
| 131 | result.incrementWeekday(left); | | |
| 132 | } | 127 | } |
| 133 | result.days += @intCast(input); | 128 | result.days += @intCast(input); |
| 134 | result.incrementWeekday(input); | | |
| 135 | | 129 | |
| 136 | if (result.months == 12) { | 130 | if (result.months == 12) { |
| 137 | result.years += 1; | 131 | result.years += 1; |
| ... | @@ -175,13 +169,6 @@ pub const DateTime = struct { | ... | @@ -175,13 +169,6 @@ pub const DateTime = struct { |
| 175 | return time.daysInMonth(self.years, month); | 169 | return time.daysInMonth(self.years, month); |
| 176 | } | 170 | } |
| 177 | | 171 | |
| 178 | fn incrementWeekday(self: *Self, count: u64) void { | | |
| 179 | var i = count % 7; | | |
| 180 | while (i > 0) : (i -= 1) { | | |
| 181 | self.weekday = self.weekday.next(); | | |
| 182 | } | | |
| 183 | } | | |
| 184 | | | |
| 185 | pub fn dayOfThisYear(self: Self) u16 { | 172 | pub fn dayOfThisYear(self: Self) u16 { |
| 186 | var ret: u16 = 0; | 173 | var ret: u16 = 0; |
| 187 | for (0..self.months) |item| { | 174 | for (0..self.months) |item| { |
| ... | @@ -252,13 +239,13 @@ pub const DateTime = struct { | ... | @@ -252,13 +239,13 @@ pub const DateTime = struct { |
| 252 | .DDDo => try printOrdinal(writer, self.dayOfThisYear() + 1), | 239 | .DDDo => try printOrdinal(writer, self.dayOfThisYear() + 1), |
| 253 | .DDDD => try writer.print("{:0>3}", .{self.dayOfThisYear() + 1}), | 240 | .DDDD => try writer.print("{:0>3}", .{self.dayOfThisYear() + 1}), |
| 254 | | 241 | |
| 255 | .d => try writer.print("{}", .{@intFromEnum(self.weekday)}), | 242 | .d => try writer.print("{}", .{@intFromEnum(self.weekday())}), |
| 256 | .do => try printOrdinal(writer, @intFromEnum(self.weekday)), | 243 | .do => try printOrdinal(writer, @intFromEnum(self.weekday())), |
| 257 | .dd => try writer.writeAll(@tagName(self.weekday)[0..2]), | 244 | .dd => try writer.writeAll(@tagName(self.weekday())[0..2]), |
| 258 | .ddd => try writer.writeAll(@tagName(self.weekday)), | 245 | .ddd => try writer.writeAll(@tagName(self.weekday())), |
| 259 | .dddd => try printLongName(writer, @intFromEnum(self.weekday), &[_]string{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }), | 246 | .dddd => try printLongName(writer, @intFromEnum(self.weekday()), &[_]string{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }), |
| 260 | .e => try writer.print("{}", .{@intFromEnum(self.weekday)}), | 247 | .e => try writer.print("{}", .{@intFromEnum(self.weekday())}), |
| 261 | .E => try writer.print("{}", .{@intFromEnum(self.weekday) + 1}), | 248 | .E => try writer.print("{}", .{@intFromEnum(self.weekday()) + 1}), |
| 262 | | 249 | |
| 263 | .w => try writer.print("{}", .{self.dayOfThisYear() / 7 + 1}), | 250 | .w => try writer.print("{}", .{self.dayOfThisYear() / 7 + 1}), |
| 264 | .wo => try printOrdinal(writer, self.dayOfThisYear() / 7 + 1), | 251 | .wo => try printOrdinal(writer, self.dayOfThisYear() / 7 + 1), |
| ... | @@ -391,6 +378,15 @@ pub const DateTime = struct { | ... | @@ -391,6 +378,15 @@ pub const DateTime = struct { |
| 391 | if (self.years >= 0) return .AD; | 378 | if (self.years >= 0) return .AD; |
| 392 | @compileError("TODO"); | 379 | @compileError("TODO"); |
| 393 | } | 380 | } |
| | 381 | |
| | 382 | pub fn weekday(self: Self) WeekDay { |
| | 383 | var i = self.daysSinceEpoch() % 7; |
| | 384 | var result = WeekDay.Thu; // weekday of epoch_unix |
| | 385 | while (i > 0) : (i -= 1) { |
| | 386 | result = result.next(); |
| | 387 | } |
| | 388 | return result; |
| | 389 | } |
| 394 | }; | 390 | }; |
| 395 | | 391 | |
| 396 | pub const format = struct { | 392 | pub const format = struct { |