Skip to content

Commit 8ed304c

Browse files
authored
Merge pull request #73 from cortex-reply/fix-holidays-2
Fix holidays 2
2 parents 87be370 + dbc9e8f commit 8ed304c

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/components/Holidays/CalendarView.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ const mockHolidays: Holiday[] = [
8181
export const Default: Story = {
8282
render: () => {
8383
const [currentDate, setCurrentDate] = useState(new Date(2025, 0, 1)) // January 2025
84-
const correctedCurrentDate = TimeUtil.toUtcMidnight(currentDate)
8584

85+
const correctedCurrentDate = TimeUtil.toUtcMidnight(currentDate)
8686
return (
8787
<CalendarView
8888
currentDate={correctedCurrentDate}

src/components/Holidays/CalendarView.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ export function CalendarView({ currentDate, setCurrentDate, holidays }: Calendar
3636
(new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + 6) % 7
3737

3838
const days = Array.from({ length: 42 }, (_, i) => {
39-
const day = new Date(currentDate.getFullYear(), currentDate.getMonth(), i - firstDayOfMonth + 1)
39+
const day = new Date(
40+
currentDate.getFullYear(),
41+
currentDate.getMonth(),
42+
i - firstDayOfMonth + 1,
43+
currentDate.getHours(),
44+
)
45+
const filteredHolidays = holidays.filter(
46+
(h) =>
47+
TimeUtil.toUtcMidnight(new Date(h.startDate)) <= day &&
48+
TimeUtil.toUtcMidnight(new Date(h.endDate)) >= day,
49+
)
4050
return {
4151
date: day,
4252
isCurrentMonth: day.getMonth() === currentDate.getMonth(),
4353
isToday: day.toDateString() === new Date().toDateString(),
44-
holidays: holidays.filter((h) => new Date(h.startDate) <= day && new Date(h.endDate) >= day),
54+
holidays: filteredHolidays,
4555
}
4656
})
4757

0 commit comments

Comments
 (0)