Fix off by one date error
This commit is contained in:
@@ -27,9 +27,13 @@
|
|||||||
let currentYear = $state(parseInt(year));
|
let currentYear = $state(parseInt(year));
|
||||||
let currentMonth = $state(parseInt(month));
|
let currentMonth = $state(parseInt(month));
|
||||||
|
|
||||||
|
function toISODate(year: number, month: number, date: number) {
|
||||||
|
return `${year}-${String(month + 1).padStart(2, '0')}-${String(date).padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
function getEntryForDay(year: number, month: number, date: number) {
|
function getEntryForDay(year: number, month: number, date: number) {
|
||||||
if (!entries) return undefined;
|
if (!entries) return undefined;
|
||||||
const dateStr = new Date(year, month, date).toISOString().split("T")[0];
|
const dateStr = toISODate(year, month, date);
|
||||||
return entries.find((e) => e.date.split("T")[0] === dateStr);
|
return entries.find((e) => e.date.split("T")[0] === dateStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +48,7 @@
|
|||||||
date: date.getDate(),
|
date: date.getDate(),
|
||||||
month: date.getMonth(),
|
month: date.getMonth(),
|
||||||
year: date.getFullYear(),
|
year: date.getFullYear(),
|
||||||
iso: date.toISOString().split('T')[0],
|
iso: toISODate(date.getFullYear(), date.getMonth(), date.getDate()),
|
||||||
dayName: headers[date.getDay() === 0 ? 6 : date.getDay() - 1],
|
dayName: headers[date.getDay() === 0 ? 6 : date.getDay() - 1],
|
||||||
isCurrentMonth,
|
isCurrentMonth,
|
||||||
isToday: date.toDateString() === today.toDateString(),
|
isToday: date.toDateString() === today.toDateString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user