1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 07:19:36 +02:00

Daylight Saving Time fix

This commit is contained in:
Sean Morley 2024-09-16 20:02:17 -04:00
parent f12f9c06e5
commit 0b808401d9
4 changed files with 56 additions and 35 deletions

View file

@ -38,7 +38,7 @@
{checklist.name}
</h2>
</div>
<div class="badge badge-neutral">Checklist</div>
<div class="badge badge-primary">Checklist</div>
{#if checklist.items.length > 0}
<p>{checklist.items.length} {checklist.items.length > 1 ? 'Items' : 'Item'}</p>
{/if}

View file

@ -39,7 +39,7 @@
{note.name}
</h2>
</div>
<div class="badge badge-neutral">Note</div>
<div class="badge badge-primary">Note</div>
{#if note.links && note.links.length > 0}
<p>{note.links.length} {note.links.length > 1 ? 'Links' : 'Link'}</p>
{/if}

View file

@ -57,9 +57,10 @@ export function groupAdventuresByDate(
): Record<string, Adventure[]> {
const groupedAdventures: Record<string, Adventure[]> = {};
// Initialize all days in the range
for (let i = 0; i < numberOfDays; i++) {
const currentDate = new Date(startDate);
currentDate.setDate(startDate.getDate() + i);
currentDate.setUTCDate(startDate.getUTCDate() + i);
const dateString = currentDate.toISOString().split('T')[0];
groupedAdventures[dateString] = [];
}
@ -69,10 +70,14 @@ export function groupAdventuresByDate(
const adventureDate = new Date(adventure.date).toISOString().split('T')[0];
if (adventure.end_date) {
const endDate = new Date(adventure.end_date).toISOString().split('T')[0];
const currentDate = new Date(startDate);
// Loop through all days and include adventure if it falls within the range
for (let i = 0; i < numberOfDays; i++) {
currentDate.setDate(startDate.getDate() + i);
const currentDate = new Date(startDate);
currentDate.setUTCDate(startDate.getUTCDate() + i);
const dateString = currentDate.toISOString().split('T')[0];
// Include the current day if it falls within the adventure date range
if (dateString >= adventureDate && dateString <= endDate) {
if (groupedAdventures[dateString]) {
groupedAdventures[dateString].push(adventure);
@ -80,6 +85,7 @@ export function groupAdventuresByDate(
}
}
} else if (groupedAdventures[adventureDate]) {
// If there's no end date, add adventure to the start date only
groupedAdventures[adventureDate].push(adventure);
}
}
@ -95,9 +101,10 @@ export function groupTransportationsByDate(
): Record<string, Transportation[]> {
const groupedTransportations: Record<string, Transportation[]> = {};
// Initialize all days in the range
for (let i = 0; i < numberOfDays; i++) {
const currentDate = new Date(startDate);
currentDate.setDate(startDate.getDate() + i);
currentDate.setUTCDate(startDate.getUTCDate() + i);
const dateString = currentDate.toISOString().split('T')[0];
groupedTransportations[dateString] = [];
}
@ -107,10 +114,14 @@ export function groupTransportationsByDate(
const transportationDate = new Date(transportation.date).toISOString().split('T')[0];
if (transportation.end_date) {
const endDate = new Date(transportation.end_date).toISOString().split('T')[0];
const currentDate = new Date(startDate);
// Loop through all days and include transportation if it falls within the range
for (let i = 0; i < numberOfDays; i++) {
currentDate.setDate(startDate.getDate() + i);
const currentDate = new Date(startDate);
currentDate.setUTCDate(startDate.getUTCDate() + i);
const dateString = currentDate.toISOString().split('T')[0];
// Include the current day if it falls within the transportation date range
if (dateString >= transportationDate && dateString <= endDate) {
if (groupedTransportations[dateString]) {
groupedTransportations[dateString].push(transportation);
@ -118,6 +129,7 @@ export function groupTransportationsByDate(
}
}
} else if (groupedTransportations[transportationDate]) {
// If there's no end date, add transportation to the start date only
groupedTransportations[transportationDate].push(transportation);
}
}
@ -133,9 +145,10 @@ export function groupNotesByDate(
): Record<string, Note[]> {
const groupedNotes: Record<string, Note[]> = {};
// Initialize all days in the range
for (let i = 0; i < numberOfDays; i++) {
const currentDate = new Date(startDate);
currentDate.setDate(startDate.getDate() + i);
currentDate.setUTCDate(startDate.getUTCDate() + i);
const dateString = currentDate.toISOString().split('T')[0];
groupedNotes[dateString] = [];
}
@ -143,6 +156,8 @@ export function groupNotesByDate(
notes.forEach((note) => {
if (note.date) {
const noteDate = new Date(note.date).toISOString().split('T')[0];
// Add note to the appropriate date group if it exists
if (groupedNotes[noteDate]) {
groupedNotes[noteDate].push(note);
}
@ -159,18 +174,21 @@ export function groupChecklistsByDate(
): Record<string, Checklist[]> {
const groupedChecklists: Record<string, Checklist[]> = {};
// Initialize all days in the range
for (let i = 0; i < numberOfDays; i++) {
const currentDate = new Date(startDate);
currentDate.setDate(startDate.getDate() + i);
currentDate.setUTCDate(startDate.getUTCDate() + i);
const dateString = currentDate.toISOString().split('T')[0];
groupedChecklists[dateString] = [];
}
checklists.forEach((checklist) => {
if (checklist.date) {
const noteDate = new Date(checklist.date).toISOString().split('T')[0];
if (groupedChecklists[noteDate]) {
groupedChecklists[noteDate].push(checklist);
const checklistDate = new Date(checklist.date).toISOString().split('T')[0];
// Add checklist to the appropriate date group if it exists
if (groupedChecklists[checklistDate]) {
groupedChecklists[checklistDate].push(checklist);
}
}
});

View file

@ -487,30 +487,33 @@
</p>
{#each Array(numberOfDays) as _, i}
{@const currentDate = new Date(collection.start_date)}
{@const temp = currentDate.setDate(currentDate.getDate() + i)}
{@const dateString = currentDate.toISOString().split('T')[0]}
{@const dayAdventures = groupAdventuresByDate(
adventures,
new Date(collection.start_date),
numberOfDays
)[dateString]}
{@const dayTransportations = groupTransportationsByDate(
transportations,
new Date(collection.start_date),
numberOfDays
)[dateString]}
{@const dayNotes = groupNotesByDate(notes, new Date(collection.start_date), numberOfDays)[
dateString
]}
{@const dayChecklists = groupChecklistsByDate(
checklists,
new Date(collection.start_date),
numberOfDays
)[dateString]}
{@const startDate = new Date(collection.start_date)}
{@const tempDate = new Date(startDate.getTime())}
<!-- Clone startDate -->
{@const adjustedDate = new Date(tempDate.setUTCDate(tempDate.getUTCDate() + i))}
<!-- Add i days in UTC -->
{@const dateString = adjustedDate.toISOString().split('T')[0]}
{@const dayAdventures =
groupAdventuresByDate(adventures, new Date(collection.start_date), numberOfDays)[
dateString
] || []}
{@const dayTransportations =
groupTransportationsByDate(transportations, new Date(collection.start_date), numberOfDays)[
dateString
] || []}
{@const dayNotes =
groupNotesByDate(notes, new Date(collection.start_date), numberOfDays)[dateString] || []}
{@const dayChecklists =
groupChecklistsByDate(checklists, new Date(collection.start_date), numberOfDays)[
dateString
] || []}
<h2 class="text-center font-semibold text-2xl mb-2 mt-4">
Day {i + 1} - {currentDate.toLocaleDateString(undefined, { timeZone: 'UTC' })}
Day {i + 1} - {adjustedDate.toLocaleDateString(undefined, { timeZone: 'UTC' })}
</h2>
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#if dayAdventures.length > 0}