MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / createDateParser

Function createDateParser

web/static/bower_components/angular/angular.js:21762–21810  ·  view source on GitHub ↗
(regexp, mapping)

Source from the content-addressed store, hash-verified

21760}
21761
21762function createDateParser(regexp, mapping) {
21763 return function(iso, date) {
21764 var parts, map;
21765
21766 if (isDate(iso)) {
21767 return iso;
21768 }
21769
21770 if (isString(iso)) {
21771 // When a date is JSON'ified to wraps itself inside of an extra
21772 // set of double quotes. This makes the date parsing code unable
21773 // to match the date string and parse it as a date.
21774 if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') {
21775 iso = iso.substring(1, iso.length - 1);
21776 }
21777 if (ISO_DATE_REGEXP.test(iso)) {
21778 return new Date(iso);
21779 }
21780 regexp.lastIndex = 0;
21781 parts = regexp.exec(iso);
21782
21783 if (parts) {
21784 parts.shift();
21785 if (date) {
21786 map = {
21787 yyyy: date.getFullYear(),
21788 MM: date.getMonth() + 1,
21789 dd: date.getDate(),
21790 HH: date.getHours(),
21791 mm: date.getMinutes(),
21792 ss: date.getSeconds(),
21793 sss: date.getMilliseconds() / 1000
21794 };
21795 } else {
21796 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
21797 }
21798
21799 forEach(parts, function(part, index) {
21800 if (index < mapping.length) {
21801 map[mapping[index]] = +part;
21802 }
21803 });
21804 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
21805 }
21806 }
21807
21808 return NaN;
21809 };
21810}
21811
21812function createDateInputType(type, regexp, parseDate, format) {
21813 return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) {

Callers 1

angular.jsFile · 0.85

Calls 3

isDateFunction · 0.85
isStringFunction · 0.85
forEachFunction · 0.85

Tested by

no test coverage detected