Skip to content

Commit b436017

Browse files
favilajquense
authored andcommitted
fix: TimeGrid display on DST change days when min is after the transition (jquense#1303)
If the "min" start time of a calender view is after the moment of transition in or out of Daylight Saving time (2am), the values in the time grid can be off by an hour. This is because the extra +/- 60 minutes was not included in minutesFromMidnight. Fixes jquense#1098, jquense#1273, possibly others
1 parent 239f0a3 commit b436017

File tree

2 files changed

+103
-30
lines changed

2 files changed

+103
-30
lines changed

src/utils/TimeSlots.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const getKey = (min, max, step, slots) =>
1111
export function getSlotMetrics({ min: start, max: end, step, timeslots }) {
1212
const key = getKey(start, end, step, timeslots)
1313

14+
// if the start is on a DST-changing day but *after* the moment of DST
15+
// transition we need to add those extra minutes to our minutesFromMidnight
16+
const daystart = dates.startOf(start, 'day')
17+
const daystartdstoffset = getDstOffset(daystart, start)
1418
const totalMin =
1519
1 + dates.diff(start, end, 'minutes') + getDstOffset(start, end)
16-
const minutesFromMidnight = dates.diff(
17-
dates.startOf(start, 'day'),
18-
start,
19-
'minutes'
20-
)
21-
20+
const minutesFromMidnight =
21+
dates.diff(daystart, start, 'minutes') + daystartdstoffset
2222
const numGroups = Math.ceil(totalMin / (step * timeslots))
2323
const numSlots = numGroups * timeslots
2424

stories/Durations.js

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,100 @@ import moment from 'moment'
44

55
import { Calendar, DragableCalendar } from './helpers'
66

7-
storiesOf('Event Durations').add('Daylight savings', () => {
8-
return (
9-
<DragableCalendar
10-
defaultView={Calendar.Views.DAY}
11-
min={moment('12:00am', 'h:mma').toDate()}
12-
max={moment('11:59pm', 'h:mma').toDate()}
13-
events={[
14-
{
15-
title: 'on DST',
16-
start: new Date(2017, 2, 12, 1),
17-
end: new Date(2017, 2, 12, 2, 30),
18-
allDay: false,
19-
},
20-
{
21-
title: 'crosses DST',
22-
start: new Date(2017, 2, 12, 1),
23-
end: new Date(2017, 2, 12, 6, 30),
24-
allDay: false,
25-
},
26-
]}
27-
defaultDate={new Date(2017, 2, 12)}
28-
/>
29-
)
30-
})
7+
storiesOf('Event Durations')
8+
.add('Daylight savings starts', () => {
9+
return (
10+
<DragableCalendar
11+
defaultView={Calendar.Views.DAY}
12+
min={moment('12:00am', 'h:mma').toDate()}
13+
max={moment('11:59pm', 'h:mma').toDate()}
14+
events={[
15+
{
16+
title: 'on DST',
17+
start: new Date(2017, 2, 12, 1),
18+
end: new Date(2017, 2, 12, 2, 30),
19+
allDay: false,
20+
},
21+
{
22+
title: 'crosses DST',
23+
start: new Date(2017, 2, 12, 1),
24+
end: new Date(2017, 2, 12, 6, 30),
25+
allDay: false,
26+
},
27+
{
28+
title: 'After DST',
29+
start: new Date(2017, 2, 12, 7),
30+
end: new Date(2017, 2, 12, 9, 30),
31+
allDay: false,
32+
},
33+
]}
34+
defaultDate={new Date(2017, 2, 12)}
35+
/>
36+
)
37+
})
38+
.add('Daylight savings ends', () => {
39+
return (
40+
<DragableCalendar
41+
defaultView={Calendar.Views.DAY}
42+
min={moment('12:00am', 'h:mma').toDate()}
43+
max={moment('11:59pm', 'h:mma').toDate()}
44+
events={[
45+
{
46+
title: 'on DST',
47+
start: new Date(2017, 10, 5, 1),
48+
end: new Date(2017, 10, 5, 3, 30),
49+
allDay: false,
50+
},
51+
{
52+
title: 'crosses DST',
53+
start: new Date(2017, 10, 5, 1),
54+
end: new Date(2017, 10, 5, 6, 30),
55+
allDay: false,
56+
},
57+
{
58+
title: 'After DST',
59+
start: new Date(2017, 10, 5, 7),
60+
end: new Date(2017, 10, 5, 7, 45),
61+
allDay: false,
62+
},
63+
]}
64+
defaultDate={new Date(2017, 10, 5)}
65+
/>
66+
)
67+
})
68+
.add('Daylight savings starts, after 2am', () => {
69+
return (
70+
<DragableCalendar
71+
defaultView={Calendar.Views.DAY}
72+
min={moment('3:00am', 'h:mma').toDate()}
73+
max={moment('11:59pm', 'h:mma').toDate()}
74+
events={[
75+
{
76+
title: 'After DST',
77+
start: new Date(2017, 2, 12, 7),
78+
end: new Date(2017, 2, 12, 9, 30),
79+
allDay: false,
80+
},
81+
]}
82+
defaultDate={new Date(2017, 2, 12)}
83+
/>
84+
)
85+
})
86+
.add('Daylight savings ends, after 2am', () => {
87+
return (
88+
<DragableCalendar
89+
defaultView={Calendar.Views.DAY}
90+
min={moment('3:00am', 'h:mma').toDate()}
91+
max={moment('11:59pm', 'h:mma').toDate()}
92+
events={[
93+
{
94+
title: 'After DST',
95+
start: new Date(2017, 10, 5, 7),
96+
end: new Date(2017, 10, 5, 9, 30),
97+
allDay: false,
98+
},
99+
]}
100+
defaultDate={new Date(2017, 10, 5)}
101+
/>
102+
)
103+
})

0 commit comments

Comments
 (0)