Skip to content

Commit 8f5ecd7

Browse files
committed
add assertions around daylight savings time in parseHours
1 parent 8a7f13f commit 8f5ecd7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

source/views/building-hours/lib/__tests__/parse-hours.test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
import {parseHours} from '../parse-hours'
3-
import {dayMoment, hourMoment, moment} from './moment.helper'
3+
import {dayMoment, plainMoment, hourMoment, moment} from './moment.helper'
44

55
it('returns an {open, close} tuple', () => {
66
const now = hourMoment('10:01am')
@@ -52,3 +52,28 @@ describe('handles wierd times', () => {
5252
expect(now.isBetween(open, close)).toBe(true)
5353
})
5454
})
55+
56+
describe('checks a list of schedules to see if any are open', () => {
57+
const schedule = {days: ['Fr', 'Sa'], from: '10:30am', to: '2:00am'}
58+
59+
it('in normal, non-dst situations', () => {
60+
const now = plainMoment('06-24-2017 12:00am', 'MM-DD-YYYY h:mma')
61+
const {open, close} = parseHours(schedule, now)
62+
expect(open.format('HH:mm')).toBe('10:30')
63+
expect(close.format('HH:mm')).toBe('02:00')
64+
})
65+
66+
it('during the spring-forward dst', () => {
67+
const now = plainMoment('03-12-2017 12:00am', 'MM-DD-YYYY h:mma')
68+
const {open, close} = parseHours(schedule, now)
69+
expect(open.format('HH:mm')).toBe('10:30')
70+
expect(close.format('HH:mm')).toBe('01:00')
71+
})
72+
73+
it('during the fall-back dst', () => {
74+
const now = plainMoment('11-4-2017 12:00am', 'MM-DD-YYYY h:mma')
75+
const {open, close} = parseHours(schedule, now)
76+
expect(open.format('HH:mm')).toBe('10:30')
77+
expect(close.format('HH:mm')).toBe('02:00')
78+
})
79+
})

0 commit comments

Comments
 (0)