From 985392ec16a1ca88b0250085ed6cfa99b0d15e3f Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 22 Jul 2024 16:11:31 -0600 Subject: [PATCH] Fix offset for SL timestamps --- helpers.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/helpers.js b/helpers.js index fc6edb7..096d153 100644 --- a/helpers.js +++ b/helpers.js @@ -1,11 +1,19 @@ module.exports = {} -const change = 62135659200; // Subtract a year, whoops +const change = 62167219200; // Subtract a year, whoops module.exports.convertSLTimestamp = (timestamp) => { - //change = 62167219200; // 1 year behind whoops - ourTs = Number(BigInt(timestamp) / 10000000n); - return new Date((ourTs - change) * 1000) + // Convert SCP SL timestamp to seconds since SCP epoch + const ourTs = Number(BigInt(timestamp) / 10000000n); + + // Convert to Unix timestamp (seconds since Jan 1, 1970 UTC) + const unixTs = ourTs - change; + + // Adjust for local timezone (Mountain Time in this case) + const date = new Date(unixTs * 1000); // Convert to milliseconds for JavaScript Date constructor + + return date; } + module.exports.toSLTimestamp = (timestamp) => { return String(((Number(timestamp) / 1000) + change) * 10000000) }