Skip to content

Commit 6384fa9

Browse files
authored
Merge pull request #79 from cortex-reply/fix-holidays-2
Fix holidays 2
2 parents 538a9a1 + 8b4ae87 commit 6384fa9

5 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/components/Holidays/CalendarView.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ const mockHolidays: Holiday[] = [
7676
totalDays: 3,
7777
leaveType: 'Full Day',
7878
},
79+
{
80+
id: '7',
81+
userId: '3',
82+
userName: 'Bob Johnson',
83+
startDate: '2025-10-27T00:00:00.000Z',
84+
endDate: '2025-10-31T00:00:00.000Z',
85+
status: 'approved',
86+
totalDays: 5,
87+
leaveType: 'Full Day',
88+
},
7989
]
8090

8191
export const Default: Story = {

src/components/Holidays/CalendarView.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ interface Holiday {
2727
export function CalendarView({ currentDate, setCurrentDate, holidays }: CalendarViewProps) {
2828
const [selectedDay, setSelectedDay] = useState<Date | null>(null)
2929

30-
console.log(
31-
'holidaysIds',
32-
holidays.map((h) => h.id),
33-
)
34-
3530
const firstDayOfMonth =
3631
(new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + 6) % 7
3732

@@ -45,7 +40,7 @@ export function CalendarView({ currentDate, setCurrentDate, holidays }: Calendar
4540
const filteredHolidays = holidays.filter(
4641
(h) =>
4742
TimeUtil.toUtcMidnight(new Date(h.startDate)) <= day &&
48-
TimeUtil.toUtcMidnight(new Date(h.endDate)) >= day,
43+
TimeUtil.toUtcEndOfDay(new Date(h.endDate)) >= day,
4944
)
5045
return {
5146
date: day,

src/components/Holidays/HolidayGrid.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ const mockHolidays: Holiday[] = [
8686
totalDays: 3,
8787
leaveType: 'Full Day',
8888
},
89+
{
90+
id: '8',
91+
userId: '3',
92+
userName: 'Bob Johnson',
93+
startDate: '2025-10-27T00:00:00.000Z',
94+
endDate: '2025-10-31T00:00:00.000Z',
95+
status: 'approved',
96+
totalDays: 5,
97+
leaveType: 'Full Day',
98+
},
8999
]
90100

91101
const mockEmployees: Employee[] = [

src/components/Holidays/HolidayGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function HolidayGrid({
4444
return {
4545
...holiday,
4646
startDate: TimeUtil.toUtcMidnight(holiday.startDate).toISOString(),
47-
endDate: TimeUtil.toUtcMidnight(holiday.endDate).toISOString(),
47+
endDate: TimeUtil.toUtcEndOfDay(holiday.endDate).toISOString(),
4848
}
4949
})
5050

src/utils/TimeUtil.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
export class TimeUtil {
2-
public static toUtcMidnight(input: string | Date): Date {
3-
const d = new Date(input)
4-
5-
if (d.getUTCHours() === 23 && d.getUTCMinutes() === 0 && d.getUTCSeconds() === 0) {
6-
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + 1))
7-
}
8-
9-
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()))
10-
}
11-
}
2+
public static toUtcMidnight(input: string | Date): Date {
3+
const d = new Date(input)
4+
5+
if (d.getUTCHours() === 23 && d.getUTCMinutes() === 0 && d.getUTCSeconds() === 0) {
6+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + 1))
7+
}
8+
9+
return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()))
10+
}
11+
12+
public static toUtcEndOfDay(input: string | Date): Date {
13+
const d = new Date(input)
14+
// Normalize to start of day UTC first (handles potential 23:00Z inputs)
15+
const startOfDayUtc = this.toUtcMidnight(d)
16+
// End of day is 1 day minus 1 millisecond from midnight
17+
return new Date(startOfDayUtc.getTime() + 24 * 60 * 60 * 1000 - 1)
18+
}
19+
}

0 commit comments

Comments
 (0)