From 2773276192dda36aa630c9bf73e404b068e2ebea Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Wed, 9 Feb 2022 23:32:31 -0500 Subject: [PATCH] ADD functions to track the current planning date/quarter/week --- local/lib/org-x/org-x-dag.el | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/local/lib/org-x/org-x-dag.el b/local/lib/org-x/org-x-dag.el index 4154d21..3972543 100644 --- a/local/lib/org-x/org-x-dag.el +++ b/local/lib/org-x/org-x-dag.el @@ -153,6 +153,53 @@ that file as it currently sits on disk.") (let ((filemap (plist-get org-x-dag :file->ids))) (--mapcat (ht-get filemap it) files))) +;; planning state + +;; TODO might be less tedious to just set the date and have functions handy +;; to get the current quarter and week start +(defvar org-x-dag-selected-quarter nil + "The current quarter to be used for planning. +Is a list like (YEAR QUARTER).") + +(defvar org-x-dag-selected-week nil + "The current week to be used for planning. +A date like (YEAR MONTH DAY).") + +(defvar org-x-dag-week-start-index 0 + "The day considered to start a week (0 = Sunday).") + +(defvar org-x-dag-selected-date nil + "The current week to be used for planning. +A date like (YEAR MONTH DAY).") + +(defun org-x-dag-gregorian-to-date (greg) + (-let (((m d y) greg)) + `(,y ,m ,d))) + +(defun org-x-dag-set-planning-quarter-at-date (date) + ;; ASSUME the date is valid with no overflow digits + (-let (((y m _) date)) + (setq org-x-dag-selected-quarter `(,y ,(/ m 3))))) + +(defun org-x-dag-date-to-week-start (date) + (while (not (= (calendar-day-of-week date) org-x-dag-week-start-index)) + (setq date (->> (org-x-dag-date-to-gregorian date) + (calendar-absolute-from-gregorian) + (1-) + (calendar-gregorian-from-absolute) + (org-x-dag-gregorian-to-date)))) + date) + +(defun org-x-dag-set-planning-week-at-date (date) + (setq org-x-dag-selected-week date)) + +(defun org-x-dag-set-planning-date (date) + ;; TODO validate date? + (let ((week-start (org-x-dag-date-to-week-start date))) + (setq org-x-dag-selected-date date) + (setq org-x-dag-selected-week week-date) + (org-x-dag-set-planning-quarter-at-date week-date))) + ;;; BUFFER SCANNING (defun org-x-dag-get-local-property (prop)