Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TimeGrid display on DST change days when min is after the transition #1303

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/utils/TimeSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const getKey = (min, max, step, slots) =>
export function getSlotMetrics({ min: start, max: end, step, timeslots }) {
const key = getKey(start, end, step, timeslots)

// if the start is on a DST-changing day but *after* the moment of DST
// transition we need to add those extra minutes to our minutesFromMidnight
const daystart = dates.startOf(start, 'day')
const daystartdstoffset = getDstOffset(daystart, start)
const totalMin =
1 + dates.diff(start, end, 'minutes') + getDstOffset(start, end)
const minutesFromMidnight = dates.diff(
dates.startOf(start, 'day'),
start,
'minutes'
)

const minutesFromMidnight =
dates.diff(daystart, start, 'minutes') + daystartdstoffset
const numGroups = Math.ceil(totalMin / (step * timeslots))
const numSlots = numGroups * timeslots

Expand Down
121 changes: 97 additions & 24 deletions stories/Durations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,100 @@ import moment from 'moment'

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

storiesOf('Event Durations').add('Daylight savings', () => {
return (
<DragableCalendar
defaultView={Calendar.Views.DAY}
min={moment('12:00am', 'h:mma').toDate()}
max={moment('11:59pm', 'h:mma').toDate()}
events={[
{
title: 'on DST',
start: new Date(2017, 2, 12, 1),
end: new Date(2017, 2, 12, 2, 30),
allDay: false,
},
{
title: 'crosses DST',
start: new Date(2017, 2, 12, 1),
end: new Date(2017, 2, 12, 6, 30),
allDay: false,
},
]}
defaultDate={new Date(2017, 2, 12)}
/>
)
})
storiesOf('Event Durations')
.add('Daylight savings starts', () => {
return (
<DragableCalendar
defaultView={Calendar.Views.DAY}
min={moment('12:00am', 'h:mma').toDate()}
max={moment('11:59pm', 'h:mma').toDate()}
events={[
{
title: 'on DST',
start: new Date(2017, 2, 12, 1),
end: new Date(2017, 2, 12, 2, 30),
allDay: false,
},
{
title: 'crosses DST',
start: new Date(2017, 2, 12, 1),
end: new Date(2017, 2, 12, 6, 30),
allDay: false,
},
{
title: 'After DST',
start: new Date(2017, 2, 12, 7),
end: new Date(2017, 2, 12, 9, 30),
allDay: false,
},
]}
defaultDate={new Date(2017, 2, 12)}
/>
)
})
.add('Daylight savings ends', () => {
return (
<DragableCalendar
defaultView={Calendar.Views.DAY}
min={moment('12:00am', 'h:mma').toDate()}
max={moment('11:59pm', 'h:mma').toDate()}
events={[
{
title: 'on DST',
start: new Date(2017, 10, 5, 1),
end: new Date(2017, 10, 5, 3, 30),
allDay: false,
},
{
title: 'crosses DST',
start: new Date(2017, 10, 5, 1),
end: new Date(2017, 10, 5, 6, 30),
allDay: false,
},
{
title: 'After DST',
start: new Date(2017, 10, 5, 7),
end: new Date(2017, 10, 5, 7, 45),
allDay: false,
},
]}
defaultDate={new Date(2017, 10, 5)}
/>
)
})
.add('Daylight savings starts, after 2am', () => {
return (
<DragableCalendar
defaultView={Calendar.Views.DAY}
min={moment('3:00am', 'h:mma').toDate()}
max={moment('11:59pm', 'h:mma').toDate()}
events={[
{
title: 'After DST',
start: new Date(2017, 2, 12, 7),
end: new Date(2017, 2, 12, 9, 30),
allDay: false,
},
]}
defaultDate={new Date(2017, 2, 12)}
/>
)
})
.add('Daylight savings ends, after 2am', () => {
return (
<DragableCalendar
defaultView={Calendar.Views.DAY}
min={moment('3:00am', 'h:mma').toDate()}
max={moment('11:59pm', 'h:mma').toDate()}
events={[
{
title: 'After DST',
start: new Date(2017, 10, 5, 7),
end: new Date(2017, 10, 5, 9, 30),
allDay: false,
},
]}
defaultDate={new Date(2017, 10, 5)}
/>
)
})