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

Function createDateParser

lib/test/angular/1.4.3/angular.js:21540–21588  ·  view source on GitHub ↗
(regexp, mapping)

Source from the content-addressed store, hash-verified

21538}
21539
21540function createDateParser(regexp, mapping) {
21541 return function(iso, date) {
21542 var parts, map;
21543
21544 if (isDate(iso)) {
21545 return iso;
21546 }
21547
21548 if (isString(iso)) {
21549 // When a date is JSON'ified to wraps itself inside of an extra
21550 // set of double quotes. This makes the date parsing code unable
21551 // to match the date string and parse it as a date.
21552 if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') {
21553 iso = iso.substring(1, iso.length - 1);
21554 }
21555 if (ISO_DATE_REGEXP.test(iso)) {
21556 return new Date(iso);
21557 }
21558 regexp.lastIndex = 0;
21559 parts = regexp.exec(iso);
21560
21561 if (parts) {
21562 parts.shift();
21563 if (date) {
21564 map = {
21565 yyyy: date.getFullYear(),
21566 MM: date.getMonth() + 1,
21567 dd: date.getDate(),
21568 HH: date.getHours(),
21569 mm: date.getMinutes(),
21570 ss: date.getSeconds(),
21571 sss: date.getMilliseconds() / 1000
21572 };
21573 } else {
21574 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
21575 }
21576
21577 forEach(parts, function(part, index) {
21578 if (index < mapping.length) {
21579 map[mapping[index]] = +part;
21580 }
21581 });
21582 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
21583 }
21584 }
21585
21586 return NaN;
21587 };
21588}
21589
21590function createDateInputType(type, regexp, parseDate, format) {
21591 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