| 60 | } |
| 61 | |
| 62 | function isoParse (str) { |
| 63 | // parses simplified iso8601 dates, such as |
| 64 | // yyyy-mm-ddThh:mm:ssZ |
| 65 | // +yyyyyy-mm-ddThh:mm:ss-06:30 |
| 66 | var result; |
| 67 | |
| 68 | // prepare for the worst |
| 69 | result = invalidDate; |
| 70 | |
| 71 | // fast parse |
| 72 | str.replace(isoParseRx, function (a, y, m, d, h, n, s, ms, tzs, tzh, tzm) { |
| 73 | var adjust = 0; |
| 74 | |
| 75 | // Date.UTC handles years between 0 and 100 as 2-digit years, but |
| 76 | // that's not what we want with iso dates. If we move forward |
| 77 | // 400 years -- a full cycle in the Gregorian calendar -- then |
| 78 | // subtract the 400 years (as milliseconds) afterwards, we can avoid |
| 79 | // this problem. (learned of this trick from kriskowal/es5-shim.) |
| 80 | if (y >= 0 && y < 100) { |
| 81 | y = +y + 400; // convert to number |
| 82 | adjust = -126227808e5; // 400 years |
| 83 | } |
| 84 | |
| 85 | result = Date.UTC(y, (m || 1) - 1, d || 1, h || 0, n || 0, s || 0, ms || 0) + adjust; |
| 86 | |
| 87 | tzh = +(tzs + tzh); // convert to signed number |
| 88 | tzm = +(tzs + tzm); // convert to signed number |
| 89 | |
| 90 | if (tzh || tzm) { |
| 91 | result -= (tzh + tzm / 60) * 36e5; |
| 92 | // check if time zone is out of bounds |
| 93 | if (tzh > 23 || tzh < -23 || tzm > 59) result = invalidDate; |
| 94 | // check if time zone pushed us over maximum date value |
| 95 | if (result > maxDate) result = invalidDate; |
| 96 | } |
| 97 | |
| 98 | return ''; // reduces memory used |
| 99 | }); |
| 100 | |
| 101 | return result; |
| 102 | } |
| 103 | |
| 104 | if (!has('date-toisostring')) { |
| 105 | |