mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: support timezoneOffset for date from scope, #401
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as chai from 'chai'
|
||||
import t, { timezoneOffset } from '../../../src/util/strftime'
|
||||
import t from '../../../src/util/strftime'
|
||||
import { DateWithTimezone } from '../../stub/date-with-timezone'
|
||||
const expect = chai.expect
|
||||
|
||||
describe('util/strftime', function () {
|
||||
@@ -118,18 +119,14 @@ describe('util/strftime', function () {
|
||||
})
|
||||
|
||||
describe('Time zone', () => {
|
||||
afterEach(() => {
|
||||
(timezoneOffset as any) = (new Date()).getTimezoneOffset()
|
||||
})
|
||||
it('should format %z as time zone', function () {
|
||||
const now = new Date('2016-01-04 13:15:23');
|
||||
|
||||
(timezoneOffset as any) = -480 // suppose we're in +8:00
|
||||
// suppose we're in +8:00
|
||||
const now = new DateWithTimezone('2016-01-04 13:15:23', -480)
|
||||
expect(t(now, '%z')).to.equal('+0800')
|
||||
})
|
||||
it('should format %z as negative time zone', function () {
|
||||
const date = new Date('2016-01-04T13:15:23.000Z');
|
||||
(timezoneOffset as any) = 480 // suppose we're in -8:00
|
||||
// suppose we're in -8:00
|
||||
const date = new DateWithTimezone('2016-01-04T13:15:23.000Z', 480)
|
||||
expect(t(date, '%z')).to.equal('-0800')
|
||||
})
|
||||
})
|
||||
@@ -210,8 +207,8 @@ describe('util/strftime', function () {
|
||||
expect(t(now, '%#P')).to.equal('PM')
|
||||
})
|
||||
it('should support : flag', () => {
|
||||
const date = new Date('2016-01-04T13:15:23.000Z');
|
||||
(timezoneOffset as any) = -480 // suppose we're in +8:00
|
||||
// suppose we're in +8:00
|
||||
const date = new DateWithTimezone('2016-01-04T13:15:23.000Z', -480)
|
||||
expect(t(date, '%:z')).to.equal('+08:00')
|
||||
expect(t(date, '%z')).to.equal('+0800')
|
||||
})
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TimezoneDate } from '../../../src/util/timezone-date'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('TimezoneDate', () => {
|
||||
it('should respect timezone set to 00:00', () => {
|
||||
const date = new TimezoneDate('2021-10-06T14:26:00.000+08:00', 0)
|
||||
expect(date.getTimezoneOffset()).to.equal(0)
|
||||
expect(date.getHours()).to.equal(6)
|
||||
expect(date.getMinutes()).to.equal(26)
|
||||
})
|
||||
it('should respect timezone set to -06:00', () => {
|
||||
const date = new TimezoneDate('2021-10-06T14:26:00.000+08:00', -360)
|
||||
expect(date.getTimezoneOffset()).to.equal(-360)
|
||||
expect(date.getMinutes()).to.equal(26)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user