(string)
| 584 | |
| 585 | |
| 586 | function jsonStringToDate(string) { |
| 587 | // The R_ISO8061_STR regex is never going to fit into the 100 char limit! |
| 588 | // eslit-disable-next-line max-len |
| 589 | var R_ISO8061_STR = /^(-?\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; |
| 590 | |
| 591 | var match; |
| 592 | if ((match = string.match(R_ISO8061_STR))) { |
| 593 | var date = new Date(0), |
| 594 | tzHour = 0, |
| 595 | tzMin = 0; |
| 596 | if (match[9]) { |
| 597 | tzHour = toInt(match[9] + match[10]); |
| 598 | tzMin = toInt(match[9] + match[11]); |
| 599 | } |
| 600 | date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); |
| 601 | date.setUTCHours(toInt(match[4] || 0) - tzHour, |
| 602 | toInt(match[5] || 0) - tzMin, |
| 603 | toInt(match[6] || 0), |
| 604 | toInt(match[7] || 0)); |
| 605 | return date; |
| 606 | } |
| 607 | return string; |
| 608 | } |
| 609 | |
| 610 | function toInt(str) { |
| 611 | return parseInt(str, 10); |
no test coverage detected