Mercurial > emacs
comparison lisp/calendar/cal-mayan.el @ 93484:0c5143f2417b
(Commentary): Point to calendar.el.
(calendar-string-to-mayan-long-count, calendar-goto-mayan-long-count-date):
Simplify.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 01 Apr 2008 02:42:05 +0000 |
parents | 6c85b8971fe3 |
children | 8b04f0b12fa3 |
comparison
equal
deleted
inserted
replaced
93483:a4a2b2f63116 | 93484:0c5143f2417b |
---|---|
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | 27 ;; Boston, MA 02110-1301, USA. |
28 | 28 |
29 ;;; Commentary: | 29 ;;; Commentary: |
30 | 30 |
31 ;; This collection of functions implements the features of calendar.el and | 31 ;; See calendar.el. |
32 ;; diary.el that deal with the Mayan calendar. It was written jointly by | |
33 | |
34 ;; Stewart M. Clamen School of Computer Science | |
35 ;; clamen@cs.cmu.edu Carnegie Mellon University | |
36 ;; 5000 Forbes Avenue | |
37 ;; Pittsburgh, PA 15213 | |
38 | |
39 ;; and | |
40 | |
41 ;; Edward M. Reingold Department of Computer Science | |
42 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
43 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
44 ;; Urbana, Illinois 61801 | |
45 | |
46 ;; Technical details of the Mayan calendrical calculations can be found in | |
47 ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold | |
48 ;; and Nachum Dershowitz, Cambridge University Press (2001), and in | |
49 ;; ``Calendrical Calculations, Part II: Three Historical Calendars'' | |
50 ;; by E. M. Reingold, N. Dershowitz, and S. M. Clamen, | |
51 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993), | |
52 ;; pages 383-404. | |
53 | 32 |
54 ;;; Code: | 33 ;;; Code: |
55 | 34 |
56 (require 'calendar) | 35 (require 'calendar) |
57 | 36 |
94 "Convert MAYAN-LONG-COUNT into traditional written form." | 73 "Convert MAYAN-LONG-COUNT into traditional written form." |
95 (apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count))) | 74 (apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count))) |
96 | 75 |
97 (defun calendar-string-to-mayan-long-count (str) | 76 (defun calendar-string-to-mayan-long-count (str) |
98 "Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of numbers." | 77 "Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of numbers." |
99 (let ((c (length str)) | 78 (let ((end 0) |
100 (cc 0) | |
101 rlc) | 79 rlc) |
102 (condition-case condition | 80 (condition-case nil |
103 (progn | 81 (progn |
104 (while (< cc c) | 82 ;; cf split-string. |
105 (let* ((start (string-match "[0-9]+" str cc)) | 83 (while (string-match "[0-9]+" str end) |
106 (end (match-end 0)) | 84 (setq rlc (cons (string-to-number (match-string 0 str)) rlc) |
107 (datum (read (substring str start end)))) | 85 end (match-end 0))) |
108 (setq rlc (cons datum rlc) | |
109 cc end))) | |
110 (unless (= (length rlc) 5) (signal 'invalid-read-syntax nil))) | 86 (unless (= (length rlc) 5) (signal 'invalid-read-syntax nil))) |
111 (invalid-read-syntax nil)) | 87 (invalid-read-syntax nil)) |
112 (reverse rlc))) | 88 (nreverse rlc))) |
113 | 89 |
114 (defun calendar-mayan-haab-from-absolute (date) | 90 (defun calendar-mayan-haab-from-absolute (date) |
115 "Convert absolute DATE into a Mayan haab date (a pair)." | 91 "Convert absolute DATE into a Mayan haab date (a pair)." |
116 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) | 92 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) |
117 (day-of-haab | 93 (day-of-haab |
359 ;;;###cal-autoload | 335 ;;;###cal-autoload |
360 (defun calendar-goto-mayan-long-count-date (date &optional noecho) | 336 (defun calendar-goto-mayan-long-count-date (date &optional noecho) |
361 "Move cursor to Mayan long count DATE. | 337 "Move cursor to Mayan long count DATE. |
362 Echo Mayan date unless NOECHO is non-nil." | 338 Echo Mayan date unless NOECHO is non-nil." |
363 (interactive | 339 (interactive |
364 (let (lc) | 340 (let (datum) |
365 (while (not lc) | 341 (while (not (setq datum |
366 (let ((datum | 342 (calendar-string-to-mayan-long-count |
367 (calendar-string-to-mayan-long-count | 343 (read-string |
368 (read-string "Mayan long count (baktun.katun.tun.uinal.kin): " | 344 "Mayan long count (baktun.katun.tun.uinal.kin): " |
369 (calendar-mayan-long-count-to-string | 345 (calendar-mayan-long-count-to-string |
370 (calendar-mayan-long-count-from-absolute | 346 (calendar-mayan-long-count-from-absolute |
371 (calendar-absolute-from-gregorian | 347 (calendar-absolute-from-gregorian |
372 (calendar-current-date)))))))) | 348 (calendar-current-date)))))) |
373 (if (calendar-mayan-long-count-common-era datum) | 349 datum (if (calendar-mayan-long-count-common-era datum) |
374 (setq lc datum)))) | 350 (list datum))))) |
375 (list lc))) | 351 datum)) |
376 (calendar-goto-date | 352 (calendar-goto-date |
377 (calendar-gregorian-from-absolute | 353 (calendar-gregorian-from-absolute |
378 (calendar-absolute-from-mayan-long-count date))) | 354 (calendar-absolute-from-mayan-long-count date))) |
379 (or noecho (calendar-print-mayan-date))) | 355 (or noecho (calendar-print-mayan-date))) |
380 | 356 |