mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-29 15:15:23 -07:00
robust date filter
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ var filters = {
|
|||||||
'ceil': v => Math.ceil(v),
|
'ceil': v => Math.ceil(v),
|
||||||
'date': (v, arg) => {
|
'date': (v, arg) => {
|
||||||
if (v === 'now') v = new Date();
|
if (v === 'now') v = new Date();
|
||||||
return strftime(v, arg);
|
return v instanceof Date ? strftime(v, arg) : '';
|
||||||
},
|
},
|
||||||
'default': (v, arg) => v || arg,
|
'default': (v, arg) => v || arg,
|
||||||
'divided_by': (v, arg) => Math.floor(v / arg),
|
'divided_by': (v, arg) => Math.floor(v / arg),
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ describe('filters', function() {
|
|||||||
it('should create a new Date when given "now"', function() {
|
it('should create a new Date when given "now"', function() {
|
||||||
return test('{{ "now" | date: "%Y"}}', (new Date).getFullYear().toString());
|
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() {
|
describe('default', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user