mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-19 12:59:36 +02:00
Daylight Saving Time fix
This commit is contained in:
parent
f12f9c06e5
commit
0b808401d9
4 changed files with 56 additions and 35 deletions
|
@ -38,7 +38,7 @@
|
||||||
{checklist.name}
|
{checklist.name}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="badge badge-neutral">Checklist</div>
|
<div class="badge badge-primary">Checklist</div>
|
||||||
{#if checklist.items.length > 0}
|
{#if checklist.items.length > 0}
|
||||||
<p>{checklist.items.length} {checklist.items.length > 1 ? 'Items' : 'Item'}</p>
|
<p>{checklist.items.length} {checklist.items.length > 1 ? 'Items' : 'Item'}</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
{note.name}
|
{note.name}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="badge badge-neutral">Note</div>
|
<div class="badge badge-primary">Note</div>
|
||||||
{#if note.links && note.links.length > 0}
|
{#if note.links && note.links.length > 0}
|
||||||
<p>{note.links.length} {note.links.length > 1 ? 'Links' : 'Link'}</p>
|
<p>{note.links.length} {note.links.length > 1 ? 'Links' : 'Link'}</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -57,9 +57,10 @@ export function groupAdventuresByDate(
|
||||||
): Record<string, Adventure[]> {
|
): Record<string, Adventure[]> {
|
||||||
const groupedAdventures: Record<string, Adventure[]> = {};
|
const groupedAdventures: Record<string, Adventure[]> = {};
|
||||||
|
|
||||||
|
// Initialize all days in the range
|
||||||
for (let i = 0; i < numberOfDays; i++) {
|
for (let i = 0; i < numberOfDays; i++) {
|
||||||
const currentDate = new Date(startDate);
|
const currentDate = new Date(startDate);
|
||||||
currentDate.setDate(startDate.getDate() + i);
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
||||||
const dateString = currentDate.toISOString().split('T')[0];
|
const dateString = currentDate.toISOString().split('T')[0];
|
||||||
groupedAdventures[dateString] = [];
|
groupedAdventures[dateString] = [];
|
||||||
}
|
}
|
||||||
|
@ -69,10 +70,14 @@ export function groupAdventuresByDate(
|
||||||
const adventureDate = new Date(adventure.date).toISOString().split('T')[0];
|
const adventureDate = new Date(adventure.date).toISOString().split('T')[0];
|
||||||
if (adventure.end_date) {
|
if (adventure.end_date) {
|
||||||
const endDate = new Date(adventure.end_date).toISOString().split('T')[0];
|
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++) {
|
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];
|
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 (dateString >= adventureDate && dateString <= endDate) {
|
||||||
if (groupedAdventures[dateString]) {
|
if (groupedAdventures[dateString]) {
|
||||||
groupedAdventures[dateString].push(adventure);
|
groupedAdventures[dateString].push(adventure);
|
||||||
|
@ -80,6 +85,7 @@ export function groupAdventuresByDate(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (groupedAdventures[adventureDate]) {
|
} else if (groupedAdventures[adventureDate]) {
|
||||||
|
// If there's no end date, add adventure to the start date only
|
||||||
groupedAdventures[adventureDate].push(adventure);
|
groupedAdventures[adventureDate].push(adventure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,9 +101,10 @@ export function groupTransportationsByDate(
|
||||||
): Record<string, Transportation[]> {
|
): Record<string, Transportation[]> {
|
||||||
const groupedTransportations: Record<string, Transportation[]> = {};
|
const groupedTransportations: Record<string, Transportation[]> = {};
|
||||||
|
|
||||||
|
// Initialize all days in the range
|
||||||
for (let i = 0; i < numberOfDays; i++) {
|
for (let i = 0; i < numberOfDays; i++) {
|
||||||
const currentDate = new Date(startDate);
|
const currentDate = new Date(startDate);
|
||||||
currentDate.setDate(startDate.getDate() + i);
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
||||||
const dateString = currentDate.toISOString().split('T')[0];
|
const dateString = currentDate.toISOString().split('T')[0];
|
||||||
groupedTransportations[dateString] = [];
|
groupedTransportations[dateString] = [];
|
||||||
}
|
}
|
||||||
|
@ -107,10 +114,14 @@ export function groupTransportationsByDate(
|
||||||
const transportationDate = new Date(transportation.date).toISOString().split('T')[0];
|
const transportationDate = new Date(transportation.date).toISOString().split('T')[0];
|
||||||
if (transportation.end_date) {
|
if (transportation.end_date) {
|
||||||
const endDate = new Date(transportation.end_date).toISOString().split('T')[0];
|
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++) {
|
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];
|
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 (dateString >= transportationDate && dateString <= endDate) {
|
||||||
if (groupedTransportations[dateString]) {
|
if (groupedTransportations[dateString]) {
|
||||||
groupedTransportations[dateString].push(transportation);
|
groupedTransportations[dateString].push(transportation);
|
||||||
|
@ -118,6 +129,7 @@ export function groupTransportationsByDate(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (groupedTransportations[transportationDate]) {
|
} else if (groupedTransportations[transportationDate]) {
|
||||||
|
// If there's no end date, add transportation to the start date only
|
||||||
groupedTransportations[transportationDate].push(transportation);
|
groupedTransportations[transportationDate].push(transportation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,9 +145,10 @@ export function groupNotesByDate(
|
||||||
): Record<string, Note[]> {
|
): Record<string, Note[]> {
|
||||||
const groupedNotes: Record<string, Note[]> = {};
|
const groupedNotes: Record<string, Note[]> = {};
|
||||||
|
|
||||||
|
// Initialize all days in the range
|
||||||
for (let i = 0; i < numberOfDays; i++) {
|
for (let i = 0; i < numberOfDays; i++) {
|
||||||
const currentDate = new Date(startDate);
|
const currentDate = new Date(startDate);
|
||||||
currentDate.setDate(startDate.getDate() + i);
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
||||||
const dateString = currentDate.toISOString().split('T')[0];
|
const dateString = currentDate.toISOString().split('T')[0];
|
||||||
groupedNotes[dateString] = [];
|
groupedNotes[dateString] = [];
|
||||||
}
|
}
|
||||||
|
@ -143,6 +156,8 @@ export function groupNotesByDate(
|
||||||
notes.forEach((note) => {
|
notes.forEach((note) => {
|
||||||
if (note.date) {
|
if (note.date) {
|
||||||
const noteDate = new Date(note.date).toISOString().split('T')[0];
|
const noteDate = new Date(note.date).toISOString().split('T')[0];
|
||||||
|
|
||||||
|
// Add note to the appropriate date group if it exists
|
||||||
if (groupedNotes[noteDate]) {
|
if (groupedNotes[noteDate]) {
|
||||||
groupedNotes[noteDate].push(note);
|
groupedNotes[noteDate].push(note);
|
||||||
}
|
}
|
||||||
|
@ -159,18 +174,21 @@ export function groupChecklistsByDate(
|
||||||
): Record<string, Checklist[]> {
|
): Record<string, Checklist[]> {
|
||||||
const groupedChecklists: Record<string, Checklist[]> = {};
|
const groupedChecklists: Record<string, Checklist[]> = {};
|
||||||
|
|
||||||
|
// Initialize all days in the range
|
||||||
for (let i = 0; i < numberOfDays; i++) {
|
for (let i = 0; i < numberOfDays; i++) {
|
||||||
const currentDate = new Date(startDate);
|
const currentDate = new Date(startDate);
|
||||||
currentDate.setDate(startDate.getDate() + i);
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
||||||
const dateString = currentDate.toISOString().split('T')[0];
|
const dateString = currentDate.toISOString().split('T')[0];
|
||||||
groupedChecklists[dateString] = [];
|
groupedChecklists[dateString] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
checklists.forEach((checklist) => {
|
checklists.forEach((checklist) => {
|
||||||
if (checklist.date) {
|
if (checklist.date) {
|
||||||
const noteDate = new Date(checklist.date).toISOString().split('T')[0];
|
const checklistDate = new Date(checklist.date).toISOString().split('T')[0];
|
||||||
if (groupedChecklists[noteDate]) {
|
|
||||||
groupedChecklists[noteDate].push(checklist);
|
// Add checklist to the appropriate date group if it exists
|
||||||
|
if (groupedChecklists[checklistDate]) {
|
||||||
|
groupedChecklists[checklistDate].push(checklist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -487,30 +487,33 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{#each Array(numberOfDays) as _, i}
|
{#each Array(numberOfDays) as _, i}
|
||||||
{@const currentDate = new Date(collection.start_date)}
|
{@const startDate = new Date(collection.start_date)}
|
||||||
{@const temp = currentDate.setDate(currentDate.getDate() + i)}
|
{@const tempDate = new Date(startDate.getTime())}
|
||||||
{@const dateString = currentDate.toISOString().split('T')[0]}
|
<!-- Clone startDate -->
|
||||||
{@const dayAdventures = groupAdventuresByDate(
|
{@const adjustedDate = new Date(tempDate.setUTCDate(tempDate.getUTCDate() + i))}
|
||||||
adventures,
|
<!-- Add i days in UTC -->
|
||||||
new Date(collection.start_date),
|
{@const dateString = adjustedDate.toISOString().split('T')[0]}
|
||||||
numberOfDays
|
|
||||||
)[dateString]}
|
{@const dayAdventures =
|
||||||
{@const dayTransportations = groupTransportationsByDate(
|
groupAdventuresByDate(adventures, new Date(collection.start_date), numberOfDays)[
|
||||||
transportations,
|
dateString
|
||||||
new Date(collection.start_date),
|
] || []}
|
||||||
numberOfDays
|
|
||||||
)[dateString]}
|
{@const dayTransportations =
|
||||||
{@const dayNotes = groupNotesByDate(notes, new Date(collection.start_date), numberOfDays)[
|
groupTransportationsByDate(transportations, new Date(collection.start_date), numberOfDays)[
|
||||||
dateString
|
dateString
|
||||||
]}
|
] || []}
|
||||||
{@const dayChecklists = groupChecklistsByDate(
|
|
||||||
checklists,
|
{@const dayNotes =
|
||||||
new Date(collection.start_date),
|
groupNotesByDate(notes, new Date(collection.start_date), numberOfDays)[dateString] || []}
|
||||||
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">
|
<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>
|
</h2>
|
||||||
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
||||||
{#if dayAdventures.length > 0}
|
{#if dayAdventures.length > 0}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue