mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix: date from integer, #125
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import strftime from '../../util/strftime'
|
||||
import { isString } from '../../util/underscore'
|
||||
import { isString, isNumber } from '../../util/underscore'
|
||||
|
||||
export default {
|
||||
'date': (v: string | Date, arg: string) => {
|
||||
let date = v
|
||||
if (v === 'now') {
|
||||
date = new Date()
|
||||
} else if (isNumber(v)) {
|
||||
date = new Date(v * 1000)
|
||||
} else if (isString(v)) {
|
||||
date = new Date(v)
|
||||
date = /^\d+$/.test(v) ? new Date(+v * 1000) : new Date(v)
|
||||
}
|
||||
return isValidDate(date) ? strftime(date, arg) : v
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { identifier } from '../../parser/lexical'
|
||||
import TagToken from '../../parser/tag-token'
|
||||
import Context from '../../context/context'
|
||||
import ITagImplOptions from '../../template/tag/itag-impl-options'
|
||||
import { isNumber } from '../../util/underscore'
|
||||
|
||||
export default {
|
||||
parse: function (token: TagToken) {
|
||||
@@ -12,7 +13,7 @@ export default {
|
||||
},
|
||||
render: function (context: Context) {
|
||||
const scope = context.environments
|
||||
if (typeof scope[this.variable] !== 'number') {
|
||||
if (!isNumber(scope[this.variable])) {
|
||||
scope[this.variable] = 0
|
||||
}
|
||||
return --scope[this.variable]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from '../../util/assert'
|
||||
import { identifier } from '../../parser/lexical'
|
||||
import { isNumber } from '../../util/underscore'
|
||||
import ITagImplOptions from '../../template/tag/itag-impl-options'
|
||||
|
||||
export default {
|
||||
@@ -10,7 +11,7 @@ export default {
|
||||
},
|
||||
render: function (context) {
|
||||
const scope = context.environments
|
||||
if (typeof scope[this.variable] !== 'number') {
|
||||
if (!isNumber(scope[this.variable])) {
|
||||
scope[this.variable] = 0
|
||||
}
|
||||
const val = scope[this.variable]
|
||||
|
||||
@@ -37,6 +37,10 @@ export function toValue (value: any): any {
|
||||
return value instanceof Drop ? value.valueOf() : value
|
||||
}
|
||||
|
||||
export function isNumber (value: any): value is number {
|
||||
return typeof value === 'number'
|
||||
}
|
||||
|
||||
export function toLiquid (value: any): any {
|
||||
if (isFunction(value.toLiquid)) return toLiquid(value.toLiquid())
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user