Skip to content

Commit 02aa563

Browse files
authored
Merge pull request #48 from templerobotics/fix-weekly-dates
Fix weekly dates not showing the correct times
2 parents e8b43a9 + c5092c1 commit 02aa563

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

src/data/EventsDatabase.tsx

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { EventObject } from '../tools/CustomTypes'
22

33
const semesterEnd = '5/31/25'
4-
const descriptionForSDW = `The goal of these classes is to equip you with the skills to model and design on a professional
5-
level, as well as create a common ground for all engineers to work together more efficiently and effectively`
64
const EVENT_INFO: EventObject[] = [
75
{
86
title: 'Weekly Solidworks Workshop',
9-
description: descriptionForSDW,
7+
description: `The goal of these classes is to equip you with the skills to model and design on a professional
8+
level, as well as create a common ground for all engineers to work together more efficiently and effectively`,
109
date: new Date('2025-02-17T17:30:00'),
1110
location: 'The ideas hub (second floor of the engineering building)',
1211
weekly: true,
@@ -43,47 +42,6 @@ const EVENT_INFO: EventObject[] = [
4342
weekly: true,
4443
endDate: new Date(semesterEnd)
4544
}
46-
// {
47-
// title: 'Weekly Programming Meeting',
48-
// description: 'The weekly meeting for the programming sub-team. Take a look at the code for the robot',
49-
// date: new Date('1/1/2025'),
50-
// time: '5:00pm',
51-
// location: 'The ideas hub (second floor of the engineering building)',
52-
// weekly: true,
53-
// endDate: new Date(semesterEnd)
54-
// },
55-
// {
56-
// title: 'Weekly Electrical Meeting',
57-
// description: 'The weekly meeting for the electrical sub-team. Talk about improved batteries, wiring, and more!',
58-
// date: new Date('1/2/2025'),
59-
// time: '6:00',
60-
// location: 'The ideas hub (second floor of the engineering building)',
61-
// weekly: true,
62-
// endDate: new Date(semesterEnd)
63-
// },
64-
// {
65-
// title: 'Weekly Mechanical Meeting',
66-
// description: 'The weekly meeting for the mechanical sub-team. Learn about the design aspects of robot and 3D model parts.',
67-
// date: new Date('1/2/2025'),
68-
// time: '4:00pm',
69-
// location: 'The ideas hub (second floor of the engineering building)',
70-
// weekly: true,
71-
// endDate: new Date(semesterEnd)
72-
// }
73-
// {
74-
// title: 'Engineering Week Showcase',
75-
// description: 'Meet us to see the robot in action and learn about the club!',
76-
// date: new Date(''),
77-
// time: '11:00 AM',
78-
// location: 'SERC Main Lobbby'
79-
// },
80-
// {
81-
// title: 'Temple Ambler Showcase',
82-
// description: 'Meet us to see the robot in action and learn about the club!',
83-
// date: new Date(''),
84-
// time: '9:15 AM',
85-
// location: 'Temple Ambler Widener'
86-
// }
8745
]
8846

8947
export default EVENT_INFO

src/tools/services/getEvents.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ function handleWeeklyEvents(events: EventObject[]): EventObject[] {
2929
return 1
3030
})
3131

32-
// Handle weekly dates
32+
// Handle weekly dates. Set them to be the next occurrence if they are in the past.
3333
events.forEach(event => {
34-
const currentDayForWeek = new Date()
35-
const dayOffset = (7 + event.date.getDay() - currentDayForWeek.getDay()) % 7
36-
const dateComparison = event.date.getTime() - currentDayForWeek.getTime()
37-
if (event.weekly && dateComparison < 0) {
38-
const newDate = currentDayForWeek.getTime() + dayOffset * 24 * 60 * 60 * 1000
39-
event.date = new Date(newDate)
34+
if (event.weekly) {
35+
const currentDate = new Date()
36+
const dayOffset = (7 + event.date.getDay() - currentDate.getDay()) % 7
37+
const nextOccurrence = new Date(currentDate.getTime() + dayOffset * 24 * 60 * 60 * 1000)
38+
if (nextOccurrence < currentDate) {
39+
nextOccurrence.setDate(nextOccurrence.getDate() + 7)
40+
}
4041
}
4142
})
4243

0 commit comments

Comments
 (0)