diff --git a/main.zig b/main.zig index 6d9a99356c38422248c5bf1a6f2afebe08ab4e05..594f700b0b5ad3e879a05d6004848fa036a1cd5f 100644 --- a/main.zig +++ b/main.zig @@ -6,21 +6,17 @@ pub fn main() !void { std.log.info("All your codebase are belong to us.", .{}); } -fn assertOk(dt: time.DateTime, comptime format: []const u8, expected: string) !void { +fn assertOk(unix_ms: u64, comptime format: []const u8, expected: string) !void { const alloc = std.testing.allocator; - const actual = try dt.formatAlloc(alloc, format); + const actual = try time.DateTime.initUnixMs(unix_ms).formatAlloc(alloc, format); defer alloc.free(actual); try std.testing.expectEqualStrings(expected, actual); } // zig fmt: off -const initUnix = time.DateTime.initUnix; -test { try assertOk(initUnix(0), "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); } -test { try assertOk(initUnix(1257894000), "YYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00"); } -test { try assertOk(initUnix(1634858430), "YYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30"); } - -const initUnixMs = time.DateTime.initUnixMs; -test { try assertOk(initUnixMs(1634858430023), "YYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023"); } - +test { try assertOk(0, "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); } +test { try assertOk(1257894000000, "YYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00"); } +test { try assertOk(1634858430000, "YYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30"); } +test { try assertOk(1634858430023, "YYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023"); }