Created
February 28, 2017 00:09
-
-
Save skellock/74d5d40c8cf9495fd7318514af31f5bc to your computer and use it in GitHub Desktop.
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
// Source: https://github.com/szwacz/fs-jetpack/blob/master/lib/read.js#L22-L32 | |
const fromJsonDate = value => { | |
const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/ | |
if (typeof value === 'string') { | |
if (reISO.exec(value)) { | |
return new Date(value) | |
} | |
} | |
return value | |
} | |
const someDate = new Date() | |
const stringified = someDate.toJSON() | |
const dateified = fromJsonDate(stringified) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment