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) }