diff --git a/common/syscalls/handlebar_helpers.ts b/common/syscalls/handlebar_helpers.ts index 2b2380b..004a09d 100644 --- a/common/syscalls/handlebar_helpers.ts +++ b/common/syscalls/handlebar_helpers.ts @@ -1,4 +1,4 @@ -import { niceDate } from "$sb/lib/dates.ts"; +import { niceDate, niceTime } from "$sb/lib/dates.ts"; export function handlebarHelpers() { return { @@ -15,6 +15,7 @@ export function handlebarHelpers() { substring: (s: string, from: number, to: number, elipsis = "") => s.length > to - from ? s.substring(from, to) + elipsis : s, + time: () => niceTime(new Date()), today: () => niceDate(new Date()), tomorrow: () => { const tomorrow = new Date(); diff --git a/plug-api/lib/dates.ts b/plug-api/lib/dates.ts index b17a2cb..63b0057 100644 --- a/plug-api/lib/dates.ts +++ b/plug-api/lib/dates.ts @@ -9,3 +9,10 @@ export function niceDate(d: Date): string { return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate()); } + +export function niceTime(d: Date): string { + const isoDate = d.toISOString(); + let [date, time] = isoDate.split("T"); + // hh:mm:ss + return time.split(".")[0]; +} diff --git a/plugs/template/template.ts b/plugs/template/template.ts index 1870eed..6f5b79e 100644 --- a/plugs/template/template.ts +++ b/plugs/template/template.ts @@ -1,7 +1,7 @@ import { editor, handlebars, markdown, space } from "$sb/syscalls.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; import { renderToText } from "$sb/lib/tree.ts"; -import { niceDate } from "$sb/lib/dates.ts"; +import { niceDate, niceTime } from "$sb/lib/dates.ts"; import { readSettings } from "$sb/lib/settings_page.ts"; import { cleanPageRef } from "$sb/lib/resolve.ts"; import { PageMeta } from "$sb/types.ts"; @@ -170,9 +170,8 @@ export async function quickNoteCommand() { const { quickNotePrefix } = await readSettings({ quickNotePrefix: "📥 ", }); - const isoDate = new Date().toISOString(); - let [date, time] = isoDate.split("T"); - time = time.split(".")[0]; + const date = niceDate(new Date()); + const time = niceTime(new Date()); const pageName = `${quickNotePrefix}${date} ${time}`; await editor.navigate(pageName); }