4

At the last weekday of the month I want to be reminded to prepare invoice/expenses so I get them filed by the first. It's no use just getting reminded on the last day of the month, if this is a Saturday or Sunday. Nor do I want to be reminded several days before the end of the month, so using diary-float is not applicable.

4

Answering myself, I came up with this. I created a function to detect whether a given date is the last weekday of the month.

There's two main cases: if it's the last day of the month and it's a weekday, then obviously it's the last weekday of the month. Otherwise, the last weekday of the month must be a Friday, and it will be either the last-but-one or last-but-two day of the month. This logic can be easily expressed in emacs-lisp (put it in your ~/.emacs):

(defun last-weekday-of-month-p (date)
  (let* ((day-of-week (calendar-day-of-week date))
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
         (last-month-day (calendar-last-day-of-month month year))
         (month-day (cadr date)))

    (or
     ;; it's the last day of the month & it is a weekday
     (and (eq month-day last-month-day)
          (memq day-of-week '(1 2 3 4 5)))

     ;; it's a friday, and it's the last-but-one or last-but-two day
     ;; of the month
     (and (eq day-of-week 5)
          (or (eq month-day (1- last-month-day))
              (eq month-day (1- (1- last-month-day))))))))

This can then be used from my Diary file like so:

%%(last-weekday-of-month-p date) File Invoice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.