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

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

[nongnu] elpa/beancount dbafe6a73d 082/103: Shift beancount-insert-date


From: ELPA Syncer
Subject: [nongnu] elpa/beancount dbafe6a73d 082/103: Shift beancount-insert-date by DAYS from today using prefix args
Date: Mon, 29 Apr 2024 15:59:48 -0400 (EDT)

branch: elpa/beancount
commit dbafe6a73d90c1f64d457b356b9dbb43499f70d5
Author: Debanjum Singh Solanky <debanjum@gmail.com>
Commit: Martin Blais <blais@furius.ca>

    Shift beancount-insert-date by DAYS from today using prefix args
    
    Examples
      - ~C-u -1 M-x beancount-insert-date~ return yesterdays date
      - ~C-u 7 M-x beancount-insert-date~ returns date a week from today
---
 beancount.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/beancount.el b/beancount.el
index fa49eb94b5..292dda5848 100644
--- a/beancount.el
+++ b/beancount.el
@@ -815,11 +815,18 @@ what that column is and returns it (an integer)."
              (goto-char pos)
               (insert " " currency))))))))
 
-(defun beancount-insert-date ()
-  "Start a new timestamped directive."
-  (interactive)
+(defun beancount-insert-date (&optional days)
+  "Start a new timestamped directive with date shifted by DAYS from today."
+  (interactive "P")
   (unless (bolp) (newline))
-  (insert (format-time-string "%Y-%m-%d") " "))
+  (insert (beancount--shift-current-date days) " "))
+
+(defun beancount--shift-current-date (days)
+  "Return ISO-8601 formatted date shifted by DAYS from today."
+  (let ((days-to-shift (or days 0)))
+    (format-time-string
+     "%Y-%m-%d"
+     (time-add (current-time) (days-to-time days-to-shift)))))
 
 (defvar beancount-install-dir nil
   "Directory in which Beancount's source is located.



reply via email to

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