Skip to content

Commit

Permalink
Month -1 offset fix (#11)
Browse files Browse the repository at this point in the history
`date.getUTCMonth()` and `date.getMonth()` are zero-based, causing months tin the converted date to be offset by -1. Therefore 1 Jan 1970 becomes 1970-00-01, etc. 

This simple fix negates the offset
  • Loading branch information
Tim-Vrhn authored May 19, 2023
1 parent 129c7c8 commit 936b512
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ function timestampToDate(ts) {

function getLocalString(date) {
tz = date.getTimezoneOffset()
return `${date.getFullYear()}-${pad(date.getMonth())}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())} GMT${tz < 0 ? '+' : '-'}${pad(Math.floor(tz / 60))}:${pad(tz % 60)}`
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())} GMT${tz < 0 ? '+' : '-'}${pad(Math.floor(tz / 60))}:${pad(tz % 60)}`
}

function getUTCString(date) {
return `${date.getUTCFullYear()}-${pad(date.getUTCMonth())}-${pad(date.getUTCDate())} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())} GMT`
return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())} GMT`
}

function pad(v) {
Expand Down

0 comments on commit 936b512

Please sign in to comment.