($locale)
| 18953 | */ |
| 18954 | dateFilter.$inject = ['$locale']; |
| 18955 | function dateFilter($locale) { |
| 18956 | |
| 18957 | |
| 18958 | var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/; |
| 18959 | // 1 2 3 4 5 6 7 8 9 10 11 |
| 18960 | function jsonStringToDate(string) { |
| 18961 | var match; |
| 18962 | if (match = string.match(R_ISO8601_STR)) { |
| 18963 | var date = new Date(0), |
| 18964 | tzHour = 0, |
| 18965 | tzMin = 0, |
| 18966 | dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear, |
| 18967 | timeSetter = match[8] ? date.setUTCHours : date.setHours; |
| 18968 | |
| 18969 | if (match[9]) { |
| 18970 | tzHour = toInt(match[9] + match[10]); |
| 18971 | tzMin = toInt(match[9] + match[11]); |
| 18972 | } |
| 18973 | dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); |
| 18974 | var h = toInt(match[4] || 0) - tzHour; |
| 18975 | var m = toInt(match[5] || 0) - tzMin; |
| 18976 | var s = toInt(match[6] || 0); |
| 18977 | var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000); |
| 18978 | timeSetter.call(date, h, m, s, ms); |
| 18979 | return date; |
| 18980 | } |
| 18981 | return string; |
| 18982 | } |
| 18983 | |
| 18984 | |
| 18985 | return function(date, format, timezone) { |
| 18986 | var text = '', |
| 18987 | parts = [], |
| 18988 | fn, match; |
| 18989 | |
| 18990 | format = format || 'mediumDate'; |
| 18991 | format = $locale.DATETIME_FORMATS[format] || format; |
| 18992 | if (isString(date)) { |
| 18993 | date = NUMBER_STRING.test(date) ? toInt(date) : jsonStringToDate(date); |
| 18994 | } |
| 18995 | |
| 18996 | if (isNumber(date)) { |
| 18997 | date = new Date(date); |
| 18998 | } |
| 18999 | |
| 19000 | if (!isDate(date) || !isFinite(date.getTime())) { |
| 19001 | return date; |
| 19002 | } |
| 19003 | |
| 19004 | while (format) { |
| 19005 | match = DATE_FORMATS_SPLIT.exec(format); |
| 19006 | if (match) { |
| 19007 | parts = concat(parts, match, 1); |
| 19008 | format = parts.pop(); |
| 19009 | } else { |
| 19010 | parts.push(format); |
| 19011 | format = null; |
| 19012 | } |
nothing calls this directly
no test coverage detected