Skip to content

Conversation

vanndoublen
Copy link
Contributor

@vanndoublen vanndoublen commented May 16, 2025

Summary:

This pull request introduces a user-configurable date/time format for the Alt+T keyboard shortcut. Users can now define their preferred date and time string format using Day.js tokens via a new setting, providing greater flexibility.

Changes Implemented:

  • New Setting UI:
    • A "Custom Date/Time Format (Alt+T)" section has been added under "Options" -> "Text Notes".
    • Users can input a Day.js compatible format string.
    • The UI provides examples, a link to Day.js documentation, and clear explanations of behavior with valid, empty, or unrecognized format strings.
  • Shortcut Logic Update:
    • The Alt+T command (insertDateTimeToTextCommand) now attempts to retrieve the custom format string from application options.
  • Formatting Utility Enhancement:
    • The utils.formatDateTime function has been updated to use dayjs with the user-supplied format string.
    • If the custom format string is empty, or if Day.js encounters a critical internal error processing the format, the system gracefully falls back to the default Trilium format (e.g., YYYY-MM-DD HH:mm).
    • Unrecognized format strings (that don't cause Day.js errors) may result in literal or partially transformed text insertion, as described in the UI.
  • Backend Configuration:
    • Updated the server-side list of allowed options (ALLOWED_OPTIONS in src/routes/api/options.js) to include the new customDateTimeFormatString key, enabling it to be saved.

How to Test:

  1. Navigate to "Options" -> "Text Notes".
  2. Locate the "Custom Date/Time Format (Alt+T)" section.
  3. Enter a valid Day.js format string (e.g., DD/MM/YYYY HH:mm:ss, MMMM D, YYYY).
  4. Go to any text note and press Alt+T. The date and time should be inserted using the custom format (assuming the option saved correctly).
  5. Clear the format string in the options.
  6. Press Alt+T in a text note. The date and time should revert to the default Trilium format.

Note on Saving Options During Testing:

While developing this feature on my Windows 11, I sometimes encountered errors in the console (like "EPERM: operation not permitted" related to session files, followed by "ERR_HTTP_HEADERS_SENT") when trying to save changes in the Options screen. This happened not just with my new setting, but also when changing other existing Trilium options.

It seems like there might be something in my local setup (perhaps related to file access or another program) that occasionally interferes with how Trilium saves options or session data.

The custom date/time formatting feature itself should work correctly if the option saves properly.

Related Issue:

This feature addresses the user need for more flexible date formatting, similar to what was requested in issue #4906.
Closes #4906


Screenshots:

Screenshot 2025-05-17 014130
Screenshot 2025-05-17 014001
image

@SiriusXT
Copy link
Member

SiriusXT commented May 17, 2025

Thanks for your contribution! However, this repository is currently in maintenance mode. You're very welcome to submit a PR to Trilium's successor repository instead. https://github.com/TriliumNext/Notes

This PR is closely related to the issue in TriliumNext: #5390.

Before proceeding, I'd like to ask @eliandoran for his thoughts on this PR.

@vanndoublen
Copy link
Contributor Author

Hi @SiriusXT,

Thanks for notifying me about TriliumNext/Notes.

I've opened a new PR for the feature over at TriliumNext/Notes and linked it to the issue you mentioned (TriliumNext/Notes#962): TriliumNext/Notes#1964

You can close this current PR whenever you're ready.

Thanks.

@eliandoran eliandoran deleted the branch TriliumNext:master June 21, 2025 14:45
@eliandoran eliandoran closed this Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Feature request) Is it possible to change date format?
3 participants