mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 23:58:31 -06:00
consolodating date logic
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { extractLabelValue } from "../assignmnet/utils/markdownUtils";
|
||||
import { IModuleItem } from "../IModuleItem";
|
||||
import { verifyDateOrThrow } from "../timeUtils";
|
||||
|
||||
export interface LocalCoursePage extends IModuleItem {
|
||||
name: string;
|
||||
@@ -9,9 +10,7 @@ export interface LocalCoursePage extends IModuleItem {
|
||||
|
||||
export const localPageMarkdownUtils = {
|
||||
toMarkdown: (page: LocalCoursePage) => {
|
||||
const printableDueDate = new Date(page.dueAt)
|
||||
.toISOString()
|
||||
.replace("\u202F", " ");
|
||||
const printableDueDate = verifyDateOrThrow(page.dueAt, "page DueDateForOrdering")
|
||||
const settingsMarkdown = `Name: ${page.name}\nDueDateForOrdering: ${printableDueDate}\n---\n`;
|
||||
return settingsMarkdown + page.text;
|
||||
},
|
||||
@@ -20,17 +19,13 @@ export const localPageMarkdownUtils = {
|
||||
const rawSettings = pageMarkdown.split("---")[0];
|
||||
const name = extractLabelValue(rawSettings, "Name");
|
||||
const rawDate = extractLabelValue(rawSettings, "DueDateForOrdering");
|
||||
|
||||
const parsedDate = new Date(rawDate);
|
||||
if (isNaN(parsedDate.getTime())) {
|
||||
throw new Error(`could not parse due date: ${rawDate}`);
|
||||
}
|
||||
const dueAt = verifyDateOrThrow(rawDate, "page DueDateForOrdering");
|
||||
|
||||
const text = pageMarkdown.split("---\n")[1];
|
||||
|
||||
const page: LocalCoursePage = {
|
||||
name,
|
||||
dueAt: parsedDate.toISOString(),
|
||||
dueAt,
|
||||
text,
|
||||
};
|
||||
return page;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
export const getDateFromString = (value: string) => {
|
||||
// may need to check for other formats
|
||||
const validDateRegex =
|
||||
/\d{2}\/\d{2}\/\d{4} [0-2][0-9]|[0-5][0-9]|[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/;
|
||||
/\d{2}\/\d{2}\/\d{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/;
|
||||
if (!validDateRegex.test(value)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user