Skip to content

Commit

Permalink
Use adjusted UTC time for timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Rentacookie committed Oct 22, 2024
1 parent bc49fbf commit 0579a34
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/datetime_decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0579a34

Please sign in to comment.