| ... | ... | @@ -6,16 +6,21 @@ pub fn main() !void { |
| 6 | 6 | std.log.info("All your codebase are belong to us.", .{}); |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | | fn assertOk(input: u64, expected: string) !void { |
| 9 | fn assertOk(dt: time.DateTime, comptime format: []const u8, expected: string) !void { |
| 10 | 10 | const alloc = std.testing.allocator; |
| 11 | 11 | |
| 12 | | const actual = try time.DateTime.initUnix(input).formatAlloc(alloc, "YYYY-MM-DD HH:mm:ss"); |
| 12 | const actual = try dt.formatAlloc(alloc, format); |
| 13 | 13 | defer alloc.free(actual); |
| 14 | 14 | |
| 15 | 15 | try std.testing.expectEqualStrings(expected, actual); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // zig fmt: off |
| 19 | | test { try assertOk(0, "1970-01-01 00:00:00"); } |
| 20 | | test { try assertOk(1257894000, "2009-11-10 23:00:00"); } |
| 21 | | test { try assertOk(1634858430, "2021-10-21 23:20:30"); } |
| 19 | const initUnix = time.DateTime.initUnix; |
| 20 | test { try assertOk(initUnix(0), "YYY-MM-DD HH:mm:ss", "1970-01-01 00:00:00"); } |
| 21 | test { try assertOk(initUnix(1257894000), "YYY-MM-DD HH:mm:ss", "2009-11-10 23:00:00"); } |
| 22 | test { try assertOk(initUnix(1634858430), "YYY-MM-DD HH:mm:ss", "2021-10-21 23:20:30"); } |
| 23 | |
| 24 | const initUnixMs = time.DateTime.initUnixMs; |
| 25 | test { try assertOk(initUnixMs(1634858430023), "YYY-MM-DD HH:mm:ss.SSS", "2021-10-21 23:20:30.023"); } |
| 26 | |