mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-31 04:02:26 +08:00
fix: address the review feedback
This commit is contained in:
parent
2e3a8dfacb
commit
d1f8e651f4
@ -125,19 +125,11 @@ 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 {
|
export function formatDateTime(date: Date, userSuppliedFormat?: string): string {
|
||||||
const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm';
|
const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm';
|
||||||
let formatToUse = DEFAULT_FORMAT;
|
const formatToUse = (typeof userSuppliedFormat === 'string' && userSuppliedFormat.trim() !== "")
|
||||||
|
? userSuppliedFormat.trim()
|
||||||
if (userSuppliedFormat && typeof userSuppliedFormat === 'string' && userSuppliedFormat.trim() !== "") {
|
: DEFAULT_FORMAT;
|
||||||
formatToUse = userSuppliedFormat.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!date) {
|
if (!date) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
|
@ -1956,5 +1956,16 @@
|
|||||||
"title": "Appearance",
|
"title": "Appearance",
|
||||||
"word_wrapping": "Word wrapping",
|
"word_wrapping": "Word wrapping",
|
||||||
"color-scheme": "Color scheme"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
|
|
||||||
// Touch bar integration
|
// Touch bar integration
|
||||||
if (hasTouchBar) {
|
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"));
|
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() {
|
async insertDateTimeToTextCommand() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
let userPreferredFormat = "";
|
let userPreferredFormat = "";
|
||||||
|
@ -5,28 +5,28 @@ import type { OptionMap } from "@triliumnext/commons";
|
|||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<div class="options-section">
|
<div class="options-section">
|
||||||
<h4>${t("options.customDateTimeFormatTitle", "Custom Date/Time Format (Alt+T)")}</h4>
|
<h4>${t("custom_date_time_format.title")}</h4>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
${t("options.customDateTimeFormatDesc1", "Define a custom format for the date and time inserted using the Alt+T shortcut.")}
|
${t("custom_date_time_format.desc1")}
|
||||||
${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.desc2")}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<strong>${t("options.customDateTimeFormatImportant", "Important:")}</strong>
|
<strong>${t("custom_date_time_format.important_label")}</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.")}
|
${t("custom_date_time_format.desc3")}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="customDateTimeFormatInput" style="margin-right: 10px;">
|
<label for="customDateTimeFormatInput" style="margin-right: 10px;">
|
||||||
${t("options.customDateTimeFormatLabel", "Format String:")}
|
${t("custom_date_time_format.format_string_label")}
|
||||||
</label>
|
</label>
|
||||||
<input type="text" id="customDateTimeFormatInput" class="form-control custom-datetime-format-input"
|
<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;">
|
style="width: 300px; display: inline-block;">
|
||||||
</div>
|
</div>
|
||||||
<p style="margin-top: 5px;">
|
<p style="margin-top: 5px;">
|
||||||
<em>${t("options.customDateTimeFormatExamplesLabel", "Examples of valid Day.js formats:")}</em>
|
<em>${t("custom_date_time_format.examples_label")}</em>
|
||||||
<code>YYYY-MM-DD HH:mm</code> (${t("options.customDateTimeFormatExampleDefault", "Default-like")}),
|
<code>YYYY-MM-DD HH:mm</code> (${t("custom_date_time_format.example_default")}),
|
||||||
<code>DD.MM.YYYY</code>,
|
<code>DD.MM.YYYY</code>,
|
||||||
<code>MMMM D, YYYY h:mm A</code>,
|
<code>MMMM D, YYYY h:mm A</code>,
|
||||||
<code>[Today is] dddd</code>
|
<code>[Today is] dddd</code>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user