Mercurial > emacs
annotate lisp/calendar/cal-mayan.el @ 75786:732f9b589f8e
(change-major-mode-with-file-name): Fix typo in docstring.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Sun, 11 Feb 2007 02:28:57 +0000 |
parents | 7a3f13e2dd57 |
children | 345c5cf4990e 95d0cdf160ea |
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, |
75346 | 4 ;; 2006, 2007 Free Software Foundation, Inc. |
957 | 5 |
6 ;; Author: Stewart M. Clamen <clamen@cs.cmu.edu> | |
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 |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6006
diff
changeset
|
16 ;; the Free Software Foundation; either version 2, or (at your option) |
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 ;; Comments, improvements, and bug reports should be sent to Reingold. | |
47 | |
48 ;; 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
|
49 ;; ``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
|
50 ;; and Nachum Dershowitz, Cambridge University Press (2001), and in |
957 | 51 ;; ``Calendrical Calculations, Part II: Three Historical Calendars'' |
52 ;; 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
|
53 ;; 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
|
54 ;; pages 383-404. |
957 | 55 |
56 ;;; Code: | |
57 | |
65145
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
58 (defvar date) |
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
59 |
957 | 60 (require 'calendar) |
61 | |
19972
fe92da0414ac
(calendar-mayan-days-before-absolute-zero): Change
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
62 (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
|
63 "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
|
64 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
|
65 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
|
66 1142840 gives you Hochleitner's correlation.") |
957 | 67 |
68 (defconst calendar-mayan-haab-at-epoch '(8 . 18) | |
69 "Mayan haab date at the epoch.") | |
70 | |
71 (defconst calendar-mayan-haab-month-name-array | |
72 ["Pop" "Uo" "Zip" "Zotz" "Tzec" "Xul" "Yaxkin" "Mol" "Chen" "Yax" | |
73 "Zac" "Ceh" "Mac" "Kankin" "Muan" "Pax" "Kayab" "Cumku"]) | |
74 | |
75 (defconst calendar-mayan-tzolkin-at-epoch '(4 . 20) | |
76 "Mayan tzolkin date at the epoch.") | |
77 | |
78 (defconst calendar-mayan-tzolkin-names-array | |
79 ["Imix" "Ik" "Akbal" "Kan" "Chicchan" "Cimi" "Manik" "Lamat" "Muluc" "Oc" | |
80 "Chuen" "Eb" "Ben" "Ix" "Men" "Cib" "Caban" "Etznab" "Cauac" "Ahau"]) | |
81 | |
82 (defun calendar-mayan-long-count-from-absolute (date) | |
83 "Compute the Mayan long count corresponding to the absolute DATE." | |
84 (let ((long-count (+ date calendar-mayan-days-before-absolute-zero))) | |
85 (let* ((baktun (/ long-count 144000)) | |
86 (remainder (% long-count 144000)) | |
87 (katun (/ remainder 7200)) | |
88 (remainder (% remainder 7200)) | |
89 (tun (/ remainder 360)) | |
90 (remainder (% remainder 360)) | |
91 (uinal (/ remainder 20)) | |
92 (kin (% remainder 20))) | |
93 (list baktun katun tun uinal kin)))) | |
94 | |
95 (defun calendar-mayan-long-count-to-string (mayan-long-count) | |
96 "Convert MAYAN-LONG-COUNT into traditional written form." | |
97 (apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count))) | |
98 | |
99 (defun calendar-string-to-mayan-long-count (str) | |
100 "Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of nums." | |
101 (let ((rlc nil) | |
102 (c (length str)) | |
103 (cc 0)) | |
104 (condition-case condition | |
105 (progn | |
106 (while (< cc c) | |
6006
dc6d45202fb9
(calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents:
5834
diff
changeset
|
107 (let* ((start (string-match "[0-9]+" str cc)) |
dc6d45202fb9
(calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents:
5834
diff
changeset
|
108 (end (match-end 0)) |
dc6d45202fb9
(calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents:
5834
diff
changeset
|
109 datum) |
dc6d45202fb9
(calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents:
5834
diff
changeset
|
110 (setq datum (read (substring str start end))) |
dc6d45202fb9
(calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents:
5834
diff
changeset
|
111 (setq rlc (cons datum rlc)) |
dc6d45202fb9
(calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents:
5834
diff
changeset
|
112 (setq cc end))) |
957 | 113 (if (not (= (length rlc) 5)) (signal 'invalid-read-syntax nil))) |
114 (invalid-read-syntax nil)) | |
115 (reverse rlc))) | |
116 | |
117 (defun calendar-mayan-haab-from-absolute (date) | |
118 "Convert absolute DATE into a Mayan haab date (a pair)." | |
119 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) | |
120 (day-of-haab | |
121 (% (+ long-count | |
122 (car calendar-mayan-haab-at-epoch) | |
123 (* 20 (1- (cdr calendar-mayan-haab-at-epoch)))) | |
124 365)) | |
125 (day (% day-of-haab 20)) | |
126 (month (1+ (/ day-of-haab 20)))) | |
127 (cons day month))) | |
128 | |
129 (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
|
130 "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
|
131 (mod (+ (* 20 (- (cdr date2) (cdr date1))) |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
132 (- (car date2) (car date1))) |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
133 365)) |
957 | 134 |
135 (defun calendar-mayan-haab-on-or-before (haab-date date) | |
136 "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
|
137 (- date |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
138 (% (- date |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
139 (calendar-mayan-haab-difference |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
140 (calendar-mayan-haab-from-absolute 0) haab-date)) |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
141 365))) |
957 | 142 |
143 (defun calendar-next-haab-date (haab-date &optional noecho) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
144 "Move cursor to next instance of Mayan HAAB-DATE. |
957 | 145 Echo Mayan date if NOECHO is t." |
146 (interactive (list (calendar-read-mayan-haab-date))) | |
147 (calendar-goto-date | |
148 (calendar-gregorian-from-absolute | |
149 (calendar-mayan-haab-on-or-before | |
150 haab-date | |
151 (+ 365 | |
152 (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
153 (or noecho (calendar-print-mayan-date))) | |
154 | |
155 (defun calendar-previous-haab-date (haab-date &optional noecho) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
156 "Move cursor to previous instance of Mayan HAAB-DATE. |
957 | 157 Echo Mayan date if NOECHO is t." |
158 (interactive (list (calendar-read-mayan-haab-date))) | |
159 (calendar-goto-date | |
160 (calendar-gregorian-from-absolute | |
161 (calendar-mayan-haab-on-or-before | |
162 haab-date | |
163 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
164 (or noecho (calendar-print-mayan-date))) | |
165 | |
166 (defun calendar-mayan-haab-to-string (haab) | |
167 "Convert Mayan haab date (a pair) into its traditional written form." | |
168 (let ((month (cdr haab)) | |
169 (day (car haab))) | |
170 ;; 19th month consists of 5 special days | |
171 (if (= month 19) | |
172 (format "%d Uayeb" day) | |
173 (format "%d %s" | |
174 day | |
175 (aref calendar-mayan-haab-month-name-array (1- month)))))) | |
176 | |
177 (defun calendar-mayan-tzolkin-from-absolute (date) | |
178 "Convert absolute DATE into a Mayan tzolkin date (a pair)." | |
179 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero)) | |
13048
6c21adf788d5
Minor fixes.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
10131
diff
changeset
|
180 (day (calendar-mod |
957 | 181 (+ long-count (car calendar-mayan-tzolkin-at-epoch)) |
182 13)) | |
13048
6c21adf788d5
Minor fixes.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
10131
diff
changeset
|
183 (name (calendar-mod |
957 | 184 (+ long-count (cdr calendar-mayan-tzolkin-at-epoch)) |
185 20))) | |
186 (cons day name))) | |
187 | |
188 (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
|
189 "Number of days from Mayan tzolkin DATE1 to next occurrence of tzolkin DATE2." |
957 | 190 (let ((number-difference (- (car date2) (car date1))) |
191 (name-difference (- (cdr date2) (cdr date1)))) | |
4521
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
192 (mod (+ number-difference |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
193 (* 13 (mod (* 3 (- number-difference name-difference)) |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
194 20))) |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
195 260))) |
957 | 196 |
197 (defun calendar-mayan-tzolkin-on-or-before (tzolkin-date date) | |
198 "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
|
199 (- date |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
200 (% (- date (calendar-mayan-tzolkin-difference |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
201 (calendar-mayan-tzolkin-from-absolute 0) |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
202 tzolkin-date)) |
f90250f69413
* cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents:
1353
diff
changeset
|
203 260))) |
957 | 204 |
205 (defun calendar-next-tzolkin-date (tzolkin-date &optional noecho) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
206 "Move cursor to next instance of Mayan TZOLKIN-DATE. |
957 | 207 Echo Mayan date if NOECHO is t." |
208 (interactive (list (calendar-read-mayan-tzolkin-date))) | |
209 (calendar-goto-date | |
210 (calendar-gregorian-from-absolute | |
211 (calendar-mayan-tzolkin-on-or-before | |
212 tzolkin-date | |
213 (+ 260 | |
214 (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
215 (or noecho (calendar-print-mayan-date))) | |
216 | |
217 (defun calendar-previous-tzolkin-date (tzolkin-date &optional noecho) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
218 "Move cursor to previous instance of Mayan TZOLKIN-DATE. |
957 | 219 Echo Mayan date if NOECHO is t." |
220 (interactive (list (calendar-read-mayan-tzolkin-date))) | |
221 (calendar-goto-date | |
222 (calendar-gregorian-from-absolute | |
223 (calendar-mayan-tzolkin-on-or-before | |
224 tzolkin-date | |
225 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date)))))) | |
226 (or noecho (calendar-print-mayan-date))) | |
227 | |
228 (defun calendar-mayan-tzolkin-to-string (tzolkin) | |
229 "Convert Mayan tzolkin date (a pair) into its traditional written form." | |
230 (format "%d %s" | |
231 (car tzolkin) | |
232 (aref calendar-mayan-tzolkin-names-array (1- (cdr tzolkin))))) | |
233 | |
234 (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
|
235 "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
|
236 Latest such date on or before DATE. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
237 Returns nil if such a tzolkin-haab combination is impossible." |
957 | 238 (let* ((haab-difference |
239 (calendar-mayan-haab-difference | |
240 (calendar-mayan-haab-from-absolute 0) | |
241 haab-date)) | |
242 (tzolkin-difference | |
243 (calendar-mayan-tzolkin-difference | |
244 (calendar-mayan-tzolkin-from-absolute 0) | |
245 tzolkin-date)) | |
246 (difference (- tzolkin-difference haab-difference))) | |
247 (if (= (% difference 5) 0) | |
248 (- date | |
4521
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
249 (mod (- date |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
250 (+ haab-difference (* 365 difference))) |
2308b366bfc8
(calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
3869
diff
changeset
|
251 18980)) |
957 | 252 nil))) |
253 | |
254 (defun calendar-read-mayan-haab-date () | |
255 "Prompt for a Mayan haab date" | |
256 (let* ((completion-ignore-case t) | |
257 (haab-day (calendar-read | |
258 "Haab kin (0-19): " | |
259 '(lambda (x) (and (>= x 0) (< x 20))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
260 (haab-month-list (append calendar-mayan-haab-month-name-array |
957 | 261 (and (< haab-day 5) '("Uayeb")))) |
262 (haab-month (cdr | |
54077
346fc2783282
(calendar-read-mayan-haab-date, calendar-read-mayan-tzolkin-date): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
263 (assoc-string |
24185
c8a68d6bcfa6
(calendar-read-mayan-haab-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
264 (completing-read "Haab uinal: " |
c8a68d6bcfa6
(calendar-read-mayan-haab-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
265 (mapcar 'list haab-month-list) |
c8a68d6bcfa6
(calendar-read-mayan-haab-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
266 nil t) |
54077
346fc2783282
(calendar-read-mayan-haab-date, calendar-read-mayan-tzolkin-date): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
267 (calendar-make-alist haab-month-list 1) t)))) |
957 | 268 (cons haab-day haab-month))) |
269 | |
270 (defun calendar-read-mayan-tzolkin-date () | |
271 "Prompt for a Mayan tzolkin date" | |
272 (let* ((completion-ignore-case t) | |
273 (tzolkin-count (calendar-read | |
274 "Tzolkin kin (1-13): " | |
275 '(lambda (x) (and (> x 0) (< x 14))))) | |
276 (tzolkin-name-list (append calendar-mayan-tzolkin-names-array nil)) | |
277 (tzolkin-name (cdr | |
54077
346fc2783282
(calendar-read-mayan-haab-date, calendar-read-mayan-tzolkin-date): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
278 (assoc-string |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
279 (completing-read "Tzolkin uinal: " |
957 | 280 (mapcar 'list tzolkin-name-list) |
24185
c8a68d6bcfa6
(calendar-read-mayan-haab-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
281 nil t) |
54077
346fc2783282
(calendar-read-mayan-haab-date, calendar-read-mayan-tzolkin-date): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
282 (calendar-make-alist tzolkin-name-list 1) t)))) |
957 | 283 (cons tzolkin-count tzolkin-name))) |
284 | |
285 (defun calendar-next-calendar-round-date | |
286 (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
|
287 "Move cursor to next instance of Mayan HAAB-DATE TZOLKIN-DATE combination. |
957 | 288 Echo Mayan date if NOECHO is t." |
289 (interactive (list (calendar-read-mayan-tzolkin-date) | |
290 (calendar-read-mayan-haab-date))) | |
291 (let ((date (calendar-mayan-tzolkin-haab-on-or-before | |
292 tzolkin-date haab-date | |
293 (+ 18980 (calendar-absolute-from-gregorian | |
294 (calendar-cursor-to-date)))))) | |
295 (if (not date) | |
296 (error "%s, %s does not exist in the Mayan calendar round" | |
297 (calendar-mayan-tzolkin-to-string tzolkin-date) | |
298 (calendar-mayan-haab-to-string haab-date)) | |
299 (calendar-goto-date (calendar-gregorian-from-absolute date)) | |
300 (or noecho (calendar-print-mayan-date))))) | |
301 | |
302 (defun calendar-previous-calendar-round-date | |
303 (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
|
304 "Move to previous instance of Mayan TZOLKIN-DATE HAAB-DATE combination. |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
305 Echo Mayan date if NOECHO is t." |
957 | 306 (interactive (list (calendar-read-mayan-tzolkin-date) |
307 (calendar-read-mayan-haab-date))) | |
308 (let ((date (calendar-mayan-tzolkin-haab-on-or-before | |
309 tzolkin-date haab-date | |
310 (1- (calendar-absolute-from-gregorian | |
311 (calendar-cursor-to-date)))))) | |
312 (if (not date) | |
313 (error "%s, %s does not exist in the Mayan calendar round" | |
314 (calendar-mayan-tzolkin-to-string tzolkin-date) | |
315 (calendar-mayan-haab-to-string haab-date)) | |
316 (calendar-goto-date (calendar-gregorian-from-absolute date)) | |
317 (or noecho (calendar-print-mayan-date))))) | |
318 | |
319 (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
|
320 "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
|
321 Long count is a list (baktun katun tun uinal kin)" |
957 | 322 (+ (* (nth 0 c) 144000) ; baktun |
323 (* (nth 1 c) 7200) ; katun | |
324 (* (nth 2 c) 360) ; tun | |
325 (* (nth 3 c) 20) ; uinal | |
326 (nth 4 c) ; kin (days) | |
327 (- ; days before absolute date 0 | |
328 calendar-mayan-days-before-absolute-zero))) | |
329 | |
5700
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
330 (defun calendar-mayan-date-string (&optional date) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
331 "String of Mayan date of Gregorian DATE. |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
332 Defaults to today's date if DATE is not given." |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
333 (let* ((d (calendar-absolute-from-gregorian |
5700
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
334 (or date (calendar-current-date)))) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
335 (tzolkin (calendar-mayan-tzolkin-from-absolute d)) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
336 (haab (calendar-mayan-haab-from-absolute d)) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
337 (long-count (calendar-mayan-long-count-from-absolute d))) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
338 (format "Long count = %s; tzolkin = %s; haab = %s" |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
339 (calendar-mayan-long-count-to-string long-count) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
340 (calendar-mayan-tzolkin-to-string tzolkin) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
341 (calendar-mayan-haab-to-string haab)))) |
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
342 |
957 | 343 (defun calendar-print-mayan-date () |
3869
037e012d04b0
* cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents:
2945
diff
changeset
|
344 "Show the Mayan long count, tzolkin, and haab equivalents of date." |
957 | 345 (interactive) |
5700
6620aa507202
(calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4521
diff
changeset
|
346 (message "Mayan date: %s" |
5834
5391898ea85c
(calendar-print-mayan-date): Use new error arg to calendar-cursor-to-date.
Richard M. Stallman <rms@gnu.org>
parents:
5700
diff
changeset
|
347 (calendar-mayan-date-string (calendar-cursor-to-date t)))) |
957 | 348 |
349 (defun calendar-goto-mayan-long-count-date (date &optional noecho) | |
350 "Move cursor to Mayan long count DATE. Echo Mayan date unless NOECHO is t." | |
351 (interactive | |
352 (let (lc) | |
353 (while (not lc) | |
354 (let ((datum | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
355 (calendar-string-to-mayan-long-count |
957 | 356 (read-string "Mayan long count (baktun.katun.tun.uinal.kin): " |
357 (calendar-mayan-long-count-to-string | |
358 (calendar-mayan-long-count-from-absolute | |
359 (calendar-absolute-from-gregorian | |
360 (calendar-current-date)))))))) | |
361 (if (calendar-mayan-long-count-common-era datum) | |
362 (setq lc datum)))) | |
363 (list lc))) | |
364 (calendar-goto-date | |
365 (calendar-gregorian-from-absolute | |
366 (calendar-absolute-from-mayan-long-count date))) | |
367 (or noecho (calendar-print-mayan-date))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
368 |
957 | 369 (defun calendar-mayan-long-count-common-era (lc) |
370 "T if long count represents date in the Common Era." | |
371 (let ((base (calendar-mayan-long-count-from-absolute 1))) | |
372 (while (and (not (null base)) (= (car lc) (car base))) | |
373 (setq lc (cdr lc) | |
374 base (cdr base))) | |
375 (or (null lc) (> (car lc) (car base))))) | |
376 | |
377 (defun diary-mayan-date () | |
378 "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
|
379 (format "Mayan date: %s" (calendar-mayan-date-string date))) |
957 | 380 |
381 (provide 'cal-mayan) | |
382 | |
52401 | 383 ;;; arch-tag: 54f35144-cd0f-4873-935a-a60129de07df |
957 | 384 ;;; cal-mayan.el ends here |