Compare commits

..

2 commits

Author SHA1 Message Date
7862c65fcd
parse long month 2024-03-13 23:02:56 -05:00
9f9aba2510
turn big test back on 2024-03-13 18:15:13 -05:00

View file

@ -473,6 +473,31 @@ pub const DateTime = struct {
left = left[year.len..];
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 => {
date.nanosecond = try readFrac(left, 9);
left = left[9..];
@ -796,6 +821,188 @@ test "parseTest" {
.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| {
@ -1481,36 +1688,36 @@ test "isLeap" {
try std.testing.expectEqual(true, isLeap(2400));
}
// test "bigTest" {
// const ystart = -1000000;
// var prev_z: i32 = daysFromCivil(ystart, .Jan, 1) - 1;
// try std.testing.expect(prev_z < 0);
// var prev_wd = DayOfWeek.weekdayFromDays(prev_z);
// try std.testing.expect(0 <= @intFromEnum(prev_wd) and @intFromEnum(prev_wd) <= 6);
// var y: Year = ystart;
// while (y <= -ystart) {
// for ([_]Month{ .Jan, .Feb, .Mar, .Apr, .May, .Jun, .Jul, .Aug, .Sep, .Oct, .Nov, .Dec }) |m| {
// var d: Day = 1;
// const e = m.lastDay(y);
// while (d <= e) {
// // std.debug.print("{d} {d} {d}\n", .{ y, @intFromEnum(m), d });
// const z = daysFromCivil(y, m, d);
// // std.debug.print("{d} {d}\n", .{ prev_z, z });
// try std.testing.expect(prev_z < z);
// try std.testing.expect(z == prev_z + 1);
// const date = civilFromDays(z);
// try std.testing.expect(y == date.year);
// try std.testing.expect(m == date.month);
// try std.testing.expect(d == date.day);
// const wd = DayOfWeek.weekdayFromDays(z);
// try std.testing.expect(0 <= @intFromEnum(wd) and @intFromEnum(wd) <= 6);
// try std.testing.expect(wd == prev_wd.next());
// try std.testing.expect(prev_wd == wd.prev());
// prev_z = z;
// prev_wd = wd;
// d += 1;
// }
// }
// y += 1;
// }
// }
test "bigTest" {
const ystart = -1000000;
var prev_z: i32 = daysFromCivil(ystart, .Jan, 1) - 1;
try std.testing.expect(prev_z < 0);
var prev_wd = DayOfWeek.weekdayFromDays(prev_z);
try std.testing.expect(0 <= @intFromEnum(prev_wd) and @intFromEnum(prev_wd) <= 6);
var y: Year = ystart;
while (y <= -ystart) {
for ([_]Month{ .Jan, .Feb, .Mar, .Apr, .May, .Jun, .Jul, .Aug, .Sep, .Oct, .Nov, .Dec }) |m| {
var d: Day = 1;
const e = m.lastDay(y);
while (d <= e) {
// std.debug.print("{d} {d} {d}\n", .{ y, @intFromEnum(m), d });
const z = daysFromCivil(y, m, d);
// std.debug.print("{d} {d}\n", .{ prev_z, z });
try std.testing.expect(prev_z < z);
try std.testing.expect(z == prev_z + 1);
const date = civilFromDays(z);
try std.testing.expect(y == date.year);
try std.testing.expect(m == date.month);
try std.testing.expect(d == date.day);
const wd = DayOfWeek.weekdayFromDays(z);
try std.testing.expect(0 <= @intFromEnum(wd) and @intFromEnum(wd) <= 6);
try std.testing.expect(wd == prev_wd.next());
try std.testing.expect(prev_wd == wd.prev());
prev_z = z;
prev_wd = wd;
d += 1;
}
}
y += 1;
}
}