emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote d862b65526 06/12: Define denote-get-identifier f


From: ELPA Syncer
Subject: [elpa] externals/denote d862b65526 06/12: Define denote-get-identifier function
Date: Sun, 11 Feb 2024 03:57:53 -0500 (EST)

branch: externals/denote
commit d862b655268f051cd7153047adec0223c8daca1a
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Define denote-get-identifier function
    
    The idea is to streamline how we do the 'format-time-string', so that
    we do not get any weird bugs.
---
 README.org           | 6 ++++++
 denote.el            | 8 ++++++++
 tests/denote-test.el | 6 ++++++
 3 files changed, 20 insertions(+)

diff --git a/README.org b/README.org
index 1d6ea37b63..de1ce3a03c 100644
--- a/README.org
+++ b/README.org
@@ -4086,6 +4086,12 @@ might change them without further notice.
 + Function ~denote-retrieve-filename-signature~ :: Extract signature
   from =FILE= name, if present, else return nil.
 
+#+findex: denote-get-identifier
++ Function ~denote-get-identifier~ :: Convert =DATE= into a Denote
+  identifier using ~denote-id-format~. =DATE= is parsed by
+  ~denote-valid-date-p~. If =DATE= is nil, use the current time.
+  [ Part of {{{development-version}}}. ]
+
 #+findex: denote-create-unique-file-identifier
 + Function ~denote-create-unique-file-identifier~ :: Create a new unique
   =FILE= identifier.  Test that the identifier is unique among
diff --git a/denote.el b/denote.el
index 05da6644dd..dbd2eb6e11 100644
--- a/denote.el
+++ b/denote.el
@@ -1548,6 +1548,14 @@ To create a new one, refer to the function
   (or (denote-retrieve-filename-identifier file)
       (error "Cannot find `%s' as a file with a Denote identifier" file)))
 
+(defun denote-get-identifier (&optional date)
+  "Convert DATE into a Denote identifier using `denote-id-format'.
+DATE is parsed by `denote-valid-date-p'.  If DATE is nil, use the
+current time."
+  (format-time-string
+   denote-id-format
+   (when date (denote-valid-date-p date))))
+
 (defun denote-create-unique-file-identifier (file used-ids &optional date)
   "Generate a unique identifier for FILE not in USED-IDS hash-table.
 
diff --git a/tests/denote-test.el b/tests/denote-test.el
index 1231cef1d2..04b83f0413 100644
--- a/tests/denote-test.el
+++ b/tests/denote-test.el
@@ -404,6 +404,12 @@ Extend what we do in 
`denote-test--denote-file-type-extensions'."
         (equal (denote-convert-file-name-keywords-to-crm "_denote") "denote")
         (equal (denote-convert-file-name-keywords-to-crm "") ""))))
 
+(ert-deftest denote-test--denote-get-identifier ()
+  "Test that `denote-get-identifier' returns an identifier."
+  (should (and (equal (denote-get-identifier) (format-time-string 
denote-id-format (current-time)))
+               (equal (denote-get-identifier "2024-02-01 10:34") 
"20240201T103400")))
+  (should-error (denote-get-identifier "Invalid date")))
+
 ;;;; denote-journal-extras.el
 
 (require 'denote-journal-extras)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]