feat: "today" when using date filter, fixes #193

This commit is contained in:
harttle
2020-02-21 01:48:10 +08:00
parent 5cd42f4500
commit 185312dbff
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import { isString, isNumber } from '../../util/underscore'
export default {
'date': (v: string | Date, arg: string) => {
let date = v
if (v === 'now') {
if (v === 'now' || v === 'today') {
date = new Date()
} else if (isNumber(v)) {
date = new Date(v * 1000)
+3
View File
@@ -14,6 +14,9 @@ describe('filters/date', function () {
it('should create a new Date when given "now"', function () {
return test('{{ "now" | date: "%Y"}}', (new Date()).getFullYear().toString())
})
it('should create a new Date when given "today"', function () {
return test('{{ "today" | date: "%Y"}}', (new Date()).getFullYear().toString())
})
it('should parse as Date when given UTC string', function () {
return test('{{ "1991-02-22T00:00:00" | date: "%Y"}}', '1991')
})