summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-05-10 14:12:26 +0300
committerThanos Apollo <[email protected]>2024-05-10 14:12:26 +0300
commit5e2c02847f2b87874c00d31d596e48460b2d4c66 (patch)
treebb5e618b299026889bd6ec2bdcfeece612c38b81
parentdd8eb64aef4e070ec500989587aed850e8e2534a (diff)
[Refactor] gnosis-algorithm-date-diff: Add date2
Return the diff between date2, optional arg with default current date.
-rw-r--r--gnosis-algorithm.el15
1 files changed, 10 insertions, 5 deletions
diff --git a/gnosis-algorithm.el b/gnosis-algorithm.el
index 4cfebd1..86a997d 100644
--- a/gnosis-algorithm.el
+++ b/gnosis-algorithm.el
@@ -123,13 +123,18 @@ Optional integer OFFSET is a number of days from the current date."
(+ offset (calendar-absolute-from-gregorian now))))))
(list (nth 2 date) (nth 0 date) (nth 1 date)))))
-(defun gnosis-algorithm-date-diff (date)
- "Find the difference between the current date and the given DATE.
+(defun gnosis-algorithm-date-diff (date &optional date2)
+ "Find the difference between DATE2 and DATE.
+
+If DATE2 is nil, current date will be used instead.
DATE format must be given as (year month day)."
- (let ((given-date (encode-time 0 0 0 (caddr date) (cadr date) (car date))))
- (- (time-to-days (current-time))
- (time-to-days given-date))))
+ (let* ((given-date (encode-time 0 0 0 (caddr date) (cadr date) (car date)))
+ (date2 (if date2 (encode-time 0 0 0 (caddr date2) (cadr date2) (car date2))
+ (current-time)))
+ (diff (- (time-to-days date2)
+ (time-to-days given-date))))
+ (if (>= diff 0) diff (error "`DATE2' must be higher than `DATE'"))))
(cl-defun gnosis-algorithm-next-ef (&key ef success increase decrease threshold
c-successes c-failures)