Add test plug for DateTime.now

This commit is contained in:
jaina heartles 2023-01-08 15:34:54 -08:00
parent 303bce771d
commit da558ac40e
1 changed files with 7 additions and 0 deletions

View File

@ -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() };
}