MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / createDateParser

Function createDateParser

code/songhop/www/lib/angular/angular.js:19665–19713  ·  view source on GitHub ↗
(regexp, mapping)

Source from the content-addressed store, hash-verified

19663}
19664
19665function createDateParser(regexp, mapping) {
19666 return function(iso, date) {
19667 var parts, map;
19668
19669 if (isDate(iso)) {
19670 return iso;
19671 }
19672
19673 if (isString(iso)) {
19674 // When a date is JSON'ified to wraps itself inside of an extra
19675 // set of double quotes. This makes the date parsing code unable
19676 // to match the date string and parse it as a date.
19677 if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') {
19678 iso = iso.substring(1, iso.length - 1);
19679 }
19680 if (ISO_DATE_REGEXP.test(iso)) {
19681 return new Date(iso);
19682 }
19683 regexp.lastIndex = 0;
19684 parts = regexp.exec(iso);
19685
19686 if (parts) {
19687 parts.shift();
19688 if (date) {
19689 map = {
19690 yyyy: date.getFullYear(),
19691 MM: date.getMonth() + 1,
19692 dd: date.getDate(),
19693 HH: date.getHours(),
19694 mm: date.getMinutes(),
19695 ss: date.getSeconds(),
19696 sss: date.getMilliseconds() / 1000
19697 };
19698 } else {
19699 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
19700 }
19701
19702 forEach(parts, function(part, index) {
19703 if (index < mapping.length) {
19704 map[mapping[index]] = +part;
19705 }
19706 });
19707 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
19708 }
19709 }
19710
19711 return NaN;
19712 };
19713}
19714
19715function createDateInputType(type, regexp, parseDate, format) {
19716 return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) {

Callers 1

angular.jsFile · 0.70

Calls 4

execMethod · 0.80
isDateFunction · 0.70
isStringFunction · 0.70
forEachFunction · 0.70

Tested by

no test coverage detected