Mercurial > emacs
annotate lisp/calendar/cal-mayan.el @ 93111:f84051049637
* intervals.c (temp_set_point, temp_set_point_both): Use EMACS_INT.
(set_point, set_point_both): Use EMACS_INT. Remove `buffer' arg,
work on current_buffer only instead (that was already the case
for some of the code anyway).
* buffer.h (set_point, set_point_both): Remove buffer arg, use long int.
(temp_set_point, temp_set_point_both): Use EMACS_INT.
(SET_PT, SET_PT_BOTH): Adjust.
* intervals.h (set_point, temp_set_point, set_point_both)
(temp_set_point_both): Remove redundant declarations.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 20 Mar 2008 18:38:34 +0000 |
parents | 6c85b8971fe3 |
children | 0c5143f2417b |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
24185
diff
changeset
|
1 ;;; cal-mayan.el --- calendar functions for the Mayan calendars |
957 | 2 |
68721 | 3 ;; Copyright (C) 1992, 1993, 1995, 1997, 2001, 2002, 2003, 2004, 2005, |
79703 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
957 | 5 |
6 ;; Author: Stewart M. Clamen <clamen@cs.cmu.edu> | |
92853 | 7 ;; Edward M. Reingold <reingold@cs.uiuc.edu> |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65145
diff
changeset
|
8 ;; Maintainer: Glenn Morris <rgm@gnu.org> |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2106
diff
changeset
|
9 ;; Keywords: calendar |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2106
diff
changeset
|
10 ;; Human-Keywords: Mayan calendar, Maya, calendar, diary |
957 | 11 |
12 ;; This file is part of GNU Emacs. | |
13 | |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
14 ;; GNU Emacs is free software; you can redistribute it and/or modify |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
15 ;; it under the terms of the GNU General Public License as published by |
78216
93e11478c954
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
16 ;; the Free Software Foundation; either version 3, or (at your option) |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
17 ;; any later version. |
957 | 18 |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
19 ;; GNU Emacs is distributed in the hope that it will be useful, |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
22 ;; GNU General Public License for more details. |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
23 |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
14169 | 25 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
957 | 28 |
29 ;;; Commentary: | |
30 | |
31 ;; This collection of functions implements the features of calendar.el and | |
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 | |
61148
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
54077
diff
changeset
|
47 ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold |
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
54077
diff
changeset
|
48 ;; and Nachum Dershowitz, Cambridge University Press (2001), and in |
957 | 49 ;; ``Calendrical Calculations, Part II: Three Historical Calendars'' |
50 ;; by E. M. Reingold, N. Dershowitz, and S. M. Clamen, | |
2945
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
2247
diff
changeset
|
51 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993), |
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
2247
diff
changeset
|
52 ;; pages 383-404. |
957 | 53 |
54 ;;; Code: | |
55 | |
56 (require 'calendar) | |
57 | |
19972
fe92da0414ac
(calendar-mayan-days-before-absolute-zero): Change
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
58 (defconst calendar-mayan-days-before-absolute-zero 1137142 |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
59 "Number of days of the Mayan calendar epoch before absolute day 0. |
19972
fe92da0414ac
(calendar-mayan-days-before-absolute-zero): Change
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
60 This is the Goodman-Martinez-Thompson correlation used by almost all experts, |
fe92da0414ac
(calendar-mayan-days-before-absolute-zero): Change
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
61 but some use 1137140. Using 1232041 gives you Spinden's correlation; using |
fe92da0414ac
(calendar-mayan-days-before-absolute-zero): Change
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
62 1142840 gives you Hochleitner's correlation.") |
957 | 63 |
64 (defconst calendar-mayan-haab-at-epoch '(8 . 18) | |
65 "Mayan haab date at the epoch.") | |
66 | |
67 (defconst calendar-mayan-haab-month-name-array | |
68 ["Pop" "Uo" "Zip" "Zotz" "Tzec" "Xul" "Yaxkin" "Mol" "Chen" "Yax" | |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
69 "Zac" "Ceh" "Mac" "Kankin" "Muan" "Pax" "Kayab" "Cumku"] |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
70 "Names of the Mayan haab months.") |
957 | 71 |
72 (defconst calendar-mayan-tzolkin-at-epoch '(4 . 20) | |
73 "Mayan tzolkin date at the epoch.") | |
74 | |
75 (defconst calendar-mayan-tzolkin-names-array | |
76 ["Imix" "Ik" "Akbal" "Kan" "Chicchan" "Cimi" "Manik" "Lamat" "Muluc" "Oc" | |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
77 "Chuen" "Eb" "Ben" "Ix" "Men" "Cib" "Caban" "Etznab" "Cauac" "Ahau"] |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
78 "Names of the Mayan tzolkin months.") |
957 | 79 |
80 (defun calendar-mayan-long-count-from-absolute (date) | |
81 "Compute the Mayan long count corresponding to the absolute DATE." | |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
82 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
83 (baktun (/ long-count 144000)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
84 (remainder (% long-count 144000)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
85 (katun (/ remainder 7200)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
86 (remainder (% remainder 7200)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
87 (tun (/ remainder 360)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
88 (remainder (% remainder 360)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
89 (uinal (/ remainder 20)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
90 (kin (% remainder 20))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
91 (list baktun katun tun uinal kin))) |
957 | 92 |
93 (defun calendar-mayan-long-count-to-string (mayan-long-count) | |
94 "Convert MAYAN-LONG-COUNT into traditional written form." | |
95 (apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count))) | |
96 | |
97 (defun calendar-string-to-mayan-long-count (str) | |
92636
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
98 "Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of numbers." |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
99 (let ((c (length str)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
100 (cc 0) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
101 rlc) |
957 | 102 (condition-case condition |
103 (progn | |
104 (while (< cc c) | |
92853 | 105 (let* ((start (string-match "[0-9]+" str cc)) |
106 (end (match-end 0)) | |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
107 (datum (read (substring str start end)))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
108 (setq rlc (cons datum rlc) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
109 cc end))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
110 (unless (= (length rlc) 5) (signal 'invalid-read-syntax nil))) |
957 | 111 (invalid-read-syntax nil)) |
112 (reverse rlc))) | |
113 | |
114 (defun calendar-mayan-haab-from-absolute (date) | |
115 "Convert absolute DATE into a Mayan haab date (a pair)." | |
116 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) | |
117 (day-of-haab | |
118 (% (+ long-count | |
119 (car calendar-mayan-haab-at-epoch) | |
120 (* 20 (1- (cdr calendar-mayan-haab-at-epoch)))) | |
121 365)) | |
122 (day (% day-of-haab 20)) | |
123 (month (1+ (/ day-of-haab 20)))) | |
124 (cons day month))) | |
125 | |
126 (defun calendar-mayan-haab-difference (date1 date2) | |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
127 "Number of days from Mayan haab DATE1 to next occurrence of haab date DATE2." |
4521
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
128 (mod (+ (* 20 (- (cdr date2) (cdr date1))) |
92853 | 129 (- (car date2) (car date1))) |
4521
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
130 365)) |
957 | 131 |
132 (defun calendar-mayan-haab-on-or-before (haab-date date) | |
133 "Absolute date of latest HAAB-DATE on or before absolute DATE." | |
2106
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
134 (- date |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
135 (% (- date |
92853 | 136 (calendar-mayan-haab-difference |
137 (calendar-mayan-haab-from-absolute 0) haab-date)) | |
138 365))) | |
957 | 139 |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
140 ;;;###cal-autoload |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
141 (defun calendar-mayan-date-string (&optional date) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
142 "String of Mayan date of Gregorian DATE; default today." |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
143 (let* ((d (calendar-absolute-from-gregorian |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
144 (or date (calendar-current-date)))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
145 (tzolkin (calendar-mayan-tzolkin-from-absolute d)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
146 (haab (calendar-mayan-haab-from-absolute d)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
147 (long-count (calendar-mayan-long-count-from-absolute d))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
148 (format "Long count = %s; tzolkin = %s; haab = %s" |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
149 (calendar-mayan-long-count-to-string long-count) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
150 (calendar-mayan-tzolkin-to-string tzolkin) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
151 (calendar-mayan-haab-to-string haab)))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
152 |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
153 ;;;###cal-autoload |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
154 (defun calendar-print-mayan-date () |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
155 "Show the Mayan long count, tzolkin, and haab equivalents of date." |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
156 (interactive) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
157 (message "Mayan date: %s" |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
158 (calendar-mayan-date-string (calendar-cursor-to-date t)))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
159 |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
160 (defun calendar-read-mayan-haab-date () |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
161 "Prompt for a Mayan haab date." |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
162 (let* ((completion-ignore-case t) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
163 (haab-day (calendar-read |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
164 "Haab kin (0-19): " |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
165 (lambda (x) (and (>= x 0) (< x 20))))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
166 (haab-month-list (append calendar-mayan-haab-month-name-array |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
167 (and (< haab-day 5) '("Uayeb")))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
168 (haab-month (cdr |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
169 (assoc-string |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
170 (completing-read "Haab uinal: " |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
171 (mapcar 'list haab-month-list) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
172 nil t) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
173 (calendar-make-alist haab-month-list 1) t)))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
174 (cons haab-day haab-month))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
175 |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
176 (defun calendar-read-mayan-tzolkin-date () |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
177 "Prompt for a Mayan tzolkin date." |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
178 (let* ((completion-ignore-case t) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
179 (tzolkin-count (calendar-read |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
180 "Tzolkin kin (1-13): " |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
181 (lambda (x) (and (> x 0) (< x 14))))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
182 (tzolkin-name-list (append calendar-mayan-tzolkin-names-array nil)) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
183 (tzolkin-name (cdr |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
184 (assoc-string |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
185 (completing-read "Tzolkin uinal: " |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
186 (mapcar 'list tzolkin-name-list) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
187 nil t) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
188 (calendar-make-alist tzolkin-name-list 1) t)))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
189 (cons tzolkin-count tzolkin-name))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
190 |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
191 ;;;###cal-autoload |
957 | 192 (defun calendar-next-haab-date (haab-date &optional noecho) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
193 "Move cursor to next instance of Mayan HAAB-DATE. |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
194 Echo Mayan date unless NOECHO is non-nil." |
957 | 195 (interactive (list (calendar-read-mayan-haab-date))) |
196 (calendar-goto-date | |
197 (calendar-gregorian-from-absolute | |
198 (calendar-mayan-haab-on-or-before | |
199 haab-date | |
200 (+ 365 | |
201 (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
202 (or noecho (calendar-print-mayan-date))) | |
203 | |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
204 ;;;###cal-autoload |
957 | 205 (defun calendar-previous-haab-date (haab-date &optional noecho) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
206 "Move cursor to previous instance of Mayan HAAB-DATE. |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
207 Echo Mayan date unless NOECHO is non-nil." |
957 | 208 (interactive (list (calendar-read-mayan-haab-date))) |
209 (calendar-goto-date | |
210 (calendar-gregorian-from-absolute | |
211 (calendar-mayan-haab-on-or-before | |
212 haab-date | |
213 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
214 (or noecho (calendar-print-mayan-date))) | |
215 | |
216 (defun calendar-mayan-haab-to-string (haab) | |
92636
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
217 "Convert Mayan HAAB date (a pair) into its traditional written form." |
93001
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
218 (let ((month (cdr haab))) |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
219 (format "%d %s" (car haab) ; day |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
220 ;; 19th month consists of 5 special days |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
221 (if (= month 19) "Uayeb" |
92853 | 222 (aref calendar-mayan-haab-month-name-array (1- month)))))) |
957 | 223 |
224 (defun calendar-mayan-tzolkin-from-absolute (date) | |
225 "Convert absolute DATE into a Mayan tzolkin date (a pair)." | |
226 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) | |
93001
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
227 ;; Remainder on division by 13,20 with 13,20 instead of zero. |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
228 (day (1+ (mod |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
229 (1- (+ long-count (car calendar-mayan-tzolkin-at-epoch))) |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
230 13))) |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
231 (name (1+ (mod |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
232 (1- (+ long-count (cdr calendar-mayan-tzolkin-at-epoch))) |
6c85b8971fe3
(calendar-mayan-haab-to-string): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92920
diff
changeset
|
233 20)))) |
957 | 234 (cons day name))) |
235 | |
236 (defun calendar-mayan-tzolkin-difference (date1 date2) | |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
237 "Number of days from Mayan tzolkin DATE1 to next occurrence of tzolkin DATE2." |
957 | 238 (let ((number-difference (- (car date2) (car date1))) |
239 (name-difference (- (cdr date2) (cdr date1)))) | |
4521
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
240 (mod (+ number-difference |
92853 | 241 (* 13 (mod (* 3 (- number-difference name-difference)) |
242 20))) | |
243 260))) | |
957 | 244 |
245 (defun calendar-mayan-tzolkin-on-or-before (tzolkin-date date) | |
246 "Absolute date of latest TZOLKIN-DATE on or before absolute DATE." | |
2106
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
247 (- date |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
248 (% (- date (calendar-mayan-tzolkin-difference |
92853 | 249 (calendar-mayan-tzolkin-from-absolute 0) |
250 tzolkin-date)) | |
251 260))) | |
957 | 252 |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
253 ;;;###cal-autoload |
957 | 254 (defun calendar-next-tzolkin-date (tzolkin-date &optional noecho) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
255 "Move cursor to next instance of Mayan TZOLKIN-DATE. |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
256 Echo Mayan date unless NOECHO is non-nil." |
957 | 257 (interactive (list (calendar-read-mayan-tzolkin-date))) |
258 (calendar-goto-date | |
259 (calendar-gregorian-from-absolute | |
260 (calendar-mayan-tzolkin-on-or-before | |
261 tzolkin-date | |
262 (+ 260 | |
263 (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
264 (or noecho (calendar-print-mayan-date))) | |
265 | |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
266 ;;;###cal-autoload |
957 | 267 (defun calendar-previous-tzolkin-date (tzolkin-date &optional noecho) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
268 "Move cursor to previous instance of Mayan TZOLKIN-DATE. |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
269 Echo Mayan date unless NOECHO is non-nil." |
957 | 270 (interactive (list (calendar-read-mayan-tzolkin-date))) |
271 (calendar-goto-date | |
272 (calendar-gregorian-from-absolute | |
273 (calendar-mayan-tzolkin-on-or-before | |
274 tzolkin-date | |
275 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
276 (or noecho (calendar-print-mayan-date))) | |
277 | |
278 (defun calendar-mayan-tzolkin-to-string (tzolkin) | |
92636
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
279 "Convert Mayan TZOLKIN date (a pair) into its traditional written form." |
957 | 280 (format "%d %s" |
281 (car tzolkin) | |
282 (aref calendar-mayan-tzolkin-names-array (1- (cdr tzolkin))))) | |
283 | |
284 (defun calendar-mayan-tzolkin-haab-on-or-before (tzolkin-date haab-date date) | |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
285 "Absolute date that is Mayan TZOLKIN-DATE and HAAB-DATE. |
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
286 Latest such date on or before DATE. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
287 Returns nil if such a tzolkin-haab combination is impossible." |
957 | 288 (let* ((haab-difference |
289 (calendar-mayan-haab-difference | |
290 (calendar-mayan-haab-from-absolute 0) | |
291 haab-date)) | |
292 (tzolkin-difference | |
293 (calendar-mayan-tzolkin-difference | |
294 (calendar-mayan-tzolkin-from-absolute 0) | |
295 tzolkin-date)) | |
296 (difference (- tzolkin-difference haab-difference))) | |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
297 (if (zerop (% difference 5)) |
957 | 298 (- date |
4521
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
299 (mod (- date |
92853 | 300 (+ haab-difference (* 365 difference))) |
301 18980)) | |
957 | 302 nil))) |
303 | |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
304 ;;;###cal-autoload |
92636
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
305 (defun calendar-next-calendar-round-date (tzolkin-date haab-date |
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
306 &optional noecho) |
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
307 "Move cursor to next instance of Mayan TZOLKIN-DATE HAAB-DATE combination. |
f565309f0cab
(calendar-string-to-mayan-long-count)
Glenn Morris <rgm@gnu.org>
parents:
92607
diff
changeset
|
308 Echo Mayan date unless NOECHO is non-nil." |
957 | 309 (interactive (list (calendar-read-mayan-tzolkin-date) |
310 (calendar-read-mayan-haab-date))) | |
311 (let ((date (calendar-mayan-tzolkin-haab-on-or-before | |
312 tzolkin-date haab-date | |
313 (+ 18980 (calendar-absolute-from-gregorian | |
314 (calendar-cursor-to-date)))))) | |
315 (if (not date) | |
316 (error "%s, %s does not exist in the Mayan calendar round" | |
317 (calendar-mayan-tzolkin-to-string tzolkin-date) | |
318 (calendar-mayan-haab-to-string haab-date)) | |
319 (calendar-goto-date (calendar-gregorian-from-absolute date)) | |
320 (or noecho (calendar-print-mayan-date))))) | |
321 | |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
322 ;;;###cal-autoload |
957 | 323 (defun calendar-previous-calendar-round-date |
324 (tzolkin-date haab-date &optional noecho) | |
13672
bb7e5d35f83b
(calendar-next-calendar-round-date, calendar-previous-calendar-round-date):
Paul Eggert <eggert@twinsun.com>
parents:
13048
diff
changeset
|
325 "Move to previous instance of Mayan TZOLKIN-DATE HAAB-DATE combination. |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
326 Echo Mayan date unless NOECHO is non-nil." |
957 | 327 (interactive (list (calendar-read-mayan-tzolkin-date) |
328 (calendar-read-mayan-haab-date))) | |
329 (let ((date (calendar-mayan-tzolkin-haab-on-or-before | |
330 tzolkin-date haab-date | |
331 (1- (calendar-absolute-from-gregorian | |
332 (calendar-cursor-to-date)))))) | |
333 (if (not date) | |
334 (error "%s, %s does not exist in the Mayan calendar round" | |
335 (calendar-mayan-tzolkin-to-string tzolkin-date) | |
336 (calendar-mayan-haab-to-string haab-date)) | |
337 (calendar-goto-date (calendar-gregorian-from-absolute date)) | |
338 (or noecho (calendar-print-mayan-date))))) | |
339 | |
340 (defun calendar-absolute-from-mayan-long-count (c) | |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
341 "Compute the absolute date corresponding to the Mayan Long Count C. |
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
342 Long count is a list (baktun katun tun uinal kin)" |
92853 | 343 (+ (* (nth 0 c) 144000) ; baktun |
344 (* (nth 1 c) 7200) ; katun | |
345 (* (nth 2 c) 360) ; tun | |
346 (* (nth 3 c) 20) ; uinal | |
347 (nth 4 c) ; kin (days) | |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
348 ;; Days before absolute date 0. |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
349 (- calendar-mayan-days-before-absolute-zero))) |
957 | 350 |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
351 (defun calendar-mayan-long-count-common-era (lc) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
352 "Return non-nil if long count LC represents a date in the Common Era." |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
353 (let ((base (calendar-mayan-long-count-from-absolute 1))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
354 (while (and base (= (car lc) (car base))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
355 (setq lc (cdr lc) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
356 base (cdr base))) |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
357 (or (null lc) (> (car lc) (car base))))) |
957 | 358 |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
359 ;;;###cal-autoload |
957 | 360 (defun calendar-goto-mayan-long-count-date (date &optional noecho) |
92920
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
361 "Move cursor to Mayan long count DATE. |
cb0aac9dd8a3
(calendar-mayan-haab-month-name-array)
Glenn Morris <rgm@gnu.org>
parents:
92853
diff
changeset
|
362 Echo Mayan date unless NOECHO is non-nil." |
957 | 363 (interactive |
364 (let (lc) | |
365 (while (not lc) | |
366 (let ((datum | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
367 (calendar-string-to-mayan-long-count |
957 | 368 (read-string "Mayan long count (baktun.katun.tun.uinal.kin): " |
369 (calendar-mayan-long-count-to-string | |
370 (calendar-mayan-long-count-from-absolute | |
92853 | 371 (calendar-absolute-from-gregorian |
372 (calendar-current-date)))))))) | |
957 | 373 (if (calendar-mayan-long-count-common-era datum) |
374 (setq lc datum)))) | |
375 (list lc))) | |
376 (calendar-goto-date | |
377 (calendar-gregorian-from-absolute | |
378 (calendar-absolute-from-mayan-long-count date))) | |
379 (or noecho (calendar-print-mayan-date))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
380 |
92607 | 381 (defvar date) |
382 | |
383 ;; To be called from list-sexp-diary-entries, where DATE is bound. | |
92835
5e8d6a369c62
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92636
diff
changeset
|
384 ;;;###diary-autoload |
957 | 385 (defun diary-mayan-date () |
386 "Show the Mayan long count, haab, and tzolkin dates as a diary entry." | |
5700
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
387 (format "Mayan date: %s" (calendar-mayan-date-string date))) |
957 | 388 |
389 (provide 'cal-mayan) | |
390 | |
92589
c11e81a389cf
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
391 ;; arch-tag: 54f35144-cd0f-4873-935a-a60129de07df |
957 | 392 ;;; cal-mayan.el ends here |