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