diff options
Diffstat (limited to 'src/apis.js')
| -rw-r--r-- | src/apis.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/apis.js b/src/apis.js index 70d9dc8b..a90685cc 100644 --- a/src/apis.js +++ b/src/apis.js @@ -202,16 +202,15 @@ var angularString = { } return chars.join(''); }, + + /** + * Tries to convert input to date and if successful returns the date, otherwise returns the input. + * @param {string} string + * @return {(Date|string)} + */ 'toDate':function(string){ - var match; - if (typeof string == 'string' && - (match = string.match(/^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/))){ - var date = new Date(0); - date.setUTCFullYear(match[1], match[2] - 1, match[3]); - date.setUTCHours(match[4], match[5], match[6], 0); - return date; - } - return string; + var date = new Date(string); + return isNaN(date.getTime()) ? string : date; } }; |
