Skip to content

Commit

Permalink
fix(datestr): Ensure generated date strings are timezone-independent
Browse files Browse the repository at this point in the history
Different dates would be generated for different timezones, since Date constructor assumes the value you give it is local time
  • Loading branch information
justinvdm committed Apr 25, 2020
1 parent d979978 commit 9a237c7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 51 deletions.
4 changes: 3 additions & 1 deletion datestr.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ module.exports = function datestr(inputs) {
var hour = fit(id, 0, 23)
var min = fit(id, 0, 59)
var millisec = fit(id, 0, 1000)
return new Date(year, monthIndex, day, hour, min, millisec).toISOString()
return new Date(
Date.UTC(year, monthIndex, day, hour, min, millisec)
).toISOString()
}

0 comments on commit 9a237c7

Please sign in to comment.