Function: holiday-float

holiday-float is a byte-compiled function defined in holidays.el.gz.

Signature

(holiday-float MONTH DAYNAME N STRING &optional DAY)

Documentation

Holiday called STRING on the Nth DAYNAME after/before MONTH DAY.

DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on. If N>0, use the Nth DAYNAME after MONTH DAY. If N<0, use the Nth DAYNAME before MONTH DAY. DAY defaults to 1 if N>0, and MONTH's last day otherwise. If the holiday is visible in the calendar window, returns a list (((month day year) STRING)). Otherwise returns nil.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/holidays.el.gz
(defun holiday-float (month dayname n string &optional day)
  "Holiday called STRING on the Nth DAYNAME after/before MONTH DAY.
DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
If N>0, use the Nth DAYNAME after MONTH DAY.
If N<0, use the Nth DAYNAME before MONTH DAY.
DAY defaults to 1 if N>0, and MONTH's last day otherwise.
If the holiday is visible in the calendar window, returns a
list (((month day year) STRING)).  Otherwise returns nil."
  ;; This is messy because the holiday may be visible, while the date
  ;; on which it is based is not.  For example, the first Monday after
  ;; December 30 may be visible when January is not.  For large values
  ;; of |n| the problem is more grotesque.  If we didn't have to worry
  ;; about such cases, we could just use the original version of this
  ;; function:
  ;;  (let ((m displayed-month)
  ;;        (y displayed-year))
  ;;    (calendar-increment-month m y (- 11 month))
  ;;    (if (> m 9); month in year y is visible
  ;;      (list (list (calendar-nth-named-day n dayname month y day) string)))))
  (let* ((m1 displayed-month)
         (y1 displayed-year)
         (m2 displayed-month)
         (y2 displayed-year)
         (d1 (progn             ; first possible base date for holiday
               (calendar-increment-month m1 y1 -1)
               (+ (calendar-nth-named-absday 1 dayname m1 y1)
                  (* -7 n)
                  (if (> n 0) 1 -7))))
         (d2                     ; last possible base date for holiday
          (progn
            (calendar-increment-month m2 y2 1)
            (+ (calendar-nth-named-absday -1 dayname m2 y2)
               (* -7 n)
               (if (> n 0) 7 -1))))
         (y1 (calendar-extract-year (calendar-gregorian-from-absolute d1)))
         (y2 (calendar-extract-year (calendar-gregorian-from-absolute d2)))
         (y                             ; year of base date
          (if (or (= y1 y2) (> month 9))
              y1
            y2))
         (d                             ; day of base date
          (or day (if (> n 0)
                      1
                    (calendar-last-day-of-month month y))))
         (date                        ; base date for holiday
          (calendar-absolute-from-gregorian (list month d y))))
    (and (<= d1 date) (<= date d2)
         (list (list (calendar-nth-named-day n dayname month y d)
                     string)))))