(string)
| 732 | |
| 733 | |
| 734 | function jsonStringToDate(string) { |
| 735 | // The R_ISO8061_STR regex is never going to fit into the 100 char limit! |
| 736 | // eslit-disable-next-line max-len |
| 737 | var R_ISO8061_STR = /^(-?\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; |
| 738 | |
| 739 | var match; |
| 740 | if ((match = string.match(R_ISO8061_STR))) { |
| 741 | var date = new Date(0), |
| 742 | tzHour = 0, |
| 743 | tzMin = 0; |
| 744 | if (match[9]) { |
| 745 | tzHour = toInt(match[9] + match[10]); |
| 746 | tzMin = toInt(match[9] + match[11]); |
| 747 | } |
| 748 | date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); |
| 749 | date.setUTCHours(toInt(match[4] || 0) - tzHour, |
| 750 | toInt(match[5] || 0) - tzMin, |
| 751 | toInt(match[6] || 0), |
| 752 | toInt(match[7] || 0)); |
| 753 | return date; |
| 754 | } |
| 755 | return string; |
| 756 | } |
| 757 | |
| 758 | function toInt(str) { |
| 759 | return parseInt(str, 10); |
no test coverage detected