summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-09-06 10:06:15 +0300
committerThanos Apollo <[email protected]>2024-09-06 10:06:15 +0300
commit8308ff516584dae073d4e8f78e0f58d5363b48de (patch)
tree6ed2d48285e052614d5fefdde483b32bef15bd05
parent731f0ba4910c872efedf7e460d904f3d9c3be9a7 (diff)
algorithm-date: Refactor date calculation.
* Use time-add & days-to-time for adding days to current time. * Construct the date list without reassigning variables.
-rw-r--r--gnosis-algorithm.el21
1 files changed, 10 insertions, 11 deletions
diff --git a/gnosis-algorithm.el b/gnosis-algorithm.el
index a8930a3..a789846 100644
--- a/gnosis-algorithm.el
+++ b/gnosis-algorithm.el
@@ -25,7 +25,7 @@
;;; Commentary:
;; Module that handles date and interval calculation as well as
-;; gnosis-score for notes.
+;; gnosis-score for gnosis.
;;; Code:
@@ -105,16 +105,15 @@ On lethe events the next interval is set to 0."
(defun gnosis-algorithm-date (&optional offset)
"Return the current date in a list (year month day).
Optional integer OFFSET is a number of days from the current date."
- (cl-assert (or (numberp offset) (null offset)) nil "Date offset must be an integer or nil")
- (let* ((now (decode-time))
- (now (list (decoded-time-month now)
- (decoded-time-day now)
- (decoded-time-year now))))
- (let ((date (if (zerop (or offset 0))
- now
- (calendar-gregorian-from-absolute
- (+ offset (calendar-absolute-from-gregorian now))))))
- (list (nth 2 date) (nth 0 date) (nth 1 date)))))
+ (cl-assert (or (integerp offset) (null offset)) nil "Date offset must be an integer or nil")
+ (let* ((base-time (current-time))
+ (target-time (if offset
+ (time-add base-time (days-to-time offset))
+ base-time))
+ (decoded-time (decode-time target-time)))
+ (list (decoded-time-year decoded-time)
+ (decoded-time-month decoded-time)
+ (decoded-time-day decoded-time))))
(defun gnosis-algorithm-date-diff (date &optional date2)
"Find the difference between DATE2 and DATE.