aboutsummaryrefslogtreecommitdiffstats
path: root/src/filters.js
diff options
context:
space:
mode:
authorIgor Minar2011-10-18 23:42:36 -0700
committerIgor Minar2011-10-20 16:51:28 -0700
commite175db37c6f52bba4080efeec22a7120a896099e (patch)
tree426cd3adb6b2fddaccc2651734076cb672539476 /src/filters.js
parentf38010d3a2f457a53798212ef72418637dabe189 (diff)
downloadangular.js-e175db37c6f52bba4080efeec22a7120a896099e.tar.bz2
fix(date filter): default to fullDate format
The browser's behave inconsistently, so we should just stick to one format when the format is not specified by the developer Closes #605
Diffstat (limited to 'src/filters.js')
-rw-r--r--src/filters.js42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/filters.js b/src/filters.js
index b2d6f4b7..f9ff418e 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -318,7 +318,7 @@ var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/,
* @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or
* number) or ISO 8601 extended datetime string (yyyy-MM-ddTHH:mm:ss.SSSZ).
* @param {string=} format Formatting rules (see Description). If not specified,
- * Date#toLocaleDateString is used.
+ * `fullDate` is used.
* @returns {string} Formatted string or the input if input is not recognized as date/millis.
*
* @example
@@ -344,7 +344,12 @@ var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/,
</doc:example>
*/
angularFilter.date = function(date, format) {
- var $locale = this.$service('$locale');
+ var $locale = this.$service('$locale'),
+ text = '',
+ parts = [],
+ fn, match;
+
+ format = format || 'fullDate'
format = $locale.DATETIME_FORMATS[format] || format;
if (isString(date)) {
if (NUMBER_STRING.test(date)) {
@@ -362,26 +367,23 @@ angularFilter.date = function(date, format) {
return date;
}
- var text = date.toLocaleDateString(), fn;
- if (format && isString(format)) {
- text = '';
- var parts = [], match;
- while(format) {
- match = DATE_FORMATS_SPLIT.exec(format);
- if (match) {
- parts = concat(parts, match, 1);
- format = parts.pop();
- } else {
- parts.push(format);
- format = null;
- }
+ while(format) {
+ match = DATE_FORMATS_SPLIT.exec(format);
+ if (match) {
+ parts = concat(parts, match, 1);
+ format = parts.pop();
+ } else {
+ parts.push(format);
+ format = null;
}
- forEach(parts, function(value){
- fn = DATE_FORMATS[value];
- text += fn ? fn(date, $locale.DATETIME_FORMATS)
- : value.replace(/(^'|'$)/g, '').replace(/''/g, "'");
- });
}
+
+ forEach(parts, function(value){
+ fn = DATE_FORMATS[value];
+ text += fn ? fn(date, $locale.DATETIME_FORMATS)
+ : value.replace(/(^'|'$)/g, '').replace(/''/g, "'");
+ });
+
return text;
};