Skip to content

Support for unix timestamp in denote-date-prompt #721

Description

@jeffvalk

Hello @protesilaos, and many thanks for Denote!

I sometimes find it convenient to paste/yank a Unix timestamp when creating a new note. denote-date-prompt doesn't presently support dates in this format, so I advise the function as follows:

(defun my/denote-date-prompt-advice (f &rest args)
  "Apply F to ARGS such that `denote-date-prompt' handles Unix timestamps.
If the value read by the prompt is a Unix timestamp, parse it to the
format expected by Denote. Otherwise, return the value as it was read."
  (let ((date (apply f args)))
    (if (string-match "[0-9]\\{10\\}" date) ; seconds since epoch
        (let ((secs (string-to-number (match-string 0 date))))
          (format-time-string "%Y-%m-%d %H:%M:%S" (seconds-to-time secs)))
      date)))

(advice-add 'denote-date-prompt :around #'my/denote-date-prompt-advice)

Might Unix timestamps make sense to support in Denote's date prompt? I would be happy to contribute a patch if you like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions