[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 8efc04c48b 1/4: Add denote-parse-date function
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/denote 8efc04c48b 1/4: Add denote-parse-date function |
|
Date: |
Sat, 20 Jan 2024 06:57:46 -0500 (EST) |
branch: externals/denote
commit 8efc04c48be43957eacf45a476500f06333a5c54
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add denote-parse-date function
---
README.org | 7 +++++++
denote.el | 22 +++++++++++++++++++---
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/README.org b/README.org
index 086350a417..2437590ae0 100644
--- a/README.org
+++ b/README.org
@@ -3863,6 +3863,13 @@ might change them without further notice.
strings into a single string. Keywords are separated by the
underscore character, per the Denote file-naming scheme.
+#+findex: denote-parse-date
++ Function ~denote-parse-date~ :: Return =DATE= as an appropriate
+ value for the ~denote~ command. If =DATE= is a list, assume it is
+ consistent with ~current-date~ or related and return it as-is. If
+ =DATE= is a non-empty string, try to convert it with ~date-to-time~.
+ If =DATE= is none of the above, return ~current-time~.
+
#+findex: denote-directory
+ Function ~denote-directory~ :: Return path of the variable
~denote-directory~ as a proper directory, also because it accepts a
diff --git a/denote.el b/denote.el
index 01bb4de19a..4a248ef57d 100644
--- a/denote.el
+++ b/denote.el
@@ -1844,6 +1844,24 @@ where the former does not read dates without a time
component."
(let ((datetime (denote--date-add-current-time date)))
(date-to-time datetime)))
+(defun denote-parse-date (date)
+ "Return DATE as an appropriate value for the `denote' command.
+
+- If DATE is a list, assume it is consistent with `current-date'
+ or related and return it as-is.
+
+- If DATE is a non-empty string, try to convert it with
+ `date-to-time'.
+
+- If DATE is none of the above, return `current-time'."
+ (cond
+ ((listp date)
+ date)
+ ((and (stringp date) (not (string-empty-p date)))
+ (denote--valid-date date))
+ (t
+ (current-time))))
+
(defun denote--buffer-file-names ()
"Return file names of Denote buffers."
(delq nil
@@ -2021,9 +2039,7 @@ When called from Lisp, all arguments are optional.
(let* ((title (or title ""))
(file-type (denote--valid-file-type (or file-type denote-file-type)))
(kws (denote-keywords-sort keywords))
- (date (if (or (null date) (string-empty-p date))
- (current-time)
- (denote--valid-date date)))
+ (date (denote-parse-date date))
(id (denote--find-first-unused-id
(format-time-string denote-id-format date)
(denote--get-all-used-ids)))