diff --git a/apps/client/src/services/keyboard_actions.ts b/apps/client/src/services/keyboard_actions.ts index dfa888620..3cb0ffd33 100644 --- a/apps/client/src/services/keyboard_actions.ts +++ b/apps/client/src/services/keyboard_actions.ts @@ -115,6 +115,7 @@ function updateDisplayedShortcuts($container: JQuery) { export default { updateDisplayedShortcuts, setupActionsForElement, + getAction, getActions, getActionsForScope }; diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts index f5c1f465f..590c596b2 100644 --- a/apps/client/src/services/utils.ts +++ b/apps/client/src/services/utils.ts @@ -124,22 +124,11 @@ function formatDateISO(date: Date) { return `${date.getFullYear()}-${padNum(date.getMonth() + 1)}-${padNum(date.getDate())}`; } - -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(); - } - - try { - return dayjs(date).format(formatToUse); - } catch (e: any) { - console.warn(`TriliumNext: Day.js encountered an error with format string "${formatToUse}". Falling back to default. Error: ${e.message}`); - return dayjs(date).format(DEFAULT_FORMAT); +function formatDateTime(date: Date, userSuppliedFormat?: string): string { + if (userSuppliedFormat?.trim()) { + return dayjs(date).format(userSuppliedFormat); + } else { + return `${formatDate(date)} ${formatTime(date)}`; } } diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 2f0c0e0a8..20dcd6f56 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1431,6 +1431,12 @@ "label": "Automatic read-only size (text notes)", "unit": "characters" }, + "custom_date_time_format": { + "title": "Custom Date/Time Format", + "description": "Customize the format of the date and time inserted using the shortcut. See Day.js docs for available format tokens.", + "format_string": "Format String:", + "formatted_time": "Formatted Time:" + }, "i18n": { "title": "Localization", "language": "Language", @@ -1962,16 +1968,5 @@ "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/content_widget.ts b/apps/client/src/widgets/type_widgets/content_widget.ts index aa3eadcb0..614159cb7 100644 --- a/apps/client/src/widgets/type_widgets/content_widget.ts +++ b/apps/client/src/widgets/type_widgets/content_widget.ts @@ -8,6 +8,7 @@ import HeadingStyleOptions from "./options/text_notes/heading_style.js"; import TableOfContentsOptions from "./options/text_notes/table_of_contents.js"; import HighlightsListOptions from "./options/text_notes/highlights_list.js"; import TextAutoReadOnlySizeOptions from "./options/text_notes/text_auto_read_only_size.js"; +import DateTimeFormatOptions from "./options/text_notes/date_time_format.js"; import CodeEditorOptions from "./options/code_notes/code_editor.js"; import CodeAutoReadOnlySizeOptions from "./options/code_notes/code_auto_read_only_size.js"; import CodeMimeTypesOptions from "./options/code_notes/code_mime_types.js"; @@ -45,7 +46,6 @@ import LanguageOptions from "./options/i18n/language.js"; import type BasicWidget from "../basic_widget.js"; import CodeTheme from "./options/code_notes/code_theme.js"; import RelatedSettings from "./options/related_settings.js"; -import DateTimeFormatOptions from "./options/text_notes/date_time_format.js"; const TPL = /*html*/`