MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / dateFilter

Function dateFilter

test/fixtures/foo.js:15202–15270  ·  view source on GitHub ↗
($locale)

Source from the content-addressed store, hash-verified

15200 */
15201dateFilter.$inject = ['$locale'];
15202function dateFilter($locale) {
15203
15204
15205 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
15206 // 1 2 3 4 5 6 7 8 9 10 11
15207 function jsonStringToDate(string) {
15208 var match;
15209 if (match = string.match(R_ISO8601_STR)) {
15210 var date = new Date(0),
15211 tzHour = 0,
15212 tzMin = 0,
15213 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
15214 timeSetter = match[8] ? date.setUTCHours : date.setHours;
15215
15216 if (match[9]) {
15217 tzHour = int(match[9] + match[10]);
15218 tzMin = int(match[9] + match[11]);
15219 }
15220 dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3]));
15221 var h = int(match[4]||0) - tzHour;
15222 var m = int(match[5]||0) - tzMin;
15223 var s = int(match[6]||0);
15224 var ms = Math.round(parseFloat('0.' + (match[7]||0)) * 1000);
15225 timeSetter.call(date, h, m, s, ms);
15226 return date;
15227 }
15228 return string;
15229 }
15230
15231
15232 return function(date, format) {
15233 var text = '',
15234 parts = [],
15235 fn, match;
15236
15237 format = format || 'mediumDate';
15238 format = $locale.DATETIME_FORMATS[format] || format;
15239 if (isString(date)) {
15240 date = NUMBER_STRING.test(date) ? int(date) : jsonStringToDate(date);
15241 }
15242
15243 if (isNumber(date)) {
15244 date = new Date(date);
15245 }
15246
15247 if (!isDate(date)) {
15248 return date;
15249 }
15250
15251 while(format) {
15252 match = DATE_FORMATS_SPLIT.exec(format);
15253 if (match) {
15254 parts = concat(parts, match, 1);
15255 format = parts.pop();
15256 } else {
15257 parts.push(format);
15258 format = null;
15259 }

Callers

nothing calls this directly

Calls 7

isStringFunction · 0.85
intFunction · 0.85
jsonStringToDateFunction · 0.85
isNumberFunction · 0.85
isDateFunction · 0.85
concatFunction · 0.85
forEachFunction · 0.85

Tested by

no test coverage detected