From 7bead204f1ca7588b872fa684e08771dc04baee4 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Mon, 31 Mar 2008 15:39:20 +0000 Subject: [PATCH] (Commentary): Replace with reference to calendar.el. (holiday-islamic): Comments. Remove un-needed let. Use and. --- lisp/ChangeLog | 3 +++ lisp/calendar/cal-islam.el | 39 +++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 11848ffc6ce..4ce645dbbaa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -43,6 +43,9 @@ * calendar/cal-china.el (holiday-chinese-new-year): Doc fix. + * calendar/cal-islam.el (holiday-islamic): Remove un-needed let. + Use and. + * calendar/cal-julian.el (holiday-julian): Fix a problem with holidays in the last fortnight in Julian October. diff --git a/lisp/calendar/cal-islam.el b/lisp/calendar/cal-islam.el index e8f5235217d..ef6f6167e61 100644 --- a/lisp/calendar/cal-islam.el +++ b/lisp/calendar/cal-islam.el @@ -27,12 +27,7 @@ ;;; Commentary: -;; This collection of functions implements the features of calendar.el and -;; diary.el that deal with the Islamic calendar. - -;; Technical details of all the calendrical calculations can be found in -;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold -;; and Nachum Dershowitz, Cambridge University Press (2001). +;; See calendar.el. ;;; Code: @@ -187,6 +182,11 @@ Reads a year, month, and day." If MONTH, DAY (Islamic) is visible, the value returned is corresponding Gregorian date in the form of the list (((month day year) STRING)). Returns nil if it is not visible in the current calendar window." + ;; Islamic date corresponding to the center of the calendar window. + ;; Since the calendar displays 3 months at a time, there are approx + ;; 45 visible days either side of this date. Given the length of + ;; the Islamic months, this means up to two different months are + ;; visible either side of the central date. (let* ((islamic-date (calendar-islamic-from-absolute (calendar-absolute-from-gregorian (list displayed-month 15 displayed-year)))) @@ -194,12 +194,29 @@ nil if it is not visible in the current calendar window." (y (extract-calendar-year islamic-date)) date) (unless (< m 1) ; Islamic calendar doesn't apply + ;; Since converting to absolute dates can be a complex + ;; operation, we try to speed things up by excluding those date + ;; ranges that can't possibly be visible. + ;; We can view the situation (see above) as if we had a calendar + ;; window displaying 5 months at a time. When month m is + ;; central, months m-2:m+2 (modulo 12) might be visible. + ;; Recall from holiday-fixed that with a 3 month calendar + ;; window, November is special, because we can do a one-sided + ;; inclusion test. When November is central is when the end of + ;; year first appears on the calendar. Similarly, with a 5 + ;; month window, October is special. When October is central is + ;; when the end of year first appears, and when January is + ;; central, October is no longer visible. October is visible + ;; when the central month is >= 8. + ;; Hence to test if any given month might be visible, we can + ;; shift things and ask about October. + ;; At the same time, we work out the appropriate year y to use. (increment-calendar-month m y (- 10 month)) - (if (> m 7) ; Islamic date might be visible - (let ((date (calendar-gregorian-from-absolute - (calendar-absolute-from-islamic (list month day y))))) - (if (calendar-date-is-visible-p date) - (list (list date string)))))))) + (and (> m 7) ; Islamic date might be visible + (calendar-date-is-visible-p + (setq date (calendar-gregorian-from-absolute + (calendar-absolute-from-islamic (list month day y))))) + (list (list date string)))))) (autoload 'diary-list-entries-1 "diary-lib") -- 2.39.5