From 0579a34761cc06080a7cc99a3b12f0c723d7d45f Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Tue, 22 Oct 2024 12:34:48 +0200 Subject: [PATCH] Use adjusted UTC time for timestamps --- lib/datetime_decode.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/datetime_decode.js b/lib/datetime_decode.js index c7bb56e..7787836 100644 --- a/lib/datetime_decode.js +++ b/lib/datetime_decode.js @@ -86,13 +86,18 @@ exports.getDateTime = function ( // readTemporalFraction(). With the dateStrings option from node-mysql, // this returns a mysql TIMESTAMP string, like '1975-03-01 23:03:20.38945' or // '1975-03-01 00:03:20'. Mysql strings are needed for precision beyond ms. +// MySQL Timestamps are returned based on the local of the requesting client. +// This is bug prone, so the timestamp is converted back to UTC exports.getTimeStamp = function ( dateStrings, // node-mysql dateStrings option secondsFromEpoch, // an integer fraction // optional fraction of second object ) { + const offsetSeconds = new Date().getTimezoneOffset() * 60; + const UTCEpochSeconds = secondsFromEpoch + offsetSeconds; const milliseconds = fraction ? fraction.milliseconds : 0; - const dateObject = new Date(secondsFromEpoch * 1000 + milliseconds); + + const dateObject = new Date(UTCEpochSeconds * 1000 + milliseconds); if (!useDateStringsForType(dateStrings, 'TIMESTAMP')) { return dateObject; }