diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts index 92ca2bc70..c31faf98d 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.json index 24f104441..efa2e5a83 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 Day.js format tokens. 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.ts index 4e530f990..1670a0ce1 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 integration if (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 version async 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.ts index 7ddf05565..0690e77a9 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*/`