Fixed filter.date, so it parses format ending with non-replaced string

Closes #159
This commit is contained in:
Vojta Jina 2011-01-09 13:41:55 +00:00 committed by Igor Minar
parent 0a6cf70deb
commit aab3df7aea
2 changed files with 13 additions and 3 deletions

View file

@ -217,10 +217,16 @@ angularFilter.date = function(date, format) {
var text = date.toLocaleDateString(), fn;
if (format && isString(format)) {
text = '';
var parts = [];
var parts = [], match;
while(format) {
parts = concat(parts, DATE_FORMATS_SPLIT.exec(format), 1);
format = parts.pop();
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];

View file

@ -142,5 +142,9 @@ describe('filter', function() {
expect(filter.date(isoString)).
toEqual(angular.String.toDate(isoString).toLocaleDateString());
});
it('should parse format ending with non-replaced string', function() {
expect(filter.date(morning, 'yy/xxx')).toEqual('10/xxx');
});
});
});