(regexp, mapping)
| 26617 | } |
| 26618 | |
| 26619 | function createDateParser(regexp, mapping) { |
| 26620 | return function(iso, previousDate) { |
| 26621 | var parts, map; |
| 26622 | |
| 26623 | if (isDate(iso)) { |
| 26624 | return iso; |
| 26625 | } |
| 26626 | |
| 26627 | if (isString(iso)) { |
| 26628 | // When a date is JSON'ified to wraps itself inside of an extra |
| 26629 | // set of double quotes. This makes the date parsing code unable |
| 26630 | // to match the date string and parse it as a date. |
| 26631 | if (iso.charAt(0) === '"' && iso.charAt(iso.length - 1) === '"') { |
| 26632 | iso = iso.substring(1, iso.length - 1); |
| 26633 | } |
| 26634 | if (ISO_DATE_REGEXP.test(iso)) { |
| 26635 | return new Date(iso); |
| 26636 | } |
| 26637 | regexp.lastIndex = 0; |
| 26638 | parts = regexp.exec(iso); |
| 26639 | |
| 26640 | if (parts) { |
| 26641 | parts.shift(); |
| 26642 | if (previousDate) { |
| 26643 | map = { |
| 26644 | yyyy: previousDate.getFullYear(), |
| 26645 | MM: previousDate.getMonth() + 1, |
| 26646 | dd: previousDate.getDate(), |
| 26647 | HH: previousDate.getHours(), |
| 26648 | mm: previousDate.getMinutes(), |
| 26649 | ss: previousDate.getSeconds(), |
| 26650 | sss: previousDate.getMilliseconds() / 1000 |
| 26651 | }; |
| 26652 | } else { |
| 26653 | map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 }; |
| 26654 | } |
| 26655 | |
| 26656 | forEach(parts, function(part, index) { |
| 26657 | if (index < mapping.length) { |
| 26658 | map[mapping[index]] = +part; |
| 26659 | } |
| 26660 | }); |
| 26661 | |
| 26662 | var date = new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0); |
| 26663 | if (map.yyyy < 100) { |
| 26664 | // In the constructor, 2-digit years map to 1900-1999. |
| 26665 | // Use `setFullYear()` to set the correct year. |
| 26666 | date.setFullYear(map.yyyy); |
| 26667 | } |
| 26668 | |
| 26669 | return date; |
| 26670 | } |
| 26671 | } |
| 26672 | |
| 26673 | return NaN; |
| 26674 | }; |
| 26675 | } |
| 26676 |
no test coverage detected