(regexp, mapping)
| 26682 | } |
| 26683 | |
| 26684 | function createDateParser(regexp, mapping) { |
| 26685 | return function(iso, previousDate) { |
| 26686 | var parts, map; |
| 26687 | |
| 26688 | if (isDate(iso)) { |
| 26689 | return iso; |
| 26690 | } |
| 26691 | |
| 26692 | if (isString(iso)) { |
| 26693 | // When a date is JSON'ified to wraps itself inside of an extra |
| 26694 | // set of double quotes. This makes the date parsing code unable |
| 26695 | // to match the date string and parse it as a date. |
| 26696 | if (iso.charAt(0) === '"' && iso.charAt(iso.length - 1) === '"') { |
| 26697 | iso = iso.substring(1, iso.length - 1); |
| 26698 | } |
| 26699 | if (ISO_DATE_REGEXP.test(iso)) { |
| 26700 | return new Date(iso); |
| 26701 | } |
| 26702 | regexp.lastIndex = 0; |
| 26703 | parts = regexp.exec(iso); |
| 26704 | |
| 26705 | if (parts) { |
| 26706 | parts.shift(); |
| 26707 | if (previousDate) { |
| 26708 | map = { |
| 26709 | yyyy: previousDate.getFullYear(), |
| 26710 | MM: previousDate.getMonth() + 1, |
| 26711 | dd: previousDate.getDate(), |
| 26712 | HH: previousDate.getHours(), |
| 26713 | mm: previousDate.getMinutes(), |
| 26714 | ss: previousDate.getSeconds(), |
| 26715 | sss: previousDate.getMilliseconds() / 1000 |
| 26716 | }; |
| 26717 | } else { |
| 26718 | map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 }; |
| 26719 | } |
| 26720 | |
| 26721 | forEach(parts, function(part, index) { |
| 26722 | if (index < mapping.length) { |
| 26723 | map[mapping[index]] = +part; |
| 26724 | } |
| 26725 | }); |
| 26726 | |
| 26727 | var date = new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0); |
| 26728 | if (map.yyyy < 100) { |
| 26729 | // In the constructor, 2-digit years map to 1900-1999. |
| 26730 | // Use `setFullYear()` to set the correct year. |
| 26731 | date.setFullYear(map.yyyy); |
| 26732 | } |
| 26733 | |
| 26734 | return date; |
| 26735 | } |
| 26736 | } |
| 26737 | |
| 26738 | return NaN; |
| 26739 | }; |
| 26740 | } |
| 26741 |
no test coverage detected