Skip to content

Instantly share code, notes, and snippets.

@edenc
Last active June 25, 2023 23:02
Show Gist options
  • Save edenc/f366866237bbc68ba47388f28f95e55c to your computer and use it in GitHub Desktop.
Save edenc/f366866237bbc68ba47388f28f95e55c to your computer and use it in GitHub Desktop.
;; * TODO receber salário no quinto dia útil do mês
;; DEADLINE: <%%(nth-weekday-of-month-p date 5)>
;;
;; requer configuração das variáveis calendar-holidays ou holiday-*
(defun nth-weekday-of-month-p (date &optional n)
"Check if DATE is the Nth weekday of current month."
(or n (setq n 1))
(let* ((month (calendar-extract-month date))
(year (calendar-extract-year date))
(day (calendar-extract-day date))
(month-days-to-n (mapcar
(lambda (day)
`(,month ,day ,year))
(number-sequence 1 day)))
(business-days (seq-filter
(lambda (date)
(and (memq (calendar-day-of-week date)
'(1 2 3 4 5))
(not (calendar-check-holidays date))))
month-days-to-n)))
(and (eq n (length business-days))
(eq day (calendar-extract-day (car (last business-days)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment