Last active
July 5, 2016 19:51
-
-
Save adambankin/70586da7f4b6b0610629c9a0f0bab351 to your computer and use it in GitHub Desktop.
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
var parseDate = (function () { | |
// test if `valueOf()` returns as UTC or Local time | |
var isUTCTime = ((new Date(Date._parse('2015-03-23T00:00:00'))).valueOf() === (new Date(Date.UTC(2015, 2, 23, 0, 0, 0))).valueOf()); | |
// chrome, safari and opera return UTC time so we need to convert it to Local time | |
function utcDate (str) { | |
var date = localDate(str); | |
return new Date(date.valueOf() + (date.getTimezoneOffset() * 60000)); | |
} | |
// firefox and IE/edge return Local time and this can be used directly | |
function localDate (str) { | |
return new Date(Date._parse(str)); | |
} | |
// return the correct date parsing function to populate `parseData` | |
return isUTCTime ? utcDate : localDate; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment