branch: elpa/beancount
commit dbafe6a73d90c1f64d457b356b9dbb43499f70d5
Author: Debanjum Singh Solanky <[email protected]>
Commit: Martin Blais <[email protected]>
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.