MCPcopy
hub / github.com/angular-ui/ui-router / createDateParser

Function createDateParser

test/angular/1.6/angular.js:25701–25749  ·  view source on GitHub ↗
(regexp, mapping)

Source from the content-addressed store, hash-verified

25699}
25700
25701function createDateParser(regexp, mapping) {
25702 return function(iso, date) {
25703 var parts, map;
25704
25705 if (isDate(iso)) {
25706 return iso;
25707 }
25708
25709 if (isString(iso)) {
25710 // When a date is JSON'ified to wraps itself inside of an extra
25711 // set of double quotes. This makes the date parsing code unable
25712 // to match the date string and parse it as a date.
25713 if (iso.charAt(0) === '"' && iso.charAt(iso.length - 1) === '"') {
25714 iso = iso.substring(1, iso.length - 1);
25715 }
25716 if (ISO_DATE_REGEXP.test(iso)) {
25717 return new Date(iso);
25718 }
25719 regexp.lastIndex = 0;
25720 parts = regexp.exec(iso);
25721
25722 if (parts) {
25723 parts.shift();
25724 if (date) {
25725 map = {
25726 yyyy: date.getFullYear(),
25727 MM: date.getMonth() + 1,
25728 dd: date.getDate(),
25729 HH: date.getHours(),
25730 mm: date.getMinutes(),
25731 ss: date.getSeconds(),
25732 sss: date.getMilliseconds() / 1000
25733 };
25734 } else {
25735 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
25736 }
25737
25738 forEach(parts, function(part, index) {
25739 if (index < mapping.length) {
25740 map[mapping[index]] = +part;
25741 }
25742 });
25743 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
25744 }
25745 }
25746
25747 return NaN;
25748 };
25749}
25750
25751function createDateInputType(type, regexp, parseDate, format) {
25752 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