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

Function createDateParser

test/angular/1.4/angular.js:22311–22359  ·  view source on GitHub ↗
(regexp, mapping)

Source from the content-addressed store, hash-verified

22309}
22310
22311function createDateParser(regexp, mapping) {
22312 return function(iso, date) {
22313 var parts, map;
22314
22315 if (isDate(iso)) {
22316 return iso;
22317 }
22318
22319 if (isString(iso)) {
22320 // When a date is JSON'ified to wraps itself inside of an extra
22321 // set of double quotes. This makes the date parsing code unable
22322 // to match the date string and parse it as a date.
22323 if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') {
22324 iso = iso.substring(1, iso.length - 1);
22325 }
22326 if (ISO_DATE_REGEXP.test(iso)) {
22327 return new Date(iso);
22328 }
22329 regexp.lastIndex = 0;
22330 parts = regexp.exec(iso);
22331
22332 if (parts) {
22333 parts.shift();
22334 if (date) {
22335 map = {
22336 yyyy: date.getFullYear(),
22337 MM: date.getMonth() + 1,
22338 dd: date.getDate(),
22339 HH: date.getHours(),
22340 mm: date.getMinutes(),
22341 ss: date.getSeconds(),
22342 sss: date.getMilliseconds() / 1000
22343 };
22344 } else {
22345 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
22346 }
22347
22348 forEach(parts, function(part, index) {
22349 if (index < mapping.length) {
22350 map[mapping[index]] = +part;
22351 }
22352 });
22353 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
22354 }
22355 }
22356
22357 return NaN;
22358 };
22359}
22360
22361function createDateInputType(type, regexp, parseDate, format) {
22362 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