This commit is contained in:
marlon-erler
2026-09-26 23:32:12 +02:00
parent 5a647da2de
commit ce9f6d89f0
3 changed files with 34 additions and 48 deletions
+4 -35
View File
@@ -5,6 +5,7 @@ import { TaskFileContent } from "./boardsAndTasksModel";
import StorageModel from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel";
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
import {isoToMonthString, padZero} from "../Utility/utility";
export default class CalendarModel {
readonly storageModel: StorageModel;
@@ -34,7 +35,7 @@ export default class CalendarModel {
readonly storeTaskReference = (taskFileContent: TaskFileContent): void => {
if (taskFileContent.date == undefined) return;
const monthString: string = CalendarModel.isoToMonthString(
const monthString: string = isoToMonthString(
taskFileContent.date,
);
@@ -102,8 +103,8 @@ export default class CalendarModel {
};
for (let i = 0; i < daysInMonth; i++) {
const paddedDate: string = CalendarModel.padZero(
(i + 1).toString(),
const paddedDate: string = padZero(
(i + 1).toString(), 2
);
grid.days[paddedDate] = defaultValueCreator();
}
@@ -121,38 +122,6 @@ export default class CalendarModel {
this.settingsModel = settingsModel;
this.fileModel = fileModel;
}
// utility
static isoToMonthString = (dateISOString: string): string => {
const [year, month, _] = dateISOString.split("-");
return CalendarModel.getMonthString(year, month);
};
static isoToDateString = (dateISOString: string): string => {
const [year, month, date, _] = dateISOString.split("-");
const paddedDate = CalendarModel.padZero(date ?? "");
return paddedDate;
};
static getMonthString = (year: string = "", month: string = ""): string => {
const paddedYear: string = year.padStart(4, "0");
const paddedMonth: string = CalendarModel.padZero(month);
return `${paddedYear}-${paddedMonth}`;
};
static getISODateString = (
year: string,
month: string,
date: string,
): string => {
const monthString: string = CalendarModel.getMonthString(year, month);
const paddedDate: string = CalendarModel.padZero(date);
return `${monthString}-${paddedDate}`;
};
static padZero = (input: string): string => {
return input.padStart(2, "0");
};
}
export enum CalendarModelSubPaths {
+22 -5
View File
@@ -20,19 +20,36 @@ export function createTimestamp(): string {
return new Date().toISOString();
}
export function isoToDateString (dateISOString: string): string {
const [year, month, date] = dateISOString.split("-");
const paddedDate = padZero(date ?? "", 2);
return paddedDate;
};
export function isoToMonthString (dateISOString: string): string {
const [year, month, _] = dateISOString.split("-");
return formatMonthStringFromParts(year, month);
};
export function formatISO(date: Date): string {
return formatISOFromParts(date.getFullYear(), date.getMonth()+1, date.getDate())
}
export function formatISOFromParts(year: number, month: number, date: number): string {
export function formatISOFromParts(year: number|string, month: number|string, date: number|string): string {
return [year, month, date]
.map((x, i) => i == 0 ? x : CalendarModel.padZero(x.toString()))
.map((x, i) => i == 0 ? x : padZero(x.toString(), 2))
.join("-");
}
export function formatMonthStringFromParts (year: string = "", month: string = ""): string {
const paddedYear: string = padZero(year, 4);
const paddedMonth: string = padZero(month, 2);
return `${paddedYear}-${paddedMonth}`;
};
export function formatTime(date: Date): string {
return [date.getHours(), date.getMinutes()]
.map(x => CalendarModel.padZero(x.toString()))
.map(x => padZero(x.toString(), 2))
.join(":");
}
@@ -224,7 +241,7 @@ export function parseValidObject<T>(string: string, reference: T): T | null {
parsed,
reference,
);
if (doesMatchReference == false) return null;
if (doesMatchReference == false) return null;
return parsed;
}