Created
January 29, 2015 16:17
-
-
Save davidmfoley/1aa5f8060582c4ccd271 to your computer and use it in GitHub Desktop.
Very kludgy PG timestamp to JS date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
// turns a postgres timestamptz field into a JS date | |
parse: function(s) { | |
//split on second fraction | |
var pieces = s.split('.'); | |
// replace space with ISO T separator | |
pieces[0] = pieces[0].replace(' ', 'T'); | |
// strip to milliseconds | |
pieces[1] = pieces[1].slice(0, 3) + pieces[1].slice(6); | |
// add minutes to TZ offset - doesn't handle non-hour TZs | |
pieces[1] = pieces[1] + ':00'; | |
return new Date(pieces.join('.')); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment