Skip to content

Commit

Permalink
test: add timezone plugin test (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored Jul 31, 2020
1 parent 5860a95 commit f7c71fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default (o, c, d) => {
const utcTs = d.utc(utcString).valueOf()
let asTS = +date
const over = asTS % 1000
asTS -= over >= 0 ? over : 1000 + over
asTS -= over
return (utcTs - asTS) / (60 * 1000)
}
const fixOffset = (localTS, o0, tz) => {
Expand Down
43 changes: 42 additions & 1 deletion test/plugin/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Convert', () => {
})


describe('DST, a time that never existed', () => {
describe('DST, a time that never existed Spring Forward', () => {
// 11 March 2012, 02:00:00 clocks were
// turned forward 1 hour to 11 March 2012, 03:00:00 local
// daylight time instead.
Expand Down Expand Up @@ -132,3 +132,44 @@ describe('DST, a time that never existed', () => {
expect(d.utcOffset()).toBe(m.utcOffset())
})
})

describe('DST, a time that never existed Fall Back', () => {
// In the fall, at the end of DST

it('2012-11-04 00:59:59', () => {
const s = '2012-11-04 00:59:59';
[dayjs, moment].forEach((_) => {
const d = _.tz(s, NY)
expect(d.format()).toBe('2012-11-04T00:59:59-04:00')
expect(d.utcOffset()).toBe(-240)
expect(d.valueOf()).toBe(1352005199000)
})
})
it('2012-11-04 01:00:00', () => {
const s = '2012-11-04 01:00:00';
[dayjs, moment].forEach((_) => {
const d = _.tz(s, NY)
expect(d.format()).toBe('2012-11-04T01:00:00-04:00')
expect(d.utcOffset()).toBe(-240)
expect(d.valueOf()).toBe(1352005200000)
})
})
it('2012-11-04 01:59:59', () => {
const s = '2012-11-04 01:59:59';
[dayjs, moment].forEach((_) => {
const d = _.tz(s, NY)
expect(d.format()).toBe('2012-11-04T01:59:59-04:00')
expect(d.utcOffset()).toBe(-240)
expect(d.valueOf()).toBe(1352008799000)
})
})
it('2012-11-04 02:00:00', () => {
const s = '2012-11-04 02:00:00';
[dayjs, moment].forEach((_) => {
const d = _.tz(s, NY)
expect(d.format()).toBe('2012-11-04T02:00:00-05:00')
expect(d.utcOffset()).toBe(-300)
expect(d.valueOf()).toBe(1352012400000)
})
})
})

0 comments on commit f7c71fc

Please sign in to comment.