MCPcopy Index your code
hub / github.com/angular-ui/ui-router / createDateParser

Function createDateParser

test/angular/1.5/angular.js:24575–24623  ·  view source on GitHub ↗
(regexp, mapping)

Source from the content-addressed store, hash-verified

24573}
24574
24575function createDateParser(regexp, mapping) {
24576 return function(iso, date) {
24577 var parts, map;
24578
24579 if (isDate(iso)) {
24580 return iso;
24581 }
24582
24583 if (isString(iso)) {
24584 // When a date is JSON'ified to wraps itself inside of an extra
24585 // set of double quotes. This makes the date parsing code unable
24586 // to match the date string and parse it as a date.
24587 if (iso.charAt(0) === '"' && iso.charAt(iso.length - 1) === '"') {
24588 iso = iso.substring(1, iso.length - 1);
24589 }
24590 if (ISO_DATE_REGEXP.test(iso)) {
24591 return new Date(iso);
24592 }
24593 regexp.lastIndex = 0;
24594 parts = regexp.exec(iso);
24595
24596 if (parts) {
24597 parts.shift();
24598 if (date) {
24599 map = {
24600 yyyy: date.getFullYear(),
24601 MM: date.getMonth() + 1,
24602 dd: date.getDate(),
24603 HH: date.getHours(),
24604 mm: date.getMinutes(),
24605 ss: date.getSeconds(),
24606 sss: date.getMilliseconds() / 1000
24607 };
24608 } else {
24609 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
24610 }
24611
24612 forEach(parts, function(part, index) {
24613 if (index < mapping.length) {
24614 map[mapping[index]] = +part;
24615 }
24616 });
24617 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
24618 }
24619 }
24620
24621 return NaN;
24622 };
24623}
24624
24625function createDateInputType(type, regexp, parseDate, format) {
24626 return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) {

Callers 1

angular.jsFile · 0.70

Calls 3

isDateFunction · 0.70
isStringFunction · 0.70
forEachFunction · 0.70

Tested by

no test coverage detected