Skip to content

Commit d1e1c09

Browse files
committed
feat: Add $atime intrinsic to Files
This field will track the last access time of the file in the stored metadata. It's added as a part of the `File` interface definition, and implemented for `MarkdownPage`, `Canvas`, and `GenericFile`, as well as their JSON representations.
1 parent 966f228 commit d1e1c09

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

src/index/types/canvas.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class Canvas implements Linkable, File, Linkbearing, Taggable, Indexable,
3434
$types: string[] = Canvas.TYPES;
3535
$typename: string = "Canvas";
3636

37+
$atime?: DateTime;
3738
$ctime: DateTime;
3839
$mtime: DateTime;
3940

@@ -75,6 +76,7 @@ export class Canvas implements Linkable, File, Linkbearing, Taggable, Indexable,
7576
$cards: this.$cards.map((x) => x.json()) as JsonCanvasCard[],
7677
$ctime: this.$ctime.toMillis(),
7778
$mtime: this.$mtime.toMillis(),
79+
$atime: this.$atime?.toMillis(),
7880
$size: this.$size,
7981
$links: this.$links,
8082
$path: this.$path,
@@ -101,6 +103,7 @@ export class Canvas implements Linkable, File, Linkbearing, Taggable, Indexable,
101103
$cards: cards,
102104
$ctime: DateTime.fromMillis(raw.$ctime),
103105
$mtime: DateTime.fromMillis(raw.$mtime),
106+
$atime: raw.$atime ? DateTime.fromMillis(raw.$atime) : undefined,
104107
$size: raw.$size,
105108
$extension: "canvas",
106109
$path: raw.$path,

src/index/types/files.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ export class GenericFile implements File, Indexable, Fieldbearing, Linkable {
1919
$ctime: DateTime;
2020
/** Obsidian-provided date this page was modified. */
2121
$mtime: DateTime;
22+
/** Timestamp of last file access, as determined by inspecting `file-open` workspace events */
23+
$atime?: DateTime;
2224
/** Obsidian-provided size of this page in bytes. */
2325
$size: number;
2426
/** The extension of the file. */
2527
$extension: string;
2628

27-
public constructor(path: string, ctime: DateTime, mtime: DateTime, size: number) {
29+
public constructor(path: string, ctime: DateTime, mtime: DateTime, size: number, atime?: DateTime) {
2830
this.$path = path;
2931
this.$ctime = ctime;
3032
this.$mtime = mtime;
33+
this.$atime = atime;
3134
this.$size = size;
3235

3336
const lastDot = path.lastIndexOf(".");

src/index/types/indexable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface File extends Linkable {
4444
$ctime: DateTime;
4545
/** Obsidian-provided date this page was modified. */
4646
$mtime: DateTime;
47+
/** Timestamp of last file access, as determined by inspecting `file-open` workspace events */
48+
$atime?: DateTime;
4749
/** Obsidian-provided size of this page in bytes. */
4850
$size: number;
4951
/** The extension of the file. */

src/index/types/json/canvas.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export interface JsonCanvas {
3636
$ctime: number;
3737
/** Last modified time as a UNIX epoch time in milliseconds. */
3838
$mtime: number;
39+
/** Last access time as a UNIX epoch time in milliseconds. */
40+
$atime?: number;
3941
/** All tags in the canvas. */
4042
$tags: string[];
4143
/** All links in the canvas. */

src/index/types/json/markdown.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface JsonMarkdownPage {
3333
$ctime: number;
3434
/** Obsidian-provided date this page was modified. */
3535
$mtime: number;
36+
/** Timestamp of last file access, as determined by inspecting `file-open` workspace events */
37+
$atime?: number;
3638
/** The extension; for markdown files, almost always '.md'. */
3739
$extension: string;
3840
/** Obsidian-provided size of this page in bytes. */

src/index/types/markdown.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export class MarkdownPage implements File, Linkbearing, Taggable, Indexable, Fie
6161
$ctime: DateTime;
6262
/** Obsidian-provided date this page was modified. */
6363
$mtime: DateTime;
64+
/** Timestamp of last file access, as determined by inspecting `file-open` workspace events */
65+
$atime?: DateTime;
6466
/** The extension; for markdown files, almost always '.md'. */
6567
$extension: string;
6668
/** Obsidian-provided size of this page in bytes. */
@@ -89,6 +91,7 @@ export class MarkdownPage implements File, Linkbearing, Taggable, Indexable, Fie
8991
$infields: mapObjectValues(raw.$infields, (field) => normalizeLinks(valueInlineField(field), normalizer)),
9092
$ctime: DateTime.fromMillis(raw.$ctime),
9193
$mtime: DateTime.fromMillis(raw.$mtime),
94+
$atime: raw.$atime ? DateTime.fromMillis(raw.$atime) : undefined,
9295
$extension: raw.$extension,
9396
$size: raw.$size,
9497
$position: raw.$position,
@@ -140,6 +143,7 @@ export class MarkdownPage implements File, Linkbearing, Taggable, Indexable, Fie
140143
$infields: mapObjectValues(this.$infields, jsonInlineField),
141144
$ctime: this.$ctime.toMillis(),
142145
$mtime: this.$mtime.toMillis(),
146+
$atime: this.$atime?.toMillis(),
143147
$extension: this.$extension,
144148
$size: this.$size,
145149
$position: this.$position,

0 commit comments

Comments
 (0)