-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuseDateInterval.ts
40 lines (37 loc) · 1013 Bytes
/
useDateInterval.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { isWithinInterval } from "date-fns";
type DateInterval = {
tickets:{
startDay: string,
endDay: string,
},
cfp:{
startDay: string,
endDay: string,
},
sponsors:{
startDate: string,
endDate: string,
}
}
export const useDateInterval = (today: Date, edition: DateInterval) => {
const ticketStartDay = new Date(edition.tickets.startDay);
const ticketEndDay = new Date(edition.tickets.endDay);
const CFPStartDay = new Date(edition.cfp.startDay);
const CFPEndDay = new Date(edition.cfp.endDay);
const sponsorStartDay = new Date(edition.sponsors.startDate);
const sponsorEndDay = new Date(edition.sponsors.endDate);
return {
isTicketsDisabled: !isWithinInterval(today, {
start: ticketStartDay,
end: ticketEndDay,
}),
isCfpDisabled: !isWithinInterval(today, {
start: CFPStartDay,
end: CFPEndDay,
}),
isSponsorDisabled: !isWithinInterval(today, {
start: sponsorStartDay,
end: sponsorEndDay,
}),
};
};