MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / dateFilter

Function dateFilter

code/songhop/www/lib/angular/angular.js:17146–17218  ·  view source on GitHub ↗
($locale)

Source from the content-addressed store, hash-verified

17144 */
17145dateFilter.$inject = ['$locale'];
17146function dateFilter($locale) {
17147
17148
17149 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
17150 // 1 2 3 4 5 6 7 8 9 10 11
17151 function jsonStringToDate(string) {
17152 var match;
17153 if (match = string.match(R_ISO8601_STR)) {
17154 var date = new Date(0),
17155 tzHour = 0,
17156 tzMin = 0,
17157 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
17158 timeSetter = match[8] ? date.setUTCHours : date.setHours;
17159
17160 if (match[9]) {
17161 tzHour = int(match[9] + match[10]);
17162 tzMin = int(match[9] + match[11]);
17163 }
17164 dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3]));
17165 var h = int(match[4] || 0) - tzHour;
17166 var m = int(match[5] || 0) - tzMin;
17167 var s = int(match[6] || 0);
17168 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
17169 timeSetter.call(date, h, m, s, ms);
17170 return date;
17171 }
17172 return string;
17173 }
17174
17175
17176 return function(date, format, timezone) {
17177 var text = '',
17178 parts = [],
17179 fn, match;
17180
17181 format = format || 'mediumDate';
17182 format = $locale.DATETIME_FORMATS[format] || format;
17183 if (isString(date)) {
17184 date = NUMBER_STRING.test(date) ? int(date) : jsonStringToDate(date);
17185 }
17186
17187 if (isNumber(date)) {
17188 date = new Date(date);
17189 }
17190
17191 if (!isDate(date)) {
17192 return date;
17193 }
17194
17195 while (format) {
17196 match = DATE_FORMATS_SPLIT.exec(format);
17197 if (match) {
17198 parts = concat(parts, match, 1);
17199 format = parts.pop();
17200 } else {
17201 parts.push(format);
17202 format = null;
17203 }

Callers

nothing calls this directly

Calls 8

execMethod · 0.80
isStringFunction · 0.70
intFunction · 0.70
jsonStringToDateFunction · 0.70
isNumberFunction · 0.70
isDateFunction · 0.70
concatFunction · 0.70
forEachFunction · 0.70

Tested by

no test coverage detected