more date fixes

This commit is contained in:
2024-08-27 20:16:33 -06:00
parent 27349af5b9
commit 72f391dcf9
4 changed files with 22 additions and 39 deletions

View File

@@ -1,16 +1,10 @@
"use client"
"use client";
import { useState } from "react";
import { CalendarMonthModel } from "./calendarMonthUtils";
import { DayOfWeek, LocalCourse } from "@/models/local/localCourse";
import { DayOfWeek } from "@/models/local/localCourse";
import Day from "./Day";
export const CalendarMonth = ({
month,
localCourse,
}: {
month: CalendarMonthModel;
localCourse: LocalCourse;
}) => {
export const CalendarMonth = ({ month }: { month: CalendarMonthModel }) => {
const [isCollapsed, setIsCollapsed] = useState(false);
const isInPast =
@@ -40,14 +34,7 @@ export const CalendarMonth = ({
<div id={monthName}>
<div className="grid grid-cols-7 text-center fw-bold">
{weekDaysList.map((day) => (
<div
key={day}
className={
localCourse?.settings.daysOfWeek.includes(day)
? "col"
: "col text-secondary"
}
>
<div key={day} className={""}>
{day}
</div>
))}
@@ -63,4 +50,4 @@ export const CalendarMonth = ({
</div>
</>
);
}
};

View File

@@ -5,27 +5,23 @@ import { getMonthsBetweenDates } from "./calendarMonthUtils";
import { CalendarMonth } from "./CalendarMonth";
export default function CourseCalendar() {
const context = useCourseContext();
const {
localCourse: {
settings: { startDate, endDate },
},
} = useCourseContext();
const startDate = getDateFromStringOrThrow(
context.localCourse.settings.startDate,
const startDateTime = getDateFromStringOrThrow(
startDate,
"course start date"
);
const endDate = getDateFromStringOrThrow(
context.localCourse.settings.endDate,
"course end date"
);
const months = getMonthsBetweenDates(startDate, endDate);
const endDateTime = getDateFromStringOrThrow(endDate, "course end date");
const months = getMonthsBetweenDates(startDateTime, endDateTime);
return (
<>
{months.map((month) => (
<CalendarMonth
key={month.month + "" + month.year}
month={month}
localCourse={context.localCourse}
/>
<CalendarMonth key={month.month + "" + month.year} month={month} />
))}
</>
);

View File

@@ -6,7 +6,9 @@ import { useCourseContext } from "../context/courseContext";
export default function Day({ day, month }: { day: Date; month: number }) {
const context = useCourseContext();
const backgroundClass = day.getMonth() + 1 != month ? "" : "bg-slate-900";
const isInSameMonth = day.getMonth() + 1 != month
const backgroundClass = isInSameMonth ? "" : "bg-slate-900";
const todaysAssignments = context.localCourse.modules
.flatMap((m) => m.assignments)
@@ -15,13 +17,11 @@ export default function Day({ day, month }: { day: Date; month: number }) {
a.dueAt,
"due at for assignment in day"
);
const isSame =
return (
dueDate.getFullYear() === day.getFullYear() &&
dueDate.getMonth() === day.getMonth() &&
dueDate.getDate() === day.getDate();
if (a.name === "Chapter 3") console.log(a.name, dueDate, day, isSame);
return isSame;
dueDate.getDate() === day.getDate()
);
});
const todaysQuizzes = context.localCourse.modules
.flatMap((m) => m.quizzes)

View File

@@ -32,7 +32,7 @@ function createCalendarMonth(year: number, month: number): CalendarMonthModel {
return new Date(year, month - 1, currentDay++);
} else {
currentDay++;
return new Date(year, month, currentDay - daysInMonth);
return new Date(year, month, currentDay - daysInMonth - 1);
}
})
);