MCPcopy Create free account
hub / github.com/apache/cloudstack / dateFilter

Function dateFilter

tools/ngui/static/js/lib/angular.js:10117–10181  ·  view source on GitHub ↗
($locale)

Source from the content-addressed store, hash-verified

10115 */
10116dateFilter.$inject = ['$locale'];
10117function dateFilter($locale) {
10118
10119
10120 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
10121 function jsonStringToDate(string){
10122 var match;
10123 if (match = string.match(R_ISO8601_STR)) {
10124 var date = new Date(0),
10125 tzHour = 0,
10126 tzMin = 0;
10127 if (match[9]) {
10128 tzHour = int(match[9] + match[10]);
10129 tzMin = int(match[9] + match[11]);
10130 }
10131 date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3]));
10132 date.setUTCHours(int(match[4]||0) - tzHour, int(match[5]||0) - tzMin, int(match[6]||0), int(match[7]||0));
10133 return date;
10134 }
10135 return string;
10136 }
10137
10138
10139 return function(date, format) {
10140 var text = '',
10141 parts = [],
10142 fn, match;
10143
10144 format = format || 'mediumDate';
10145 format = $locale.DATETIME_FORMATS[format] || format;
10146 if (isString(date)) {
10147 if (NUMBER_STRING.test(date)) {
10148 date = int(date);
10149 } else {
10150 date = jsonStringToDate(date);
10151 }
10152 }
10153
10154 if (isNumber(date)) {
10155 date = new Date(date);
10156 }
10157
10158 if (!isDate(date)) {
10159 return date;
10160 }
10161
10162 while(format) {
10163 match = DATE_FORMATS_SPLIT.exec(format);
10164 if (match) {
10165 parts = concat(parts, match, 1);
10166 format = parts.pop();
10167 } else {
10168 parts.push(format);
10169 format = null;
10170 }
10171 }
10172
10173 forEach(parts, function(value){
10174 fn = DATE_FORMATS[value];

Callers

nothing calls this directly

Calls 9

isStringFunction · 0.85
intFunction · 0.85
jsonStringToDateFunction · 0.85
isNumberFunction · 0.85
isDateFunction · 0.85
concatFunction · 0.85
forEachFunction · 0.85
replaceMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected