Fixes #680 all times and dates are now local (to the environment)
parent
6ef9dc8b99
commit
3ac21498f3
|
@ -4,6 +4,7 @@ import { plugPrefix } from "$common/spaces/constants.ts";
|
||||||
import type { AttachmentMeta, FileMeta, PageMeta } from "../plug-api/types.ts";
|
import type { AttachmentMeta, FileMeta, PageMeta } from "../plug-api/types.ts";
|
||||||
import type { EventHook } from "./hooks/event.ts";
|
import type { EventHook } from "./hooks/event.ts";
|
||||||
import { safeRun } from "../lib/async.ts";
|
import { safeRun } from "../lib/async.ts";
|
||||||
|
import { localDateString } from "$lib/dates.ts";
|
||||||
|
|
||||||
const pageWatchInterval = 5000;
|
const pageWatchInterval = 5000;
|
||||||
|
|
||||||
|
@ -195,8 +196,8 @@ export function fileMetaToPageMeta(fileMeta: FileMeta): PageMeta {
|
||||||
ref: name,
|
ref: name,
|
||||||
tag: "page",
|
tag: "page",
|
||||||
name,
|
name,
|
||||||
created: new Date(fileMeta.created).toISOString(),
|
created: localDateString(new Date(fileMeta.created)),
|
||||||
lastModified: new Date(fileMeta.lastModified).toISOString(),
|
lastModified: localDateString(new Date(fileMeta.lastModified)),
|
||||||
} as PageMeta;
|
} as PageMeta;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to convert fileMeta to pageMeta", fileMeta, e);
|
console.error("Failed to convert fileMeta to pageMeta", fileMeta, e);
|
||||||
|
@ -212,8 +213,8 @@ export function fileMetaToAttachmentMeta(
|
||||||
...fileMeta,
|
...fileMeta,
|
||||||
ref: fileMeta.name,
|
ref: fileMeta.name,
|
||||||
tag: "attachment",
|
tag: "attachment",
|
||||||
created: new Date(fileMeta.created).toISOString(),
|
created: localDateString(new Date(fileMeta.created)),
|
||||||
lastModified: new Date(fileMeta.lastModified).toISOString(),
|
lastModified: localDateString(new Date(fileMeta.lastModified)),
|
||||||
} as AttachmentMeta;
|
} as AttachmentMeta;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to convert fileMeta to attachmentMeta", fileMeta, e);
|
console.error("Failed to convert fileMeta to attachmentMeta", fileMeta, e);
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { localDateString } from "$lib/dates.ts";
|
||||||
|
|
||||||
|
Deno.test("Dates", () => {
|
||||||
|
console.log("Local date string", localDateString(new Date()));
|
||||||
|
});
|
25
lib/dates.ts
25
lib/dates.ts
|
@ -1,22 +1,21 @@
|
||||||
export function niceDate(d: Date): string {
|
export function niceDate(d: Date): string {
|
||||||
function pad(n: number) {
|
return localDateString(d).split("T")[0];
|
||||||
let s = String(n);
|
|
||||||
if (s.length === 1) {
|
|
||||||
s = "0" + s;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function niceTime(d: Date): string {
|
export function niceTime(d: Date): string {
|
||||||
const isoDate = d.toISOString();
|
return localDateString(d).split("T")[1];
|
||||||
const [_, time] = isoDate.split("T");
|
|
||||||
// hh:mm:ss
|
|
||||||
return time.split(".")[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function safeTime(d: Date): string {
|
export function safeTime(d: Date): string {
|
||||||
return niceTime(d).replace(/:/g, "-");
|
return niceTime(d).replace(/:/g, "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function localDateString(d: Date): string {
|
||||||
|
return d.getFullYear() +
|
||||||
|
"-" + String(d.getMonth() + 1).padStart(2, "0") +
|
||||||
|
"-" + String(d.getDate()).padStart(2, "0") +
|
||||||
|
"T" + String(d.getHours()).padStart(2, "0") +
|
||||||
|
":" + String(d.getMinutes()).padStart(2, "0") +
|
||||||
|
":" + String(d.getSeconds()).padStart(2, "0") +
|
||||||
|
"." + String(d.getMilliseconds()).padStart(3, "0");
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { localDateString } from "$lib/dates.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a deep comparison of two objects, returning true if they are equal
|
* Performs a deep comparison of two objects, returning true if they are equal
|
||||||
* @param a first object
|
* @param a first object
|
||||||
|
@ -58,7 +60,7 @@ export function cleanStringDate(d: Date): string {
|
||||||
String(d.getMonth() + 1).padStart(2, "0") + "-" +
|
String(d.getMonth() + 1).padStart(2, "0") + "-" +
|
||||||
String(d.getDate()).padStart(2, "0");
|
String(d.getDate()).padStart(2, "0");
|
||||||
} else {
|
} else {
|
||||||
return d.toISOString();
|
return localDateString(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { listFilesCached } from "../federation/federation.ts";
|
||||||
import { queryObjects } from "../index/plug_api.ts";
|
import { queryObjects } from "../index/plug_api.ts";
|
||||||
import { folderName } from "@silverbulletmd/silverbullet/lib/resolve";
|
import { folderName } from "@silverbulletmd/silverbullet/lib/resolve";
|
||||||
import type { LinkObject } from "../index/page_links.ts";
|
import type { LinkObject } from "../index/page_links.ts";
|
||||||
|
import { localDateString } from "$lib/dates.ts";
|
||||||
|
|
||||||
// A meta page is a page tagged with either #template or #meta
|
// A meta page is a page tagged with either #template or #meta
|
||||||
const isMetaPageFilter: QueryExpression = ["or", ["=", ["attr", "tags"], [
|
const isMetaPageFilter: QueryExpression = ["or", ["=", ["attr", "tags"], [
|
||||||
|
@ -204,7 +205,7 @@ function fileMetaToPageMeta(fileMeta: FileMeta): PageMeta {
|
||||||
ref: fileMeta.name,
|
ref: fileMeta.name,
|
||||||
tag: "page",
|
tag: "page",
|
||||||
name,
|
name,
|
||||||
created: new Date(fileMeta.created).toISOString(),
|
created: localDateString(new Date(fileMeta.created)),
|
||||||
lastModified: new Date(fileMeta.lastModified).toISOString(),
|
lastModified: localDateString(new Date(fileMeta.lastModified)),
|
||||||
} as PageMeta;
|
} as PageMeta;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
import { defaultLinkStyle, maximumAttachmentSize } from "../constants.ts";
|
import { defaultLinkStyle, maximumAttachmentSize } from "../constants.ts";
|
||||||
import { safeRun } from "$lib/async.ts";
|
import { safeRun } from "$lib/async.ts";
|
||||||
import { resolvePath } from "@silverbulletmd/silverbullet/lib/resolve";
|
import { resolvePath } from "@silverbulletmd/silverbullet/lib/resolve";
|
||||||
|
import { localDateString } from "$lib/dates.ts";
|
||||||
|
|
||||||
const turndownService = new TurndownService({
|
const turndownService = new TurndownService({
|
||||||
hr: "---",
|
hr: "---",
|
||||||
|
@ -187,8 +188,7 @@ export function attachmentExtension(editor: Client) {
|
||||||
}
|
}
|
||||||
const fileType = file.type;
|
const fileType = file.type;
|
||||||
const ext = fileType.split("/")[1];
|
const ext = fileType.split("/")[1];
|
||||||
const fileName = new Date()
|
const fileName = localDateString(new Date())
|
||||||
.toISOString()
|
|
||||||
.split(".")[0]
|
.split(".")[0]
|
||||||
.replace("T", "_")
|
.replace("T", "_")
|
||||||
.replaceAll(":", "-");
|
.replaceAll(":", "-");
|
||||||
|
|
Loading…
Reference in New Issue