diff options
author | 2022-10-18 13:48:50 -0700 | |
---|---|---|
committer | 2022-10-18 13:48:50 -0700 | |
commit | 30d43b027f02b0b08992ef125e5116ebea183dc4 (patch) | |
tree | 6d77ae8f74c5afb89a2a86ebca3a043ccd73f01e | |
parent | 693b1c9b2329a016901dd5b45146dc1cf4a9dab8 (diff) | |
download | bun-30d43b027f02b0b08992ef125e5116ebea183dc4.tar.gz bun-30d43b027f02b0b08992ef125e5116ebea183dc4.tar.zst bun-30d43b027f02b0b08992ef125e5116ebea183dc4.zip |
Update javascript.zig
-rw-r--r-- | src/bun.js/javascript.zig | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index c163d99ae..59479df1a 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -537,7 +537,20 @@ pub const VirtualMachine = struct { /// Instead of storing timestamp as a i128, we store it as a u64. /// We subtract the timestamp from Jan 1, 2000 (Y2K) - pub const origin_relative_epoch = 975628800000 * std.time.ns_per_ms; + pub const origin_relative_epoch = 946684800 * std.time.ns_per_s; + fn getOriginTimestamp() u64 { + return @truncate( + u64, + @intCast( + u128, + // handle if they set their system clock to be before epoch + @maximum( + std.time.nanoTimestamp(), + origin_relative_epoch, + ), + ) - origin_relative_epoch, + ); + } pub fn init( allocator: std.mem.Allocator, @@ -582,7 +595,7 @@ pub const VirtualMachine = struct { .macros = MacroMap.init(allocator), .macro_entry_points = @TypeOf(VirtualMachine.vm.macro_entry_points).init(allocator), .origin_timer = std.time.Timer.start() catch @panic("Please don't mess with timers."), - .origin_timestamp = @truncate(u64, @intCast(u128, @maximum(std.time.nanoTimestamp(), origin_relative_epoch)) - origin_relative_epoch), + .origin_timestamp = getOriginTimestamp(), .ref_strings = JSC.RefString.Map.init(allocator), .file_blobs = JSC.WebCore.Blob.Store.Map.init(allocator), }; |