Skip to content

Commit d590a1e

Browse files
committed
refactor: abstract functionality in a hook
1 parent 6b1a6ea commit d590a1e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/hooks/useDateInterval.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { isWithinInterval } from "date-fns";
2+
3+
type DateInterval = {
4+
tickets:{
5+
startDay: string,
6+
endDay: string,
7+
},
8+
cfp:{
9+
startDay: string,
10+
endDay: string,
11+
},
12+
sponsors:{
13+
startDate: string,
14+
endDate: string,
15+
}
16+
}
17+
18+
export const useDateInterval = (today: Date, edition: DateInterval) => {
19+
const ticketStartDay = new Date(edition.tickets.startDay);
20+
const ticketEndDay = new Date(edition.tickets.endDay);
21+
const CFPStartDay = new Date(edition.cfp.startDay);
22+
const CFPEndDay = new Date(edition.cfp.endDay);
23+
const sponsorStartDay = new Date(edition.sponsors.startDate);
24+
const sponsorEndDay = new Date(edition.sponsors.endDate);
25+
26+
return {
27+
isTicketsDisabled: !isWithinInterval(today, {
28+
start: ticketStartDay,
29+
end: ticketEndDay,
30+
}),
31+
isCfpDisabled: !isWithinInterval(today, {
32+
start: CFPStartDay,
33+
end: CFPEndDay,
34+
}),
35+
isSponsorDisabled: !isWithinInterval(today, {
36+
start: sponsorStartDay,
37+
end: sponsorEndDay,
38+
}),
39+
};
40+
};

0 commit comments

Comments
 (0)