Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix: address the review feedback
iamvannd1f8e651f46c
diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.tsindex 92ca2bc70b..c31faf98d7 100644--- a/apps/client/src/services/utils.ts+++ b/apps/client/src/services/utils.ts@@ -125,22 +125,14 @@ function formatDateISO(date: Date) {}-// old version-// function formatDateTime(date: Date) {-// return `${formatDate(date)} ${formatTime(date)}`;-// }--// new version-export function formatDateTime(date: Date, userSuppliedFormat?: string): string {- const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm';- let formatToUse = DEFAULT_FORMAT;-- if (userSuppliedFormat && typeof userSuppliedFormat === 'string' && userSuppliedFormat.trim() !== "") {- formatToUse = userSuppliedFormat.trim();- }+export function formatDateTime(date: Date, userSuppliedFormat?: string): string {+ const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm';+ const formatToUse = (typeof userSuppliedFormat === 'string' && userSuppliedFormat.trim() !== "")+ ? userSuppliedFormat.trim()+ : DEFAULT_FORMAT;if (!date) {- date = new Date();+ date = new Date();}try {diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 24f1044419..efa2e5a83f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1956,5 +1956,16 @@"title": "Appearance","word_wrapping": "Word wrapping","color-scheme": "Color scheme"+ },+ "custom_date_time_format": {+ "title": "Custom Date/Time Format (Alt+T)",+ "desc1": "Define a custom format for the date and time inserted using the Alt+T shortcut.",+ "desc2": "Uses <a href=\"https://day.js.org/docs/en/display/format\" target=\"_blank\" rel=\"noopener noreferrer\">Day.js format tokens</a>. Refer to the Day.js documentation for valid tokens.",+ "important_label": "Important:",+ "desc3": "If you provide a format string that Day.js does not recognize (e.g., mostly plain text without valid Day.js tokens), the text you typed might be inserted literally. If the format string is left empty, or if Day.js encounters a critical internal error with your format, a default format (e.g., YYYY-MM-DD HH:mm) will be used.",+ "format_string_label": "Format String:",+ "placeholder": "e.g., DD/MM/YYYY HH:mm:ss or dddd, MMMM D",+ "examples_label": "Examples of valid Day.js formats:",+ "example_default": "Default-like"}}diff --git a/apps/client/src/widgets/type_widgets/editable_text.ts b/apps/client/src/widgets/type_widgets/editable_text.tsindex 4e530f9908..1670a0ce10 100644--- a/apps/client/src/widgets/type_widgets/editable_text.ts+++ b/apps/client/src/widgets/type_widgets/editable_text.ts@@ -287,7 +287,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {// Touch bar integrationif (hasTouchBar) {- for (const event of ["bold", "italic", "underline", "paragraph", "heading"]) {+ for (const event of [ "bold", "italic", "underline", "paragraph", "heading" ]) {editor.commands.get(event)?.on("change", () => this.triggerCommand("refreshTouchBar"));}}@@ -373,15 +373,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {});}}- // old version- // insertDateTimeToTextCommand() {- // const date = new Date();- // const dateString = utils.formatDateTime(date);- // this.addTextToEditor(dateString);- // }-- // new versionasync insertDateTimeToTextCommand() {const date = new Date();let userPreferredFormat = "";diff --git a/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts b/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.tsindex 7ddf055659..0690e77a93 100644--- a/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts+++ b/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts@@ -5,28 +5,28 @@ import type { OptionMap } from "@triliumnext/commons";const TPL = /*html*/`<div class="options-section">- <h4>${t("options.customDateTimeFormatTitle", "Custom Date/Time Format (Alt+T)")}</h4>+ <h4>${t("custom_date_time_format.title")}</h4><p>- ${t("options.customDateTimeFormatDesc1", "Define a custom format for the date and time inserted using the Alt+T shortcut.")}- ${t("options.customDateTimeFormatDesc2", "Uses <a href=\"https://day.js.org/docs/en/display/format\" target=\"_blank\" rel=\"noopener noreferrer\">Day.js format tokens</a>. Refer to the Day.js documentation for valid tokens.")}+ ${t("custom_date_time_format.desc1")}+ ${t("custom_date_time_format.desc2")}</p><p>- <strong>${t("options.customDateTimeFormatImportant", "Important:")}</strong>- ${t("options.customDateTimeFormatDesc3", "If you provide a format string that Day.js does not recognize (e.g., mostly plain text without valid Day.js tokens), the text you typed might be inserted literally. If the format string is left empty, or if Day.js encounters a critical internal error with your format, a default format (e.g., YYYY-MM-DD HH:mm) will be used.")}+ <strong>${t("custom_date_time_format.important_label")}</strong>+ ${t("custom_date_time_format.desc3")}</p><div class="form-group"><label for="customDateTimeFormatInput" style="margin-right: 10px;">- ${t("options.customDateTimeFormatLabel", "Format String:")}+ ${t("custom_date_time_format.format_string_label")}</label><input type="text" id="customDateTimeFormatInput" class="form-control custom-datetime-format-input"- placeholder="${t("options.customDateTimeFormatPlaceholder", "e.g., DD/MM/YYYY HH:mm:ss or dddd, MMMM D")}"+ placeholder="${t("custom_date_time_format.placeholder")}"style="width: 300px; display: inline-block;"></div><p style="margin-top: 5px;">- <em>${t("options.customDateTimeFormatExamplesLabel", "Examples of valid Day.js formats:")}</em>- <code>YYYY-MM-DD HH:mm</code> (${t("options.customDateTimeFormatExampleDefault", "Default-like")}),+ <em>${t("custom_date_time_format.examples_label")}</em>+ <code>YYYY-MM-DD HH:mm</code> (${t("custom_date_time_format.example_default")}),<code>DD.MM.YYYY</code>,<code>MMMM D, YYYY h:mm A</code>,<code>[Today is] dddd</code>