(defun compare-lists (a b)
(if (every 'seq-empty-p (list a b))
t
(let* ((a- (mapcar (lambda (x) (if (null x) 0 x)) a))
(b- (mapcar (lambda (x) (if (null x) 0 x)) b))
(x (first a-))
(y (first b-)))
(cond ((null x) nil)
((null y) t)
((= x y) (compare-lists (rest a) (rest b)))
(t (< x y))))))
(defun compare-dates (a b)
(apply 'compare-lists
(mapcar 'reverse (mapcar 'parse-time-string (list a b)))))
(defun get-property (property element &optional default)
(let ((value (org-element-property property element)))
(if (null value) default value)))
(defun compare-timesheet-lists (a b)
(apply 'compare-dates (mapcar 'first (list a b))))
(nconc
'(("date" "project" "hours" "tasks" "name"))
'(hline)
(sort (let ((ast (org-element-parse-buffer 'element)))
(org-element-map ast 'clock
(lambda (x)
(let* ((val (org-element-property :value x))
(task (org-element-property :parent (org-element-property :parent x))))
`(,(let ((year (org-element-property :year-start val))
(month (calendar-month-name
(org-element-property :month-start val)))
(day (org-element-property :day-start val)))
(format "%s %s, %s" month day year))
,(get-property :PROJECT task "")
,(org-element-property :duration x)
,(org-element-property :title task)
,(get-property :NAME task "Alex"))
))))
'compare-timesheet-lists)
'(hline)
'(("" "total:" ":=vsum(@2..@-1)" "" "")))
Last active
April 16, 2018 05:53
-
-
Save alexpeits/2acedf36a9d2006cf1e73e27dcefb76a to your computer and use it in GitHub Desktop.
Simple org file demonstrating how to track work hours per project
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment