~swflint/time-block-command

2b4795fb2e7ca5bdfdced7704411426372ad4fc0 — Samuel W. Flint 1 year, 2 months ago f6daeb2 v1.2.0
Clean up how holidays are ignored
2 files changed, 30 insertions(+), 10 deletions(-)

M README.md
M time-block.el
M README.md => README.md +4 -2
@@ 33,9 33,11 @@ group definition is an alist from days of the week (as numbers, Sunday
= 0/7, etc.) to lists of start/stop pairs (times in "HH:MM" form).

It is also possible to ignore time blocking on holidays.  This is
globally set using the `time-block-skip-on-holidays-p' variable.  This
globally set using the `time-block-skip-on-holidays-p` variable.  This
defaults to nil, which does not ignore blocking on holidays.  If set
to t, time blocking will be ignored on holidays.
to t, time blocking will be ignored on any holiday.  It may also be
set to a regular expression or a list.  Holidays which match either
representation will cause time blocking to be ignored.

### Defining Time Blocked Commands


M time-block.el => time-block.el +26 -8
@@ 2,7 2,7 @@

;; Author: Samuel W. Flint <swflint@flintfam.org>
;; URL: https://git.sr.ht/~swflint/time-block
;; Version: 1.1.0
;; Version: 1.2.0
;; Package-Requires: ((emacs "25.1") (ts "0.1"))
;; Keywords: tools, productivity, convenience



@@ 53,7 53,9 @@
;; It is also possible to ignore time blocking on holidays.  This is
;; globally set using the `time-block-skip-on-holidays-p' variable.
;; This defaults to nil, which does not ignore blocking on holidays.
;; If set to t, time blocking will be ignored on holidays.
;; If set to t, time blocking will be ignored on any holiday.  It may
;; also be set to a regular expression or a list.  Holidays which
;; match either representation will cause time blocking to be ignored.
;;
;;;; Defining Time Blocked Commands
;;


@@ 143,18 145,34 @@ Saturday   6"
(defcustom time-block-skip-on-holidays-p nil
  "If t skip checking for time blocking on holidays.  Default to nil."
  :group 'time-block
  :type '(choice (const :tag "Continue blocking on holidays." nil)
                 (const :tag "Do not block on holidays." t)))
  :type '(choice (const :tag "Continue blocking on holidays" nil)
                 (regexp :tag "Matching regexp")
                 (repeat :tag "Listed holidays" string)
                 (const :tag "All holidays" t)))


;; Utility Functions

(defun time-block-is-skipped-holiday-p ()
  "Determine if today is a skipped holiday."
  (when-let ((holidays time-block-skip-on-holidays-p)
             (holidays-today (calendar-check-holidays (list (ts-month (ts-now))
                                                            (ts-day (ts-now))
                                                            (ts-year (ts-now))))))
    (cond
     ((listp holidays)
      (cl-find-if #'(lambda (x)
                      (cl-member x holidays :test #'string=))
                  holidays-today))
     ((stringp holidays)
      (cl-find-if #'(lambda (x)
                      (string-match-p holidays x))
                  holidays-today))
     (t t))))

(defun time-block-group-blocked-p (block-group)
  "Is group BLOCK-GROUP currently blocked?"
  (unless (and time-block-skip-on-holidays-p
               (not (null (calendar-check-holidays (list (ts-month (ts-now))
                                                         (ts-day (ts-now))
                                                         (ts-year (ts-now)))))))
  (unless (time-block-is-skipped-holiday-p)
    (when-let ((group (cl-rest (assoc block-group time-block-groups)))
               (ts-now (ts-now))
               (current-day (ts-dow ts-now))