Skip to content

Commit 4cf9ead

Browse files
committed
show timeago time next time timestamps in directory listing (useful for snapshots)
1 parent ae23158 commit 4cf9ead

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/packages/file-server/btrfs/snapshots.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import {
55
type SnapshotCounts,
66
} from "@cocalc/util/db-schema/projects";
77
import getLogger from "@cocalc/backend/logger";
8+
import { isISODate } from "@cocalc/util/misc";
89

910
export { type SnapshotCounts };
1011

1112
const logger = getLogger("file-server:btrfs:snapshots");
1213

13-
const DATE_REGEXP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
14-
1514
export async function updateRollingSnapshots({
1615
snapshots,
1716
counts,
@@ -32,9 +31,7 @@ export async function updateRollingSnapshots({
3231
});
3332

3433
// get exactly the iso timestamp snapshot names:
35-
const snapshotNames = (await snapshots.readdir()).filter((name) =>
36-
DATE_REGEXP.test(name),
37-
);
34+
const snapshotNames = (await snapshots.readdir()).filter(isISODate);
3835
snapshotNames.sort();
3936
let needNewSnapshot = false;
4037
if (changed) {

src/packages/frontend/project/explorer/file-listing/file-row.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { PublicButton } from "./public-button";
2727
import { generate_click_for } from "./utils";
2828
import { type DirectoryListing } from "@cocalc/frontend/project/explorer/types";
2929
import { FILE_ITEM_OPENED_STYLE } from "@cocalc/frontend/project/page/flyouts/file-list-item";
30+
import { isISODate } from "@cocalc/util/misc";
3031

3132
export const VIEWABLE_FILE_EXT: Readonly<string[]> = [
3233
"md",
@@ -134,6 +135,11 @@ export function FileRow({
134135
{linkTarget}{" "}
135136
</>
136137
)}
138+
{isISODate(name) && (
139+
<span style={{ marginLeft: "30px", color: "#666" }}>
140+
(<TimeAgo date={name} />)
141+
</span>
142+
)}
137143
</a>
138144
);
139145
}

src/packages/util/misc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ export function isSha1(s: string): boolean {
340340
return s.length === 40 && !!s.match(SHA1_REGEXP);
341341
}
342342

343-
344343
// returns the number of keys of an object, e.g., {a:5, b:7, d:'hello'} --> 3
345344
export function len(obj: object | undefined | null): number {
346345
if (obj == null) {
@@ -2780,3 +2779,9 @@ export function k8sMemoryParser(input: string | number): number {
27802779

27812780
return parseInt(input, 10);
27822781
}
2782+
2783+
export const DATE_REGEXP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
2784+
2785+
export function isISODate(s: string): boolean {
2786+
return DATE_REGEXP.test(s);
2787+
}

0 commit comments

Comments
 (0)