emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/calendar/cal-islam.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/calendar/cal-islam.el,v
Date: Mon, 31 Mar 2008 15:37:52 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       08/03/31 15:37:52

Index: cal-islam.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/calendar/cal-islam.el,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- cal-islam.el        29 Mar 2008 02:43:32 -0000      1.41
+++ cal-islam.el        31 Mar 2008 15:37:52 -0000      1.42
@@ -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 @@
 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 @@
          (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
+      (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)))))
-            (if (calendar-date-is-visible-p date)
-                (list (list date string))))))))
+           (list (list date string))))))
 
 (autoload 'diary-list-entries-1 "diary-lib")
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]