($locale)
| 20442 | dateFilter.$inject = ['$locale']; |
| 20443 | |
| 20444 | function dateFilter($locale) { |
| 20445 | var R_ISO8601_STR = |
| 20446 | /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/; |
| 20447 | |
| 20448 | // 1 2 3 4 5 6 7 8 9 10 11 |
| 20449 | function jsonStringToDate(string) { |
| 20450 | var match; |
| 20451 | if (match = string.match(R_ISO8601_STR)) { |
| 20452 | var date = new Date(0), |
| 20453 | tzHour = 0, |
| 20454 | tzMin = 0, |
| 20455 | dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear, |
| 20456 | timeSetter = match[8] ? date.setUTCHours : date.setHours; |
| 20457 | |
| 20458 | if (match[9]) { |
| 20459 | tzHour = toInt(match[9] + match[10]); |
| 20460 | tzMin = toInt(match[9] + match[11]); |
| 20461 | } |
| 20462 | dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); |
| 20463 | var h = toInt(match[4] || 0) - tzHour; |
| 20464 | var m = toInt(match[5] || 0) - tzMin; |
| 20465 | var s = toInt(match[6] || 0); |
| 20466 | var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000); |
| 20467 | timeSetter.call(date, h, m, s, ms); |
| 20468 | return date; |
| 20469 | } |
| 20470 | return string; |
| 20471 | } |
| 20472 | |
| 20473 | return function (date, format, timezone) { |
| 20474 | var text = '', |
| 20475 | parts = [], |
| 20476 | fn, |
| 20477 | match; |
| 20478 | |
| 20479 | format = format || 'mediumDate'; |
| 20480 | format = $locale.DATETIME_FORMATS[format] || format; |
| 20481 | if (isString(date)) { |
| 20482 | date = NUMBER_STRING.test(date) ? toInt(date) : jsonStringToDate(date); |
| 20483 | } |
| 20484 | |
| 20485 | if (isNumber(date)) { |
| 20486 | date = new Date(date); |
| 20487 | } |
| 20488 | |
| 20489 | if (!isDate(date) || !isFinite(date.getTime())) { |
| 20490 | return date; |
| 20491 | } |
| 20492 | |
| 20493 | while (format) { |
| 20494 | match = DATE_FORMATS_SPLIT.exec(format); |
| 20495 | if (match) { |
| 20496 | parts = concat(parts, match, 1); |
| 20497 | format = parts.pop(); |
| 20498 | } else { |
| 20499 | parts.push(format); |
| 20500 | format = null; |
| 20501 | } |
nothing calls this directly
no test coverage detected