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 {...@@ -16,11 +16,11 @@ fn assertOk(unix_ms: u64, comptime format: []const u8, expected: string) !void {
16}16}
1717
18// zig fmt: off18// zig fmt: off
19test { try assertOk(0, "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); }19test { try assertOk(0, "YYYY-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"); }20test { try assertOk(1257894000000, "YYYY-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"); }21test { try assertOk(1634858430000, "YYYY-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"); }22test { try assertOk(1634858430023, "YYYY-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"); }23test { try assertOk(1144509852789, "YYYY-MM-DD HH:mm:ss.SSS", "2006-04-08 15:24:12.789"); }
2424
25// test every field25// test every field
26test { try assertOk(1144509852789, "M", "4"); }26test { try assertOk(1144509852789, "M", "4"); }
time.zig+9-10
...@@ -17,17 +17,17 @@ pub const DateTime = struct {...@@ -17,17 +17,17 @@ pub const DateTime = struct {
17 const Self = @This();17 const Self = @This();
1818
19 pub fn initUnixMs(unix: u64) Self {19 pub fn initUnixMs(unix: u64) Self {
20 return unix_epoch.addMs(unix);20 return epoch_unix.addMs(unix);
21 }21 }
2222
23 pub fn initUnix(unix: u64) Self {23 pub fn initUnix(unix: u64) Self {
24 return unix_epoch.addSecs(unix);24 return epoch_unix.addSecs(unix);
25 }25 }
2626
27 /// Caller asserts that this is > epoch27 /// Caller asserts that this is > epoch
28 pub fn init(year: u16, month: u16, day: u16, hr: u16, min: u16, sec: u16) Self {28 pub fn init(year: u16, month: u16, day: u16, hr: u16, min: u16, sec: u16) Self {
29 return unix_epoch29 return epoch_unix
30 .addYears(year - unix_epoch.years)30 .addYears(year - epoch_unix.years)
31 .addMonths(month)31 .addMonths(month)
32 .addDays(day)32 .addDays(day)
33 .addHours(hr)33 .addHours(hr)
...@@ -39,7 +39,7 @@ pub const DateTime = struct {...@@ -39,7 +39,7 @@ pub const DateTime = struct {
39 return initUnixMs(@intCast(u64, std.time.milliTimestamp()));39 return initUnixMs(@intCast(u64, std.time.milliTimestamp()));
40 }40 }
4141
42 pub const unix_epoch = Self{42 pub const epoch_unix = Self{
43 .ms = 0,43 .ms = 0,
44 .seconds = 0,44 .seconds = 0,
45 .minutes = 0,45 .minutes = 0,
...@@ -225,7 +225,7 @@ pub const DateTime = struct {...@@ -225,7 +225,7 @@ pub const DateTime = struct {
225 switch (tag) {225 switch (tag) {
226 .ddd => try writer.writeAll(@tagName(self.weekday)),226 .ddd => try writer.writeAll(@tagName(self.weekday)),
227 .DD => try writer.print("{:0>2}", .{self.days + 1}),227 .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}),
229 .HH => try writer.print("{:0>2}", .{self.hours}),229 .HH => try writer.print("{:0>2}", .{self.hours}),
230 .mm => try writer.print("{:0>2}", .{self.minutes}),230 .mm => try writer.print("{:0>2}", .{self.minutes}),
231 .ss => try writer.print("{:0>2}", .{self.seconds}),231 .ss => try writer.print("{:0>2}", .{self.seconds}),
...@@ -313,11 +313,10 @@ pub const DateTime = struct {...@@ -313,11 +313,10 @@ pub const DateTime = struct {
313 W, // 1 2 ... 52 53 (ISO)313 W, // 1 2 ... 52 53 (ISO)
314 Wo, // 1st 2nd ... 52nd 53rd314 Wo, // 1st 2nd ... 52nd 53rd
315 WW, // 01 02 ... 52 53315 WW, // 01 02 ... 52 53
316 Y, // 1970 1971 ... 9999 +10000 +10001316 Y, // 11970 11971 ... 19999 20000 20001 (Holocene calendar)
317 YY, // 70 71 ... 29 30317 YY, // 70 71 ... 29 30
318 YYY, // 1970 1971 ... 2029 2030318 YYY, // 1 2 ... 1970 1971 ... 2029 2030
319 YYYY, // -001970 -001971 ... +001907 +001971319 YYYY, // 0001 0002 ... 1970 1971 ... 2029 2030
320 y, // 1 2 ... 2020 ... (era)
321 N, // BC AD320 N, // BC AD
322 NN, // Before Christ ... Anno Domini321 NN, // Before Christ ... Anno Domini
323 A, // AM PM322 A, // AM PM