mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
fixing more dates
This commit is contained in:
@@ -19,7 +19,7 @@ export const CalendarMonth = ({ month }: { month: CalendarMonthModel }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<h3 className="text-center">
|
||||
<h3 className="text-center text-2xl">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-link"
|
||||
|
||||
@@ -57,7 +57,7 @@ export default function Day({ day, month }: { day: Date; month: number }) {
|
||||
{day.getDate()}
|
||||
<ul className="list-disc ms-4">
|
||||
{todaysAssignments.map((a) => (
|
||||
<li key={a.name}>{a.name}</li>
|
||||
<li key={a.name} >{a.name}</li>
|
||||
))}
|
||||
{todaysQuizzes.map((q) => (
|
||||
<li key={q.name}>{q.name}</li>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
import { ReactNode } from "react";
|
||||
import { CourseContext } from "./courseContext";
|
||||
"use client";
|
||||
import { ReactNode, useState } from "react";
|
||||
import { CourseContext, DraggableItem } from "./courseContext";
|
||||
import { useLocalCourseDetailsQuery } from "@/hooks/localCoursesHooks";
|
||||
|
||||
export default function CourseContextProvider({
|
||||
@@ -11,8 +11,17 @@ export default function CourseContextProvider({
|
||||
localCourseName: string;
|
||||
}) {
|
||||
const { data: course } = useLocalCourseDetailsQuery(localCourseName);
|
||||
const [itemBeingDragged, setItemBeingDragged] = useState<
|
||||
DraggableItem | undefined
|
||||
>();
|
||||
return (
|
||||
<CourseContext.Provider value={{ localCourse: course }}>
|
||||
<CourseContext.Provider
|
||||
value={{
|
||||
localCourse: course,
|
||||
startModuleDrag: (d) => setItemBeingDragged(d),
|
||||
stopModuleDrag: (day) => setItemBeingDragged(undefined),
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</CourseContext.Provider>
|
||||
);
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
"use client";
|
||||
import { IModuleItem } from "@/models/local/IModuleItem";
|
||||
import { LocalCourse } from "@/models/local/localCourse";
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export interface DraggableItem {
|
||||
item: IModuleItem;
|
||||
type: "quiz" | "assignment" | "page";
|
||||
}
|
||||
|
||||
export interface CourseContextInterface {
|
||||
localCourse: LocalCourse;
|
||||
startModuleDrag: (dragging: DraggableItem) => void;
|
||||
stopModuleDrag: (droppedOnDay?: Date) => void;
|
||||
}
|
||||
|
||||
const defaultValue: CourseContextInterface = {
|
||||
@@ -21,6 +29,10 @@ const defaultValue: CourseContextInterface = {
|
||||
},
|
||||
},
|
||||
},
|
||||
startModuleDrag: () => { },
|
||||
stopModuleDrag: function (droppedOnDay?: Date): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
};
|
||||
|
||||
export const CourseContext =
|
||||
|
||||
@@ -76,6 +76,7 @@ const getQuizWithOnlySettings = (settings: string): LocalQuiz => {
|
||||
const rawDueAt = extractLabelValue(settings, "DueAt");
|
||||
const dueAt = verifyDateOrThrow(rawDueAt, "DueAt");
|
||||
|
||||
|
||||
const rawLockAt = extractLabelValue(settings, "LockAt");
|
||||
const lockAt = verifyDateStringOrUndefined(rawLockAt);
|
||||
|
||||
|
||||
@@ -28,4 +28,15 @@ describe("Can properly handle expected date formats", () => {
|
||||
expect(dateObject?.getHours()).toBe(23);
|
||||
expect(dateObject?.getSeconds()).toBe(0);
|
||||
});
|
||||
it("can get correct time from format", () => {
|
||||
const dateString = "8/27/2024 1:00:00 AM";
|
||||
const dateObject = getDateFromString(dateString);
|
||||
|
||||
expect(dateObject?.getDate()).toBe(27);
|
||||
expect(dateObject?.getMonth()).toBe(8 - 1); // 0 based
|
||||
expect(dateObject?.getFullYear()).toBe(2024);
|
||||
expect(dateObject?.getMinutes()).toBe(0);
|
||||
expect(dateObject?.getHours()).toBe(1);
|
||||
expect(dateObject?.getSeconds()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ const _getDateFromAMPM = (
|
||||
datePart: string,
|
||||
timePartWithMeridian: string
|
||||
): Date | undefined => {
|
||||
const [day, month, year] = datePart.split("/").map(Number);
|
||||
const [month, day, year] = datePart.split("/").map(Number);
|
||||
const [timePart, meridian] = timePartWithMeridian.split(" ");
|
||||
const [hours, minutes, seconds] = timePart.split(":").map(Number);
|
||||
|
||||
@@ -56,7 +56,10 @@ export const getDateFromString = (value: string): Date | undefined => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getDateFromStringOrThrow = (value: string, labelForError: string): Date => {
|
||||
export const getDateFromStringOrThrow = (
|
||||
value: string,
|
||||
labelForError: string
|
||||
): Date => {
|
||||
const d = getDateFromString(value);
|
||||
if (!d) throw Error(`Invalid date format for ${labelForError}, ${value}`);
|
||||
return d;
|
||||
@@ -73,9 +76,9 @@ export const verifyDateOrThrow = (
|
||||
value: string,
|
||||
labelForError: string
|
||||
): string => {
|
||||
const myDate = verifyDateStringOrUndefined(value);
|
||||
const myDate = getDateFromString(value);
|
||||
if (!myDate) throw new Error(`Invalid format for ${labelForError}: ${value}`);
|
||||
return myDate;
|
||||
return dateToMarkdownString(myDate);
|
||||
};
|
||||
|
||||
export const dateToMarkdownString = (date: Date) => {
|
||||
|
||||
Reference in New Issue
Block a user