From 78924c841eeb3a28bd5303b36db1672bb89154a8 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 12 Oct 2024 17:04:54 +0200 Subject: [PATCH] Add first draft function to compute time at home for given date This is supposed to be used with `db/org-workload-overview-report`. --- init.el | 14 +++++++++----- site-lisp/db-org.el | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/init.el b/init.el index 935278a..3609cf6 100644 --- a/init.el +++ b/init.el @@ -211,18 +211,20 @@ calendar-week-start-day 1 ; Monday calendar-bahai-all-holidays-flag nil calendar-chinese-all-holidays-flag nil - calendar-christian-all-holidays-flag t + calendar-christian-all-holidays-flag nil calendar-islamic-all-holidays-flag nil calendar-hebrew-all-holidays-flag nil + ;; The following list should contain only holidays without work, as it is examined by + ;; `db/org-home-time-for-date'. holiday-general-holidays '((holiday-fixed 1 1 "New Year's Day") - (holiday-fixed 2 14 "Valentine's Day") - (holiday-fixed 4 1 "April Fools' Day") (holiday-fixed 5 1 "Labour Day") (holiday-fixed 10 3 "German Unity Day") (holiday-fixed 10 31 "Reformation Day") - (holiday-float 11 3 -1 "Day of Repentance and Prayer" 22) - (holiday-float 11 4 4 "Thanksgiving")) + (holiday-float 11 3 -1 "Day of Repentance and Prayer" 22)) holiday-other-holidays '((holiday-fixed 2 13 "Jahrestag Zerstörung Dresden 1945") + (holiday-fixed 2 14 "Valentine's Day") + (holiday-fixed 4 1 "April Fools' Day") + (holiday-fixed 5 25 "Towel Day") (holiday-fixed 6 4 "Tiananmen Massacre 1989") (holiday-fixed 6 5 "Snowden-Veröffentlichungen 2013") @@ -235,6 +237,7 @@ (holiday-fixed 7 21 "Jahrestag der 1. Mondlandung 1969") (holiday-fixed 7 21 "Jahrestag Massaker von Vassieux-en-Vercors 1944") (holiday-fixed 7 28 "Start WWI 1914") + (holiday-float 11 4 4 "Thanksgiving") (holiday-fixed 11 11 "End WWI 1918")) diary-show-holidays-flag t calendar-view-holidays-initially-flag nil)) @@ -530,6 +533,7 @@ db/org-remaining-effort-of-current-item db/org-cmp-remaining-effort org-dblock-write:db/org-workload-report + db/org-home-time-for-date endless/org-ispell db/org-agenda-list-deadlines db/org-agenda-insert-active-filters diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index b0e3719..94ba25c 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -18,6 +18,7 @@ (require 'db-customize) (require 'ox-icalendar) (require 'org-ql) +(require 'holidays) (autoload 'which-function "which-func") (autoload 'org-element-property "org-element") @@ -911,6 +912,23 @@ from now, the time spent on work is assumed to be zero." worked-today) 0)))) +(defun db/org-home-time-for-date (date-string) + "Return planned time for DATE-STRING to spend at home. + +DATE-STRING must be a date formatted as Org time stamp. The +returned time is given as an Org duration string." + ;; This is a simplification, as `date-string' might be the start of the day or the end. + (pcase-let ((`(_ _ _ ,day ,month ,year ,dow _ _) (parse-time-string date-string))) + (cond + ((let ((calendar-holidays (append holiday-general-holidays + holiday-christian-holidays))) + (calendar-check-holidays (list month day year))) + "8:00") + ((= dow 6) "8:00") ; Saturday + ((= dow 0) "6:00") ; Sunday, let's do not plan too much here + ((= dow 4) "3:00") ; Wednesday + (t "2:00")))) + ;;; Fixes