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 {...@@ -6,21 +6,17 @@ pub fn main() !void {
6 std.log.info("All your codebase are belong to us.", .{});6 std.log.info("All your codebase are belong to us.", .{});
7}7}
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 {
10 const alloc = std.testing.allocator;10 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);
13 defer alloc.free(actual);13 defer alloc.free(actual);
1414
15 try std.testing.expectEqualStrings(expected, actual);15 try std.testing.expectEqualStrings(expected, actual);
16}16}
1717
18// zig fmt: off18// zig fmt: off
19const initUnix = time.DateTime.initUnix;19test { try assertOk(0, "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); }
20test { try assertOk(initUnix(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(initUnix(1257894000), "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(initUnix(1634858430), "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"); }
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