From c5092c1e44cbd0126e351c87c331b6c17e7faa18 Mon Sep 17 00:00:00 2001 From: Ryan Hodge Date: Tue, 18 Feb 2025 21:37:11 -0500 Subject: [PATCH] Fix weekly dates not showing the correct times --- src/data/EventsDatabase.tsx | 46 ++------------------------------ src/tools/services/getEvents.tsx | 15 ++++++----- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/src/data/EventsDatabase.tsx b/src/data/EventsDatabase.tsx index 3d6a4ef..891f664 100644 --- a/src/data/EventsDatabase.tsx +++ b/src/data/EventsDatabase.tsx @@ -1,12 +1,11 @@ import { EventObject } from '../tools/CustomTypes' const semesterEnd = '5/31/25' -const descriptionForSDW = `The goal of these classes is to equip you with the skills to model and design on a professional -level, as well as create a common ground for all engineers to work together more efficiently and effectively` const EVENT_INFO: EventObject[] = [ { title: 'Weekly Solidworks Workshop', - description: descriptionForSDW, + description: `The goal of these classes is to equip you with the skills to model and design on a professional + level, as well as create a common ground for all engineers to work together more efficiently and effectively`, date: new Date('2025-02-17T17:30:00'), location: 'The ideas hub (second floor of the engineering building)', weekly: true, @@ -43,47 +42,6 @@ const EVENT_INFO: EventObject[] = [ weekly: true, endDate: new Date(semesterEnd) } - // { - // title: 'Weekly Programming Meeting', - // description: 'The weekly meeting for the programming sub-team. Take a look at the code for the robot', - // date: new Date('1/1/2025'), - // time: '5:00pm', - // location: 'The ideas hub (second floor of the engineering building)', - // weekly: true, - // endDate: new Date(semesterEnd) - // }, - // { - // title: 'Weekly Electrical Meeting', - // description: 'The weekly meeting for the electrical sub-team. Talk about improved batteries, wiring, and more!', - // date: new Date('1/2/2025'), - // time: '6:00', - // location: 'The ideas hub (second floor of the engineering building)', - // weekly: true, - // endDate: new Date(semesterEnd) - // }, - // { - // title: 'Weekly Mechanical Meeting', - // description: 'The weekly meeting for the mechanical sub-team. Learn about the design aspects of robot and 3D model parts.', - // date: new Date('1/2/2025'), - // time: '4:00pm', - // location: 'The ideas hub (second floor of the engineering building)', - // weekly: true, - // endDate: new Date(semesterEnd) - // } - // { - // title: 'Engineering Week Showcase', - // description: 'Meet us to see the robot in action and learn about the club!', - // date: new Date(''), - // time: '11:00 AM', - // location: 'SERC Main Lobbby' - // }, - // { - // title: 'Temple Ambler Showcase', - // description: 'Meet us to see the robot in action and learn about the club!', - // date: new Date(''), - // time: '9:15 AM', - // location: 'Temple Ambler Widener' - // } ] export default EVENT_INFO diff --git a/src/tools/services/getEvents.tsx b/src/tools/services/getEvents.tsx index 5534e96..eefd3c1 100644 --- a/src/tools/services/getEvents.tsx +++ b/src/tools/services/getEvents.tsx @@ -29,14 +29,15 @@ function handleWeeklyEvents(events: EventObject[]): EventObject[] { return 1 }) - // Handle weekly dates + // Handle weekly dates. Set them to be the next occurrence if they are in the past. events.forEach(event => { - const currentDayForWeek = new Date() - const dayOffset = (7 + event.date.getDay() - currentDayForWeek.getDay()) % 7 - const dateComparison = event.date.getTime() - currentDayForWeek.getTime() - if (event.weekly && dateComparison < 0) { - const newDate = currentDayForWeek.getTime() + dayOffset * 24 * 60 * 60 * 1000 - event.date = new Date(newDate) + if (event.weekly) { + const currentDate = new Date() + const dayOffset = (7 + event.date.getDay() - currentDate.getDay()) % 7 + const nextOccurrence = new Date(currentDate.getTime() + dayOffset * 24 * 60 * 60 * 1000) + if (nextOccurrence < currentDate) { + nextOccurrence.setDate(nextOccurrence.getDate() + 7) + } } })