diff options
| -rw-r--r-- | lisp/calendar/lunar.el | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/lisp/calendar/lunar.el b/lisp/calendar/lunar.el index 468a3b25b06..b1ac809ec61 100644 --- a/lisp/calendar/lunar.el +++ b/lisp/calendar/lunar.el | |||
| @@ -27,8 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | ;;; Commentary: | 28 | ;;; Commentary: |
| 29 | 29 | ||
| 30 | ;; This collection of functions implements lunar phases for calendar.el and | 30 | ;; See calendar.el. |
| 31 | ;; diary.el. | ||
| 32 | 31 | ||
| 33 | ;; Based on ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus, | 32 | ;; Based on ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus, |
| 34 | ;; Willmann-Bell, Inc., 1985 and ``Astronomical Algorithms'' by Jean Meeus, | 33 | ;; Willmann-Bell, Inc., 1985 and ``Astronomical Algorithms'' by Jean Meeus, |
| @@ -39,10 +38,6 @@ | |||
| 39 | ;; The author would be delighted to have an astronomically more sophisticated | 38 | ;; The author would be delighted to have an astronomically more sophisticated |
| 40 | ;; person rewrite the code for the lunar calculations in this file! | 39 | ;; person rewrite the code for the lunar calculations in this file! |
| 41 | 40 | ||
| 42 | ;; Technical details of all the calendrical calculations can be found in | ||
| 43 | ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold | ||
| 44 | ;; and Nachum Dershowitz, Cambridge University Press (2001). | ||
| 45 | |||
| 46 | ;;; Code: | 41 | ;;; Code: |
| 47 | 42 | ||
| 48 | (require 'calendar) | 43 | (require 'calendar) |
| @@ -145,32 +140,33 @@ remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon, | |||
| 145 | 140 | ||
| 146 | (defun lunar-phase-list (month year) | 141 | (defun lunar-phase-list (month year) |
| 147 | "List of lunar phases for three months starting with Gregorian MONTH, YEAR." | 142 | "List of lunar phases for three months starting with Gregorian MONTH, YEAR." |
| 148 | (let ((end-month month) | 143 | (let* ((end-month month) |
| 149 | (end-year year) | 144 | (end-year year) |
| 150 | (start-month month) | 145 | (start-month month) |
| 151 | (start-year year)) | 146 | (start-year year) |
| 152 | (increment-calendar-month end-month end-year 3) | 147 | (end-date (progn |
| 153 | (increment-calendar-month start-month start-year -1) | 148 | (increment-calendar-month end-month end-year 3) |
| 154 | (let* ((end-date (list (list end-month 1 end-year))) | 149 | (list (list end-month 1 end-year)))) |
| 155 | (start-date (list (list start-month | 150 | (start-date (progn |
| 151 | (increment-calendar-month start-month start-year -1) | ||
| 152 | (list (list start-month | ||
| 156 | (calendar-last-day-of-month | 153 | (calendar-last-day-of-month |
| 157 | start-month start-year) | 154 | start-month start-year) |
| 158 | start-year))) | 155 | start-year)))) |
| 159 | (index (* 4 | 156 | (index (* 4 (truncate |
| 160 | (truncate | ||
| 161 | (* 12.3685 | 157 | (* 12.3685 |
| 162 | (+ year | 158 | (+ year |
| 163 | ( / (calendar-day-number (list month 1 year)) | 159 | ( / (calendar-day-number (list month 1 year)) |
| 164 | 366.0) | 160 | 366.0) |
| 165 | -1900))))) | 161 | -1900))))) |
| 166 | (new-moon (lunar-phase index)) | 162 | (new-moon (lunar-phase index)) |
| 167 | (list)) | 163 | list) |
| 168 | (while (calendar-date-compare new-moon end-date) | 164 | (while (calendar-date-compare new-moon end-date) |
| 169 | (if (calendar-date-compare start-date new-moon) | 165 | (if (calendar-date-compare start-date new-moon) |
| 170 | (setq list (append list (list new-moon)))) | 166 | (setq list (append list (list new-moon)))) |
| 171 | (setq index (1+ index) | 167 | (setq index (1+ index) |
| 172 | new-moon (lunar-phase index))) | 168 | new-moon (lunar-phase index))) |
| 173 | list))) | 169 | list)) |
| 174 | 170 | ||
| 175 | (defun lunar-phase-name (phase) | 171 | (defun lunar-phase-name (phase) |
| 176 | "Name of lunar PHASE. | 172 | "Name of lunar PHASE. |
| @@ -375,17 +371,18 @@ as governed by the values of `calendar-daylight-savings-starts', | |||
| 375 | (year (+ (extract-calendar-year date) | 371 | (year (+ (extract-calendar-year date) |
| 376 | (/ (calendar-day-number date) 365.25))) | 372 | (/ (calendar-day-number date) 365.25))) |
| 377 | (k (floor (* (- year 2000.0) 12.3685))) | 373 | (k (floor (* (- year 2000.0) 12.3685))) |
| 378 | (date (lunar-new-moon-time k))) | 374 | (date (lunar-new-moon-time k)) |
| 379 | (while (< date d) | 375 | (a-date (progn |
| 380 | (setq k (1+ k) | 376 | (while (< date d) |
| 381 | date (lunar-new-moon-time k))) | 377 | (setq k (1+ k) |
| 382 | (let* ((a-date (calendar-absolute-from-astro date)) | 378 | date (lunar-new-moon-time k))) |
| 383 | (time (* 24 (- a-date (truncate a-date)))) | 379 | (calendar-absolute-from-astro date))) |
| 384 | (date (calendar-gregorian-from-absolute (truncate a-date))) | 380 | (time (* 24 (- a-date (truncate a-date)))) |
| 385 | (adj (dst-adjust-time date time))) | 381 | (date (calendar-gregorian-from-absolute (truncate a-date))) |
| 386 | (calendar-astro-from-absolute | 382 | (adj (dst-adjust-time date time))) |
| 387 | (+ (calendar-absolute-from-gregorian (car adj)) | 383 | (calendar-astro-from-absolute |
| 388 | (/ (cadr adj) 24.0)))))) | 384 | (+ (calendar-absolute-from-gregorian (car adj)) |
| 385 | (/ (cadr adj) 24.0))))) | ||
| 389 | 386 | ||
| 390 | (provide 'lunar) | 387 | (provide 'lunar) |
| 391 | 388 | ||