fix: throws when using preserveTimezones on Node.js, fixes #431

This commit is contained in:
Harttle
2021-12-07 22:43:47 +08:00
committed by Harttle
parent 80c2280ee6
commit e2ef236f68
6 changed files with 117 additions and 51 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
import { Liquid } from '../../src/liquid'
import { Liquid } from '../..'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import * as sinon from 'sinon'
@@ -153,4 +153,12 @@ describe('Issues', function () {
expect(exists).to.be.calledOnce
expect(readFile).to.be.calledOnce
})
it('#431 Error when using Date timezoneOffset in 9.28.5', async () => {
const engine = new Liquid({
timezoneOffset: 0,
preserveTimezones: true
})
const tpl = engine.parse('Welcome to {{ now | date: "%Y-%m-%d" }}!')
expect(engine.render(tpl, { now: new Date('2019/02/01') })).to.eventually.equal('Welcome to 2019-02-01')
})
})
+1 -1
View File
@@ -75,7 +75,7 @@ describe('filters/date', function () {
const scope = { date: new Date('1990-12-31T23:00:00Z') }
return test('{{ date | date: "%z"}}', scope, '-0600', opts)
})
it('should ignore this setting when `preserveTimezones` also specified', function () {
it('should work with `preserveTimezones`', function () {
const opts: LiquidOptions = { timezoneOffset: 600, preserveTimezones: true }
return test('{{ "1990-12-31T23:00:00+02:30" | date: "%Y-%m-%dT%H:%M:%S"}}', '1990-12-31T23:00:00', undefined, opts)
})