(string)
| 555 | var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; |
| 556 | |
| 557 | function jsonStringToDate(string) { |
| 558 | var match; |
| 559 | if (match = string.match(R_ISO8061_STR)) { |
| 560 | var date = new Date(0), |
| 561 | tzHour = 0, |
| 562 | tzMin = 0; |
| 563 | if (match[9]) { |
| 564 | tzHour = toInt(match[9] + match[10]); |
| 565 | tzMin = toInt(match[9] + match[11]); |
| 566 | } |
| 567 | date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); |
| 568 | date.setUTCHours(toInt(match[4] || 0) - tzHour, |
| 569 | toInt(match[5] || 0) - tzMin, |
| 570 | toInt(match[6] || 0), |
| 571 | toInt(match[7] || 0)); |
| 572 | return date; |
| 573 | } |
| 574 | return string; |
| 575 | } |
| 576 | |
| 577 | function toInt(str) { |
| 578 | return parseInt(str, 10); |
no test coverage detected