From 4b5d438ee722dc66e67ac24d285e990e4bd186ad Mon Sep 17 00:00:00 2001 From: Spencer Flagg Date: Tue, 30 Jan 2024 23:51:14 +0100 Subject: [PATCH] added calendar prev/next --- src/routes/calendar/+page.svelte | 357 ++++++++++++++++++------------- 1 file changed, 210 insertions(+), 147 deletions(-) diff --git a/src/routes/calendar/+page.svelte b/src/routes/calendar/+page.svelte index 761541a..6ef4c9b 100644 --- a/src/routes/calendar/+page.svelte +++ b/src/routes/calendar/+page.svelte @@ -1,164 +1,227 @@ - - - -
-
- -
- - - {#each daysOfWeek as day (day)} -
{day}
- {/each} - - - {#each hours as hour (hour)} -
{formatHour(hour)}
- {#each daysOfWeek as _, dayIndex} -
- {#each actions as action (action.id)} - {#if getDayOfWeek(action.timestamp) === dayIndex && getHourOfDay(action.timestamp) === hour} -
- {#if action.type == 'awake'} - - {:else if action.type == 'asleep'} - - {:else if action.type == 'food'} - - {:else if action.type == 'diaper'} - - {:else if action.type == 'poop'} - - {/if} - - {formatTime(action.timestamp)} -
- {/if} - {/each} -
- {/each} - {/each} -
-
- \ No newline at end of file + // Generate hours for the grid + const hours = Array.from({ length: 24 }, (_, i) => i); + + // Function to format hour in HH:mm format + const formatHour = (hour: number) => { + return `${hour.toString().padStart(2, '0')}:00`; + }; + + // function formatTime(date: Date): string { + // const hours = date.getHours().toString().padStart(2, '0'); + // const minutes = date.getMinutes().toString().padStart(2, '0'); + // return `${hours}:${minutes}`; + // } + + function formatTime(dateString: string): string { + const date = new Date(dateString); + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + return `${hours}:${minutes}`; + } + + // Function to check if it's the current week + function isCurrentWeek() { + const today = new Date(); + const startOfTodayWeek = new Date( + today.getFullYear(), + today.getMonth(), + today.getDate() - today.getDay() + ); + + return ( + currentWeekStart.getFullYear() === startOfTodayWeek.getFullYear() && + currentWeekStart.getMonth() === startOfTodayWeek.getMonth() && + currentWeekStart.getDate() === startOfTodayWeek.getDate() + ); + } + + // Function to check if it's the oldest data week + function isOldestWeek() { + return currentWeekStart <= oldestDataDate; + } + + + + + + + + + +
+
+ +
+ + + {#each daysOfWeek as day (day)} +
{day}
+ {/each} + + + {#each hours as hour (hour)} +
{formatHour(hour)}
+ + {#each daysOfWeek as _, dayIndex} +
+ {#each actions as action (action.id)} + {#if getDayOfWeek(action.timestamp) === dayIndex && getHourOfDay(action.timestamp) === hour} +
+ {#if action.type == 'awake'} + + {:else if action.type == 'asleep'} + + {:else if action.type == 'food'} + + {:else if action.type == 'diaper'} + + {:else if action.type == 'poop'} + + {/if} + + {formatTime(action.timestamp)} +
+ {/if} + {/each} +
+ {/each} + {/each} +
+
+ +