feat: timezoneOffset option to specify output timezone, see #375

This commit is contained in:
Harttle
2021-09-27 01:54:31 +08:00
committed by harttle
parent 91c721e650
commit 6b9f872bcc
8 changed files with 76 additions and 36 deletions
+9 -6
View File
@@ -1,6 +1,5 @@
import * as chai from 'chai'
import t from '../../../src/util/strftime'
import t, { timezoneOffset } from '../../../src/util/strftime'
const expect = chai.expect
describe('util/strftime', function () {
@@ -119,14 +118,18 @@ 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')
now.getTimezoneOffset = () => -480 // suppose we're in +8:00
const now = new Date('2016-01-04 13:15:23');
(timezoneOffset as any) = -480 // suppose we're in +8:00
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')
date.getTimezoneOffset = () => 480 // suppose we're in -8:00
const date = new Date('2016-01-04T13:15:23.000Z');
(timezoneOffset as any) = 480 // suppose we're in -8:00
expect(t(date, '%z')).to.equal('-0800')
})
})