Skip to content

Commit bb86f65

Browse files
authored
Merge pull request #97 from cortex-reply/fix-timezone-holiday-issue
fix: further fix for timezone issue
2 parents 4951448 + 379edd8 commit bb86f65

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/components/Holidays/RequestLeave.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ export function RequestLeave({ remainingDays, submitLeaveRequest }: RequestLeave
5050
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0))
5151
}
5252

53+
// Format date using UTC values to avoid hydration mismatch between server/client timezones
54+
const formatDateUTC = (date: Date) => {
55+
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
56+
const day = date.getUTCDate()
57+
const month = months[date.getUTCMonth()]
58+
const year = date.getUTCFullYear()
59+
const suffix = day === 1 || day === 21 || day === 31 ? 'st' : day === 2 || day === 22 ? 'nd' : day === 3 || day === 23 ? 'rd' : 'th'
60+
return `${month} ${day}${suffix}, ${year}`
61+
}
62+
5363
const [startDate, setStartDate] = useState<Date | undefined>(undefined)
5464
const [endDate, setEndDate] = useState<Date | undefined>(undefined)
5565

@@ -142,7 +152,7 @@ export function RequestLeave({ remainingDays, submitLeaveRequest }: RequestLeave
142152
)}
143153
>
144154
<CalendarIcon className="mr-2 h-4 w-4" />
145-
{startDate ? format(startDate, 'PPP') : <span>Pick a date</span>}
155+
{startDate ? formatDateUTC(startDate) : <span>Pick a date</span>}
146156
</Button>
147157
</PopoverTrigger>
148158
<PopoverContent className="w-auto p-0" align="start">
@@ -175,7 +185,7 @@ export function RequestLeave({ remainingDays, submitLeaveRequest }: RequestLeave
175185
)}
176186
>
177187
<CalendarIcon className="mr-2 h-4 w-4" />
178-
{endDate ? format(endDate, 'PPP') : <span>Pick a date</span>}
188+
{endDate ? formatDateUTC(endDate) : <span>Pick a date</span>}
179189
</Button>
180190
</PopoverTrigger>
181191
<PopoverContent className="w-auto p-0" align="start">

0 commit comments

Comments
 (0)