Fix double date (#4825)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-02-29 17:52:29 +06:00 committed by GitHub
parent 7224bc625a
commit aa8dd37d79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -33,6 +33,11 @@
$: weekMonday = startFromWeekStart
? getMonday(currentDate, mondayStart)
: new Date(new Date(currentDate).setHours(0, 0, 0, 0))
function getDate (startDate: Date, dayIndex: number, minutes: number): Date {
const date = getDay(startDate, dayIndex)
return new Date(date.setMinutes(date.getMinutes() + minutes))
}
</script>
<Scroller fade={{ multipler: { top: 3, bottom: 0 } }}>
@ -70,7 +75,7 @@
{#each [...Array(displayedDaysCount).keys()] as dayIndex}
<td class="calendar-td cell" style:height={cellHeight}>
{#if $$slots.cell}
<slot name="cell" date={getDay(weekMonday, dayIndex, hourOfDay * 60)} />
<slot name="cell" date={getDate(weekMonday, dayIndex, hourOfDay * 60)} />
{/if}
</td>
{/each}

View File

@ -48,8 +48,8 @@ export function getWeekDayName (weekDay: Date, weekFormat: 'narrow' | 'short' |
}).format(weekDay)
}
export function day (firstDay: Date, offset: number, minutes?: number): Date {
return new Date(firstDay.getTime() + offset * MILLISECONDS_IN_DAY + (minutes ?? 0) * MILLISECONDS_IN_MINUTE)
export function day (firstDay: Date, offset: number): Date {
return new Date(new Date(firstDay).setDate(firstDay.getDate() + offset))
}
export function weekday (firstDay: Date, w: number, d: number): Date {