(string)
| 559 | |
| 560 | |
| 561 | function jsonStringToDate(string) { |
| 562 | // The R_ISO8061_STR regex is never going to fit into the 100 char limit! |
| 563 | // eslit-disable-next-line max-len |
| 564 | var R_ISO8061_STR = /^(-?\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; |
| 565 | |
| 566 | var match; |
| 567 | if ((match = string.match(R_ISO8061_STR))) { |
| 568 | var date = new Date(0), |
| 569 | tzHour = 0, |
| 570 | tzMin = 0; |
| 571 | if (match[9]) { |
| 572 | tzHour = toInt(match[9] + match[10]); |
| 573 | tzMin = toInt(match[9] + match[11]); |
| 574 | } |
| 575 | date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); |
| 576 | date.setUTCHours(toInt(match[4] || 0) - tzHour, |
| 577 | toInt(match[5] || 0) - tzMin, |
| 578 | toInt(match[6] || 0), |
| 579 | toInt(match[7] || 0)); |
| 580 | return date; |
| 581 | } |
| 582 | return string; |
| 583 | } |
| 584 | |
| 585 | function toInt(str) { |
| 586 | return parseInt(str, 10); |
no test coverage detected