(regexp, mapping)
| 25842 | } |
| 25843 | |
| 25844 | function createDateParser(regexp, mapping) { |
| 25845 | return function(iso, previousDate) { |
| 25846 | var parts, map; |
| 25847 | |
| 25848 | if (isDate(iso)) { |
| 25849 | return iso; |
| 25850 | } |
| 25851 | |
| 25852 | if (isString(iso)) { |
| 25853 | // When a date is JSON'ified to wraps itself inside of an extra |
| 25854 | // set of double quotes. This makes the date parsing code unable |
| 25855 | // to match the date string and parse it as a date. |
| 25856 | if (iso.charAt(0) === '"' && iso.charAt(iso.length - 1) === '"') { |
| 25857 | iso = iso.substring(1, iso.length - 1); |
| 25858 | } |
| 25859 | if (ISO_DATE_REGEXP.test(iso)) { |
| 25860 | return new Date(iso); |
| 25861 | } |
| 25862 | regexp.lastIndex = 0; |
| 25863 | parts = regexp.exec(iso); |
| 25864 | |
| 25865 | if (parts) { |
| 25866 | parts.shift(); |
| 25867 | if (previousDate) { |
| 25868 | map = { |
| 25869 | yyyy: previousDate.getFullYear(), |
| 25870 | MM: previousDate.getMonth() + 1, |
| 25871 | dd: previousDate.getDate(), |
| 25872 | HH: previousDate.getHours(), |
| 25873 | mm: previousDate.getMinutes(), |
| 25874 | ss: previousDate.getSeconds(), |
| 25875 | sss: previousDate.getMilliseconds() / 1000 |
| 25876 | }; |
| 25877 | } else { |
| 25878 | map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 }; |
| 25879 | } |
| 25880 | |
| 25881 | forEach(parts, function(part, index) { |
| 25882 | if (index < mapping.length) { |
| 25883 | map[mapping[index]] = +part; |
| 25884 | } |
| 25885 | }); |
| 25886 | |
| 25887 | var date = new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0); |
| 25888 | if (map.yyyy < 100) { |
| 25889 | // In the constructor, 2-digit years map to 1900-1999. |
| 25890 | // Use `setFullYear()` to set the correct year. |
| 25891 | date.setFullYear(map.yyyy); |
| 25892 | } |
| 25893 | |
| 25894 | return date; |
| 25895 | } |
| 25896 | } |
| 25897 | |
| 25898 | return NaN; |
| 25899 | }; |
| 25900 | } |
| 25901 |
no test coverage detected