authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-24 04:29:25 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-24 04:29:25 -07:00
log8b7cc7151c736428f7d2029662ae1a22bc79473a
treeb8118007a179d0bfc0625d86d755bce72c6136f9
parent3fa0282bd5a5e26a5b11c24f6c974e0fd2482154

update year format definitons


2 files changed, 14 insertions(+), 15 deletions(-)

main.zig+5-5
......@@ -16,11 +16,11 @@ fn assertOk(unix_ms: u64, comptime format: []const u8, expected: string) !void {
1616}
1717
1818// zig fmt: off
19test { try assertOk(0, "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); }
20test { try assertOk(1257894000000, "YYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00"); }
21test { try assertOk(1634858430000, "YYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30"); }
22test { try assertOk(1634858430023, "YYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023"); }
23test { try assertOk(1144509852789, "YYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789"); }
19test { try assertOk(0, "YYYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); }
20test { try assertOk(1257894000000, "YYYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00"); }
21test { try assertOk(1634858430000, "YYYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30"); }
22test { try assertOk(1634858430023, "YYYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023"); }
23test { try assertOk(1144509852789, "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789"); }
2424
2525// test every field
2626test { try assertOk(1144509852789, "M", "4"); }
time.zig+9-10
......@@ -17,17 +17,17 @@ pub const DateTime = struct {
1717 const Self = @This();
1818
1919 pub fn initUnixMs(unix: u64) Self {
20 return unix_epoch.addMs(unix);
20 return epoch_unix.addMs(unix);
2121 }
2222
2323 pub fn initUnix(unix: u64) Self {
24 return unix_epoch.addSecs(unix);
24 return epoch_unix.addSecs(unix);
2525 }
2626
2727 /// Caller asserts that this is > epoch
2828 pub fn init(year: u16, month: u16, day: u16, hr: u16, min: u16, sec: u16) Self {
29 return unix_epoch
30 .addYears(year - unix_epoch.years)
29 return epoch_unix
30 .addYears(year - epoch_unix.years)
3131 .addMonths(month)
3232 .addDays(day)
3333 .addHours(hr)
......@@ -39,7 +39,7 @@ pub const DateTime = struct {
3939 return initUnixMs(@intCast(u64, std.time.milliTimestamp()));
4040 }
4141
42 pub const unix_epoch = Self{
42 pub const epoch_unix = Self{
4343 .ms = 0,
4444 .seconds = 0,
4545 .minutes = 0,
......@@ -225,7 +225,7 @@ pub const DateTime = struct {
225225 switch (tag) {
226226 .ddd => try writer.writeAll(@tagName(self.weekday)),
227227 .DD => try writer.print("{:0>2}", .{self.days + 1}),
228 .YYY => try writer.print("{:0>4}", .{self.years}),
228 .YYYY => try writer.print("{:0>4}", .{self.years}),
229229 .HH => try writer.print("{:0>2}", .{self.hours}),
230230 .mm => try writer.print("{:0>2}", .{self.minutes}),
231231 .ss => try writer.print("{:0>2}", .{self.seconds}),
......@@ -313,11 +313,10 @@ pub const DateTime = struct {
313313 W, // 1 2 ... 52 53 (ISO)
314314 Wo, // 1st 2nd ... 52nd 53rd
315315 WW, // 01 02 ... 52 53
316 Y, // 1970 1971 ... 9999 +10000 +10001
316 Y, // 11970 11971 ... 19999 20000 20001 (Holocene calendar)
317317 YY, // 70 71 ... 29 30
318 YYY, // 1970 1971 ... 2029 2030
319 YYYY, // -001970 -001971 ... +001907 +001971
320 y, // 1 2 ... 2020 ... (era)
318 YYY, // 1 2 ... 1970 1971 ... 2029 2030
319 YYYY, // 0001 0002 ... 1970 1971 ... 2029 2030
321320 N, // BC AD
322321 NN, // Before Christ ... Anno Domini
323322 A, // AM PM