diff --git a/src/document.ts b/src/document.ts index 47a25d1..8ae4f82 100644 --- a/src/document.ts +++ b/src/document.ts @@ -276,9 +276,20 @@ export class List { return this.data.note || ""; } - /** Date of last change */ - public get lastModifiedAt(): Date { - return this.#companion.getRealTimestamp(this.data.lastModified); + /** Date of creation, or undefined if not available */ + public get createdAt(): Date | undefined { + if (this.data.created !== undefined) { + return this.#companion.getRealTimestamp(this.data.created); + } + return undefined; + } + + /** Date of last change, or undefined if not available */ + public get lastModifiedAt(): Date | undefined { + if (this.data.lastModified !== undefined) { + return this.#companion.getRealTimestamp(this.data.lastModified); + } + return undefined; } /** Date of completion, or undefined if not completed */ @@ -413,7 +424,7 @@ export class List { this.itemIds.splice(priority, 0, newId); - const parentid = this.id === "home" ? ROOT : this.id; + const parentid = this.id === ROOT ? "None" : this.id; this.#companion.addOperation(this.data.treeId, { type: "create", diff --git a/src/export.ts b/src/export.ts index 4700bb5..4412d5b 100644 --- a/src/export.ts +++ b/src/export.ts @@ -70,6 +70,9 @@ export function toJson(list: List): any { name: list.name, note: list.note, isCompleted: list.isCompleted, + createdAt: list.createdAt?.toISOString(), + lastModifiedAt: list.lastModifiedAt?.toISOString(), + completedAt: list.completedAt?.toISOString(), items: list.items.map((sublist) => toJson(sublist)), }; } diff --git a/src/schema.ts b/src/schema.ts index 32fc923..92a80aa 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -61,6 +61,7 @@ export const TreeDataSchema = z.object({ prnt: z.string().or(z.null()), pr: z.number(), cp: z.number().optional(), + ct: z.number().optional(), lm: z.number(), metadata: z.object({ mirror: z.object({ @@ -76,6 +77,7 @@ export const TreeDataSchema = z.object({ parentId: i.prnt !== null ? i.prnt : ROOT, priority: i.pr, completed: i.cp, + created: i.ct, lastModified: i.lm, originalId: i.metadata?.mirror?.originalId, isMirrorRoot: i.metadata?.mirror?.isMirrorRoot === true,