authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-23 16:20:10 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-23 16:20:10 -07:00
loge9e770c300edaa63e196d99be4f0229c0f3d0dc1
tree1d9a31f083ec770828bbbfc9506a72c636ee9375
parent73c55102612e55eb8f07eadb51cfa610efc9f3eb

use ms for all tests


1 files changed, 6 insertions(+), 10 deletions(-)

main.zig+6-10
......@@ -6,21 +6,17 @@ pub fn main() !void {
66 std.log.info("All your codebase are belong to us.", .{});
77}
88
9fn assertOk(dt: time.DateTime, comptime format: []const u8, expected: string) !void {
9fn assertOk(unix_ms: u64, comptime format: []const u8, expected: string) !void {
1010 const alloc = std.testing.allocator;
1111
12 const actual = try dt.formatAlloc(alloc, format);
12 const actual = try time.DateTime.initUnixMs(unix_ms).formatAlloc(alloc, format);
1313 defer alloc.free(actual);
1414
1515 try std.testing.expectEqualStrings(expected, actual);
1616}
1717
1818// zig fmt: off
19const initUnix = time.DateTime.initUnix;
20test { try assertOk(initUnix(0), "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); }
21test { try assertOk(initUnix(1257894000), "YYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00"); }
22test { try assertOk(initUnix(1634858430), "YYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30"); }
23
24const initUnixMs = time.DateTime.initUnixMs;
25test { try assertOk(initUnixMs(1634858430023), "YYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023"); }
26
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"); }