robust date filter

This commit is contained in:
harttle
2016-12-08 23:25:38 +08:00
parent deca9677dd
commit 89636736a4
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ var filters = {
'ceil': v => Math.ceil(v),
'date': (v, arg) => {
if (v === 'now') v = new Date();
return strftime(v, arg);
return v instanceof Date ? strftime(v, arg) : '';
},
'default': (v, arg) => v || arg,
'divided_by': (v, arg) => Math.floor(v / arg),
+3
View File
@@ -51,6 +51,9 @@ describe('filters', function() {
it('should create a new Date when given "now"', function() {
return test('{{ "now" | date: "%Y"}}', (new Date).getFullYear().toString());
});
it('should render as empty string when invalid', function() {
return test('{{ "" | date: "%Y"}}', "");
});
});
describe('default', function() {