Comments (10)
But this function does not accept only a date.
You mean it does not accept input like 2020-01-15
? It seems to work on my end, but maybe I am doing something different.
I am moving old notes from years ago into denote and like to keep the original date, but I have not record of the original creation time.
Depending on what you are doing exactly, you might find better value in the commands denote-dired-rename-marked-files
and denote-dired-rename-marked-files-and-add-front-matters
. Both are in the main
branch, though they will only be available for the regular package in the next tagged release (maybe at end of this week or beginning of the next one)). Their doc strings explain what they do.
Could this function be written so that it uses current time, when only a date is added?
Wouldn't this be the same as the denote
command then? Or am I misunderstanding what you mean by "current time"? Maybe you want the input 2020-01-15
to be interpreted as, say, 2020-01-15 14:48
(current local hour and minute)?
Just asking to be sure I get this right.
from denote.
Assuming I understood your request earlier, this diff automatically adds an HOUR:MINUTE
component to a YEAR-MONTH-DAY
input. The helper function's doc string notes as much:
denote.el | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/denote.el b/denote.el
index 8a17fbe..0cbf13c 100644
--- a/denote.el
+++ b/denote.el
@@ -827,9 +827,20 @@ (defun denote--date-prompt ()
"DATE and TIME for note (e.g. 2022-06-16 14:30): "
nil 'denote--date-history))
+(defun denote--date-add-current-time (date)
+ "Add current time to date, if necessary.
+The idea is to turn 2020-01-15 into 2020-01-15 16:19 so that the
+hour and minute component is not left to 00:00. This reduces the
+burden on the user who would otherwise need to input that value
+in order to avoid the error of duplicate identifiers."
+ (if (<= (length date) 10)
+ (format "%s %s" date (format-time-string "%H:%M:%S" (current-time)))
+ date))
+
(defun denote--valid-date (date)
"Return DATE if parsed by `date-to-time', else signal error."
- (date-to-time date))
+ (let ((d (denote--date-add-current-time date)))
+ (date-to-time d)))
(defun denote--buffer-file-names ()
"Return file names of active buffers."
from denote.
I'll explain it a bit better:
- I evoke the
denote-date
function - I enter a date only, e.g.
2013-12-22
- I enter filename and tags
- Emacs says "
Invalid date: 2013-12-22
I am using Denote 0.3.1.
The manual either needs to specify that a time has to be provided, or the function should assume current time or 00:00:00 when no time is provided.
from denote.
That's strange. It works on my end.
Does this evaluate for you? (this is basically what we do):
(date-to-time "2013-12-22")
On my end, it returns (21174 3936)
. So this works as well:
(format-time-string "%Y%m%dT%H%M%S" (date-to-time "2013-12-22"))
It returns "20131222T000000"
which is the expected value.
from denote.
Hi Prot,
I used a clean Emacs 28.1 with only Denote (GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.17.6) of 2022-04-28).
When I run (date-to-time "2013-12-22")
, I get the same error: date-to-time: Invalid date: 2013-12-22
.
This version works: (date-to-time "2013-12-22 12:13:14")
.
I excavated the date-time
function in my setup. I am not much of an elisp wiz. Is this the same function you use?
(defun date-to-time (date)
"Parse a string DATE that represents a date-time and return a time value.
DATE should be in one of the forms recognized by `parse-time-string'.
If DATE lacks timezone information, GMT is assumed."
(condition-case err
(encode-time (parse-time-string date))
(error
(let ((overflow-error '(error "Specified time is not representable")))
(if (equal err overflow-error)
(signal (car err) (cdr err))
(condition-case err
(encode-time (parse-time-string
(timezone-make-date-arpa-standard date)))
(error
(if (equal err overflow-error)
(signal (car err) (cdr err))
(error "Invalid date: %s" date)))))))))
from denote.
Hi Peter,
I just reproduced your problem. It is a difference between Emacs 28 and Emacs 29. I will update the code accordingly. The desired behaviour is to accept input like 2013-12-22
.
from denote.
Just pushed commit f6a1276
. It should fix your problem.
To recap, this would return an error on Emacs 28 but not on Emacs 29:
(denote--valid-date "2013-12-22")
Changing the code to the following makes (denote--valid-date "2013-12-22")
work:
(defun denote--date-add-current-time (date)
"Add current time to date, if necessary.
The idea is to turn 2020-01-15 into 2020-01-15 16:19 so that the
hour and minute component is not left to 00:00.
This reduces the burden on the user who would otherwise need to
input that value in order to avoid the error of duplicate
identifiers.
It also addresses a difference between Emacs 28 and Emacs 29
where the former does not read dates without a time component."
(if (<= (length date) 10)
(format "%s %s" date (format-time-string "%H:%M:%S" (current-time)))
date))
(defun denote--valid-date (date)
"Return DATE if parsed by `date-to-time', else signal error."
(let ((datetime (denote--date-add-current-time date)))
(date-to-time datetime)))
EDIT: clarify sentence.
from denote.
As for how date-to-time
looks on Emacs 29:
;;;###autoload
;; `parse-time-string' isn't sufficiently general or robust. It fails
;; to grok some of the formats that timezone does (e.g. dodgy
;; post-2000 stuff from some Elms) and either fails or returns bogus
;; values. timezone-make-date-arpa-standard should help.
(defun date-to-time (date)
"Parse a string DATE that represents a date-time and return a time value.
DATE should be in one of the forms recognized by `parse-time-string'.
If DATE lacks timezone information, GMT is assumed."
(condition-case err
(let ((parsed (parse-time-string date)))
(when (decoded-time-year parsed)
(decoded-time-set-defaults parsed))
(encode-time parsed))
(error
(let ((overflow-error '(error "Specified time is not representable")))
(if (equal err overflow-error)
(signal (car err) (cdr err))
(condition-case err
(encode-time (parse-time-string
(timezone-make-date-arpa-standard date)))
(error
(if (equal err overflow-error)
(signal (car err) (cdr err))
(error "Invalid date: %s" date)))))))))
from denote.
Excellent. I moved to the development version and now it works a treat. Thanks for researching this minor issue.
from denote.
You're welcome!
from denote.
Related Issues (20)
- Org capture with denote while creating title programatically HOT 3
- Providing a way to extend the content of the backlinks buffer ? HOT 5
- "denote:" link for non-note files doesn't open HOT 22
- Adding denote-keywords-add and denote-keywords-remove as call able function HOT 14
- denote--get-silo-path: Symbol’s function definition is void: file-name-parent-directory HOT 7
- denote-file-types plist now has 11 elements and not 8 HOT 1
- defuns for implementing a zettelkasten in denote. HOT 14
- Selecting a non-denote file navigates to only to denote files with `denote-link-find-file` minibuffer HOT 1
- use consult for `denote-link-insert-*` HOT 6
- `denote-link-or-create` enters path instead of note name into title history HOT 5
- add a way to use `denote-link-or-create` programmatically HOT 2
- Delimiters in signatures HOT 6
- denote-rename-file-using-front-matter doesn't work since last update HOT 5
- double `#+title ` when called through keybinding but not through `M-x` HOT 12
- backlinks buffer doesn't support non-latin characters HOT 19
- [feature request] Only display TITLE in tabs HOT 19
- is there a way to skip the "file title" prompt when using the function denote-open-or-create HOT 2
- How to open denote links outside of denote when the note is located in a silo? HOT 2
- parenthesis are stripped from the title including thier content when creating file name HOT 1
- How to stop denote-dired-rename-marked-files from prompting for pdf files? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from denote.