Enable dayjs for task dates

This commit is contained in:
2025-01-15 14:19:23 +01:00
parent 3f25000723
commit 12fa9e4e75
4 changed files with 44 additions and 27 deletions

7
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "0.0.1",
"license": "ISC",
"dependencies": {
"dayjs": "^1.11.13",
"peggy": "^4.2.0"
},
"bin": {
@@ -574,6 +575,12 @@
"node": "^12.20.0 || >=14"
}
},
"node_modules/dayjs": {
"version": "1.11.13",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz",
"integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==",
"license": "MIT"
},
"node_modules/dir-glob": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",

View File

@@ -20,6 +20,7 @@
"typescript": "^5.6.3"
},
"dependencies": {
"dayjs": "^1.11.13",
"peggy": "^4.2.0"
}
}

View File

@@ -1,3 +1,4 @@
import dayjs, { Dayjs } from "dayjs";
import { ParsedTask, ParsedTaskDate, ParsedTaskDependency, ParsedTaskMeta } from "../types/grammar/task";
import { Task, TaskPriority } from "../types/task";
@@ -34,31 +35,37 @@ export class LazyTask implements Task {
}[priority] as TaskPriority;
}
get createdDate(): string|undefined {
return this.#dates.find(d => d.type === '')?.date;
get createdDate(): Dayjs|undefined {
return this.#date(this.#dates.find(d => d.type === '')?.date);
}
get startDate(): string|undefined {
return this.#dates.find(d => d.type === '🛫')?.date;
#date(string?: string): Dayjs|undefined {
return string
? dayjs(string)
: undefined;
}
get scheduledDate(): string|undefined {
return this.#dates.find(d => d.type === '')?.date;
get startDate(): Dayjs|undefined {
return this.#date(this.#dates.find(d => d.type === '🛫')?.date);
}
get scheduledDate(): Dayjs|undefined {
return this.#date(this.#dates.find(d => d.type === '⏳')?.date);
}
get dueDate(): string|undefined {
return this.#dates.find(d => d.type === '📅')?.date;
get dueDate(): Dayjs|undefined {
return this.#date(this.#dates.find(d => d.type === '📅')?.date);
}
get completedDate(): string|undefined {
return this.#dates.find(d => d.type === '✅')?.date;
get completedDate(): Dayjs|undefined {
return this.#date(this.#dates.find(d => d.type === '✅')?.date);
}
get cancelledDate(): string|undefined {
return this.#dates.find(d => d.type === '❌')?.date;
get cancelledDate(): Dayjs|undefined {
return this.#date(this.#dates.find(d => d.type === '❌')?.date);
}
get recurrencyRule(): string|undefined {
get recurrenceRule(): string|undefined {
return this.#parsed.meta.find(x => x.feature === 'recurrence')?.rule;
}
@@ -87,13 +94,13 @@ export class LazyTask implements Task {
const items = [
o("priority", this.priority),
o("created", this.createdDate),
o("start", this.startDate),
o("scheduled", this.scheduledDate),
o("due", this.dueDate),
o("completed", this.completedDate),
o("cancelled", this.cancelledDate),
o("recurrence", this.recurrencyRule),
o("created", this.createdDate?.format("YYYY-MM-DD")),
o("start", this.startDate?.format("YYYY-MM-DD")),
o("scheduled", this.scheduledDate?.format("YYYY-MM-DD")),
o("due", this.dueDate?.format("YYYY-MM-DD")),
o("completed", this.completedDate?.format("YYYY-MM-DD")),
o("cancelled", this.cancelledDate?.format("YYYY-MM-DD")),
o("recurrence", this.recurrenceRule),
o("delete", this.onDelete),
o("id", this.id),
o("deps", this.dependsOn.join(",")),

View File

@@ -1,14 +1,16 @@
import { Dayjs } from "dayjs";
export type Task = {
status: string;
label: string;
priority: TaskPriority;
createdDate?: string;
startDate?: string;
scheduledDate?: string;
dueDate?: string;
completedDate?: string;
cancelledDate?: string;
recurrencyRule?: string;
createdDate?: Dayjs;
startDate?: Dayjs;
scheduledDate?: Dayjs;
dueDate?: Dayjs;
completedDate?: Dayjs;
cancelledDate?: Dayjs;
recurrenceRule?: string;
onDelete?: string;
id?: string;
dependsOn?: string[];