From da558ac40e2c7383123557d66671d1dadad47483 Mon Sep 17 00:00:00 2001 From: jaina heartles Date: Sun, 8 Jan 2023 15:34:54 -0800 Subject: [PATCH] Add test plug for DateTime.now --- src/util/DateTime.zig | 7 +++++++ 1 file changed, 7 insertions(+) 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() }; }