Function: math-from-business-day
math-from-business-day is an autoloaded and byte-compiled function
defined in calc-forms.el.gz.
Signature
(math-from-business-day NUM)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-forms.el.gz
;;; Compute the date a certain number of business days since Jan 1, 1 AD.
;;; If this returns nil, holiday table was adjusted; redo calculation.
(defun math-from-business-day (num)
(let* ((day (math-floor num))
(time (math-sub num day)))
(or (integerp day)
(math-reject-arg nil "*Date is outside valid range"))
(math-setup-holidays)
(let ((days (nth 1 math-holidays-cache))
(delta 0))
(while (and (setq days (cdr days)) (< (car days) day))
(setq delta (1+ delta)))
(setq day (+ day delta)))
(let* ((weekdays (nth 3 math-holidays-cache))
(bweek (- 7 (length weekdays))) ; Business days in a week, 1..7.
(weeks (/ day bweek)) ; Whole weeks.
(wkday (mod day bweek)) ; Business day in last week, 0..bweek-1
(w 0))
(setq day (+ day (* weeks (length weekdays))))
;; Add business days in the last week; `w' is weekday, 0..6.
(while (if (memq w weekdays)
(setq day (1+ day))
(>= (setq wkday (1- wkday)) 0))
(setq w (1+ w)))
(let ((hours (nth 7 math-holidays-cache)))
(if hours
(setq time (math-add (math-mul time (cdr hours)) (car hours)))))
(and (not (math-setup-holidays day))
(list 'date (math-add day time))))))