Compare commits

..

No commits in common. "7862c65fcde5e29f05638d6302ae0fa941533639" and "1bbdcd3e401f924343b46c894bc52944fd49c45a" have entirely different histories.

View file

@ -473,31 +473,6 @@ pub const DateTime = struct {
left = left[year.len..]; left = left[year.len..];
date.weekday = DayOfWeek.dayOfWeek(date.year, date.month, date.day); date.weekday = DayOfWeek.dayOfWeek(date.year, date.month, date.day);
}, },
.MMMM => {
const map = std.ComptimeStringMapWithEql(Month, .{
.{ "january", .Jan },
.{ "february", .Feb },
.{ "march", .Mar },
.{ "april", .Apr },
.{ "may", .May },
.{ "june", .Jun },
.{ "july", .Jul },
.{ "august", .Aug },
.{ "september", .Sep },
.{ "october", .Oct },
.{ "november", .Nov },
.{ "december", .Dec },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
date.month = month: {
for (1..left.len) |l| {
if (map.get(left[0..l])) |m| {
left = left[l..];
break :month m;
}
}
return error.ParseError;
};
},
.SSSSSSSSS => { .SSSSSSSSS => {
date.nanosecond = try readFrac(left, 9); date.nanosecond = try readFrac(left, 9);
left = left[9..]; left = left[9..];
@ -821,188 +796,6 @@ test "parseTest" {
.weekday = .Thu, .weekday = .Thu,
}, },
}, },
.{
.value = "january",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Jan,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "february",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Feb,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "march",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Mar,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "apr",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Apr,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "may",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .May,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "june",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Jun,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "july",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Jul,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "august",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Aug,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "september",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Sep,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "october",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Oct,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "november",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Jan,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "december",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Dec,
.year = 1970,
.weekday = .Thu,
},
},
.{
.value = "january",
.fmt = "MMMM",
.expected = .{
.nanosecond = 0,
.second = 0,
.minute = 0,
.hour = 0,
.day = 1,
.month = .Jan,
.year = 1970,
.weekday = .Thu,
},
},
}; };
inline for (cases) |case| { inline for (cases) |case| {
@ -1688,36 +1481,36 @@ test "isLeap" {
try std.testing.expectEqual(true, isLeap(2400)); try std.testing.expectEqual(true, isLeap(2400));
} }
test "bigTest" { // test "bigTest" {
const ystart = -1000000; // const ystart = -1000000;
var prev_z: i32 = daysFromCivil(ystart, .Jan, 1) - 1; // var prev_z: i32 = daysFromCivil(ystart, .Jan, 1) - 1;
try std.testing.expect(prev_z < 0); // try std.testing.expect(prev_z < 0);
var prev_wd = DayOfWeek.weekdayFromDays(prev_z); // var prev_wd = DayOfWeek.weekdayFromDays(prev_z);
try std.testing.expect(0 <= @intFromEnum(prev_wd) and @intFromEnum(prev_wd) <= 6); // try std.testing.expect(0 <= @intFromEnum(prev_wd) and @intFromEnum(prev_wd) <= 6);
var y: Year = ystart; // var y: Year = ystart;
while (y <= -ystart) { // while (y <= -ystart) {
for ([_]Month{ .Jan, .Feb, .Mar, .Apr, .May, .Jun, .Jul, .Aug, .Sep, .Oct, .Nov, .Dec }) |m| { // for ([_]Month{ .Jan, .Feb, .Mar, .Apr, .May, .Jun, .Jul, .Aug, .Sep, .Oct, .Nov, .Dec }) |m| {
var d: Day = 1; // var d: Day = 1;
const e = m.lastDay(y); // const e = m.lastDay(y);
while (d <= e) { // while (d <= e) {
// std.debug.print("{d} {d} {d}\n", .{ y, @intFromEnum(m), d }); // // std.debug.print("{d} {d} {d}\n", .{ y, @intFromEnum(m), d });
const z = daysFromCivil(y, m, d); // const z = daysFromCivil(y, m, d);
// std.debug.print("{d} {d}\n", .{ prev_z, z }); // // std.debug.print("{d} {d}\n", .{ prev_z, z });
try std.testing.expect(prev_z < z); // try std.testing.expect(prev_z < z);
try std.testing.expect(z == prev_z + 1); // try std.testing.expect(z == prev_z + 1);
const date = civilFromDays(z); // const date = civilFromDays(z);
try std.testing.expect(y == date.year); // try std.testing.expect(y == date.year);
try std.testing.expect(m == date.month); // try std.testing.expect(m == date.month);
try std.testing.expect(d == date.day); // try std.testing.expect(d == date.day);
const wd = DayOfWeek.weekdayFromDays(z); // const wd = DayOfWeek.weekdayFromDays(z);
try std.testing.expect(0 <= @intFromEnum(wd) and @intFromEnum(wd) <= 6); // try std.testing.expect(0 <= @intFromEnum(wd) and @intFromEnum(wd) <= 6);
try std.testing.expect(wd == prev_wd.next()); // try std.testing.expect(wd == prev_wd.next());
try std.testing.expect(prev_wd == wd.prev()); // try std.testing.expect(prev_wd == wd.prev());
prev_z = z; // prev_z = z;
prev_wd = wd; // prev_wd = wd;
d += 1; // d += 1;
} // }
} // }
y += 1; // y += 1;
} // }
} // }