Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dka36/HolidaysEnum #544

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 10 additions & 32 deletions frontend/src/components/MiniCal/MiniCal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,20 @@ import 'react-datepicker/dist/react-datepicker.css';
import './datepicker_override.css';
import styles from './minical.module.css';
import { useDate } from '../../context/date';
import { holidaysList } from 'util/holidays';

/**startDate is inclusive, endDate is exclusive */
type Holiday = {
startDate: Date;
endDate: Date;
holidayName: string;
const isWeekday = (date: Date) => {
return 0 < date.getDay() && date.getDay() < 6;
};

const holidays: Holiday[] = [
{
startDate: new Date('2024-2-24'),
endDate: new Date('2024-2-28'),
holidayName: 'Febuaray Break',
},
{
startDate: new Date('2024-3-30'),
endDate: new Date('2024-4-8'),
holidayName: 'Spring Break',
},
];

const isHoliday = (date: Date) => {
for (const holiday of holidays) {
if (holiday.startDate <= date && date < holiday.endDate) {
return true;
}
}
return false;
return holidaysList.some(
(holiday) => holiday.startDate <= date && date < holiday.endDate
);
};

const filterDate = (date: Date) => {
return isWeekday(date) && !isHoliday(date);
};

const currentDate = new Date();
Expand Down Expand Up @@ -119,14 +105,6 @@ const MiniCal = () => {
window.scroll(x + 1, y);
window.scroll(x, y);
};
const isWeekday = (date: Date) => {
const day = date.getDay();
return day !== 0 && day !== 6;
};

const filterDate = (date: Date) => {
return isWeekday(date) && !isHoliday(date);
};

return (
<div className={styles.root}>
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/util/holidays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Update this file with API fetch later on, i.e once per AY release or somet
export enum Holidays {
MartinLutherKingJrDay = 'MartinLutherKingJrDay: 2024-01-15 to 2024-01-15',
MemorialDay = 'MemorialDay: 2024-05-27 to 2024-05-27',
Juneteenth = 'Juneteenth: 2024-06-19 to 2024-06-19',
IndependenceDay = 'IndependenceDay: 2024-07-04 to 2024-07-04',
LaborDay = 'LaborDay: 2024-09-02 to 2024-09-02',
Thanksgiving = 'Thanksgiving: 2024-11-28 to 2024-12-2',
WinterBreak = 'WinterBreak: 2024-12-23 to 2025-01-01',
FallBreak = 'FallBreak: 2024-10-12 to 2024-10-13',
IndigenousPeoplesDay = 'IndigenousPeoplesDay: 2024-10-14 to 2024-10-14',
VeteransDay = 'VeteransDay: 2024-11-11 to 2024-11-11',
FebruaryBreak = 'FebruaryBreak: 2025-02-24 to 2025-02-25',
}

type holiday = {
name: string;
startDate: Date;
endDate: Date;
};

function parseHoliday(holiday: Holidays): holiday {
const [name, dates] = holiday.split(': ');
const [start, end] = dates.split(' to ');

return { name, startDate: new Date(start), endDate: new Date(end) };
}

export const holidaysList: holiday[] = Object.values(Holidays).map((h) =>
parseHoliday(h)
);
Loading