Function: calendar-bahai-from-absolute

calendar-bahai-from-absolute is a byte-compiled function defined in cal-bahai.el.gz.

Signature

(calendar-bahai-from-absolute DATE)

Documentation

Bahá’í date (month day year) corresponding to the absolute DATE.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/cal-bahai.el.gz
(defun calendar-bahai-from-absolute (date)
  "Bahá’í date (month day year) corresponding to the absolute DATE."
  (if (< date calendar-bahai-epoch)
      (list 0 0 0)                      ; pre-Bahá’í date
    (let* ((greg (calendar-gregorian-from-absolute date))
           (gmonth (calendar-extract-month greg))
           (gyear (calendar-extract-year greg))
           (gday (calendar-extract-day greg))
           ;; Estimate the Bahá’í year
           (year (+ (- gyear 1844)
                    (if (or (> gmonth 3)
                            (and (= gmonth 3) (>= gday 15)))
                        1 0))))
      ;; Adjust year if needed based on actual Naw-Rúz
      (while (< date (calendar-bahai-nawruz year))
        (setq year (1- year)))
      (while (>= date (calendar-bahai-nawruz (1+ year)))
        (setq year (1+ year)))
      ;; Now calculate month and day within the year
      (let* ((year-start (calendar-bahai-nawruz year))
             (days-in-year (- date year-start))
             (ayyam-ha-days (if (calendar-bahai-leap-year-p year) 5 4))
             month day)
        (cond
         ;; In first 18 months (days 0-341)
         ((< days-in-year (* 19 18))
          (setq month (1+ (/ days-in-year 19))
                day (1+ (% days-in-year 19))))
         ;; In Ayyám-i-Há (days 342-345 or 342-346)
         ((< days-in-year (+ (* 19 18) ayyam-ha-days))
          ;; Encode Ayyám-i-Há as month 19 with day <= 0
          ;; First day is -(ayyam-ha-days-1), last day is 0
          (let ((ayyam-day (- days-in-year (* 19 18))))
            (setq month 19
                  day (- ayyam-day (1- ayyam-ha-days)))))
         ;; In month 19 ('Alá')
         (t
          (setq month 19
                day (1+ (- days-in-year (* 19 18) ayyam-ha-days)))))
        (list month day year)))))