Skip to content

Commit 155f56b

Browse files
authored
Merge pull request #1239 from StoDevX/fix-dst-hours
Fix DST hour checks
2 parents 108561a + 8f5ecd7 commit 155f56b

File tree

4 files changed

+86
-29
lines changed

4 files changed

+86
-29
lines changed

source/views/building-hours/lib/__tests__/__snapshots__/get-detailed-building-status.test.js.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`checks a list of schedules to see if any are open 1`] = `
4+
Array [
5+
Object {
6+
"isActive": true,
7+
"label": "Hours",
8+
"status": "10:30 AM — 2:00 AM",
9+
},
10+
]
11+
`;
12+
313
exports[`handles multiple internal schedules for the same timeframe 1`] = `
414
Array [
515
Object {
@@ -35,6 +45,26 @@ Array [
3545
]
3646
`;
3747

48+
exports[`returns a list of [isOpen, scheduleName, verboseStatus] tuples 1`] = `
49+
Array [
50+
Object {
51+
"isActive": true,
52+
"label": "Hours",
53+
"status": "10:30 AM — 2:00 AM",
54+
},
55+
]
56+
`;
57+
58+
exports[`returns false if none are available for this day 1`] = `
59+
Array [
60+
Object {
61+
"isActive": false,
62+
"label": "Hours",
63+
"status": "Closed today",
64+
},
65+
]
66+
`;
67+
3868
exports[`returns false if none are open 1`] = `
3969
Array [
4070
Object {

source/views/building-hours/lib/__tests__/get-detailed-building-status.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @flow
22
import {getDetailedBuildingStatus} from '../get-detailed-status'
3-
import {dayMoment} from './moment.helper'
3+
import {plainMoment} from './moment.helper'
44

5-
xit('returns a list of [isOpen, scheduleName, verboseStatus] tuples', () => {
6-
let m = dayMoment('Fri 1:00pm')
5+
it('returns a list of [isOpen, scheduleName, verboseStatus] tuples', () => {
6+
let m = plainMoment('06-23-2017 1:00pm', 'MM-DD-YYYY h:mma')
77
let building = {
88
name: 'building',
99
category: '???',
@@ -31,8 +31,8 @@ xit('returns a list of [isOpen, scheduleName, verboseStatus] tuples', () => {
3131
expect(actual).toMatchSnapshot()
3232
})
3333

34-
xit('checks a list of schedules to see if any are open', () => {
35-
let m = dayMoment('Fri 1:00pm')
34+
it('checks a list of schedules to see if any are open', () => {
35+
let m = plainMoment('06-23-2017 1:00pm', 'MM-DD-YYYY h:mma')
3636
let building = {
3737
name: 'building',
3838
category: '???',
@@ -56,7 +56,7 @@ xit('checks a list of schedules to see if any are open', () => {
5656
})
5757

5858
it('handles multiple internal schedules for the same timeframe', () => {
59-
let m = dayMoment('Mon 1:00pm')
59+
let m = plainMoment('06-19-2017 1:00pm', 'MM-DD-YYYY h:mma')
6060
let building = {
6161
name: 'building',
6262
category: '???',
@@ -80,7 +80,7 @@ it('handles multiple internal schedules for the same timeframe', () => {
8080
})
8181

8282
it('handles multiple named schedules for the same timeframe', () => {
83-
let m = dayMoment('Mon 1:00pm')
83+
let m = plainMoment('06-19-2017 1:00pm', 'MM-DD-YYYY h:mma')
8484
let building = {
8585
name: 'building',
8686
category: '???',
@@ -108,8 +108,8 @@ it('handles multiple named schedules for the same timeframe', () => {
108108
expect(actual[2].isActive).toBe(true)
109109
})
110110

111-
xit('returns false if none are available for this day', () => {
112-
let m = dayMoment('Sun 1:00pm')
111+
it('returns false if none are available for this day', () => {
112+
let m = plainMoment('06-18-2017 1:00pm', 'MM-DD-YYYY h:mma')
113113
let building = {
114114
name: 'building',
115115
category: '???',
@@ -132,7 +132,7 @@ xit('returns false if none are available for this day', () => {
132132
})
133133

134134
it('returns false if none are open', () => {
135-
let m = dayMoment('Mon 3:00pm')
135+
let m = plainMoment('06-19-2017 3:00pm', 'MM-DD-YYYY h:mma')
136136
let building = {
137137
name: 'building',
138138
category: '???',

source/views/building-hours/lib/__tests__/moment.helper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ export const dayMoment = (time: string, format: ?string = 'ddd h:mma') =>
66
moment.tz(time, format, false, 'America/Winnipeg')
77
export const hourMoment = (time: string) =>
88
moment.tz(time, 'h:mma', false, 'America/Winnipeg')
9+
export const plainMoment = (time: string, format: string) =>
10+
moment.tz(time, format, false, 'America/Winnipeg')
Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,79 @@
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', () => {
6-
let now = hourMoment('10:01am')
7-
let input = {days: [], from: '10:00am', to: '4:00pm'}
8-
let actual = parseHours(input, now)
6+
const now = hourMoment('10:01am')
7+
const input = {days: [], from: '10:00am', to: '4:00pm'}
8+
const actual = parseHours(input, now)
99

1010
expect(actual).toBeDefined()
1111
expect(actual.open).toBeDefined()
1212
expect(actual.close).toBeDefined()
1313
})
1414

1515
it('returns a Moment for .open', () => {
16-
let now = hourMoment('10:01am')
17-
let input = {days: [], from: '10:00am', to: '4:00pm'}
18-
let {open} = parseHours(input, now)
16+
const now = hourMoment('10:01am')
17+
const input = {days: [], from: '10:00am', to: '4:00pm'}
18+
const {open} = parseHours(input, now)
1919
expect(moment.isMoment(open)).toBe(true)
2020
})
2121

2222
it('returns a Moment for .close', () => {
23-
let now = hourMoment('10:01am')
24-
let input = {days: [], from: '10:00am', to: '4:00pm'}
25-
let {close} = parseHours(input, now)
23+
const now = hourMoment('10:01am')
24+
const input = {days: [], from: '10:00am', to: '4:00pm'}
25+
const {close} = parseHours(input, now)
2626
expect(moment.isMoment(close)).toBe(true)
2727
})
2828

2929
it('will add a day to the close time with nextDay:true', () => {
30-
let now = hourMoment('10:01am')
31-
let input = {days: [], from: '10:00am', to: '2:00am'}
32-
let {open, close} = parseHours(input, now)
30+
const now = hourMoment('10:01am')
31+
const input = {days: [], from: '10:00am', to: '2:00am'}
32+
const {open, close} = parseHours(input, now)
3333

3434
expect(close.isAfter(open)).toBe(true)
3535
expect(close.isAfter(now)).toBe(true)
3636
})
3737

3838
describe('handles wierd times', () => {
3939
it('handles Friday at 4:30pm', () => {
40-
let now = dayMoment('Fri 4:30pm')
41-
let input = {days: [], from: '10:00am', to: '2:00am'}
42-
let {open, close} = parseHours(input, now)
40+
const now = dayMoment('Fri 4:30pm')
41+
const input = {days: [], from: '10:00am', to: '2:00am'}
42+
const {open, close} = parseHours(input, now)
4343

4444
expect(now.isBetween(open, close)).toBe(true)
4545
})
4646

4747
it('handles Saturday at 1:30am', () => {
48-
let now = dayMoment('Sat 1:30am')
49-
let input = {days: [], from: '10:00am', to: '2:00am'}
50-
let {open, close} = parseHours(input, now)
48+
const now = dayMoment('Sat 1:30am')
49+
const input = {days: [], from: '10:00am', to: '2:00am'}
50+
const {open, close} = parseHours(input, now)
5151

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)