diff --git a/src/util/DateTime.zig b/src/util/DateTime.zig index 2b096fa..be35aa6 100644 --- a/src/util/DateTime.zig +++ b/src/util/DateTime.zig @@ -67,7 +67,14 @@ pub fn parseRfc3339(str: []const u8) !DateTime { }; } +const is_test = @import("builtin").is_test; +const test_utils = struct { + pub threadlocal var test_now_timestamp: i64 = 1356076800; +}; +pub usingnamespace if (is_test) test_utils else struct {}; + pub fn now() DateTime { + if (comptime is_test) return .{ .seconds_since_epoch = test_utils.test_now_timestamp }; return .{ .seconds_since_epoch = std.time.timestamp() }; }