Created
February 7, 2014 21:22
-
-
Save nisaacson/8872117 to your computer and use it in GitHub Desktop.
Parse timestamp strings with timezones. Use Denver timezone if timezone is 00 (ie not set).
This file contains 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
// Denver ISO 8601 Offset | |
// see https://github.com/moment/moment/issues/1422#issuecomment-32908589 | |
var DEFAULT_TIMEZONE_OFFSET = '-07:00' | |
var moment = require('moment') | |
console.log(parseTime('2013-01-01T00:00:00-02:00')) | |
console.log(parseTime('2013-01-01 00:00:00')); | |
function parseTime(input) { | |
var date = moment.parseZone(input) | |
var zone = date.zone() | |
if (zone === 0) { | |
return date.zone(DEFAULT_TIMEZONE_OFFSET).toISOString() | |
} | |
return date.toISOString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment