annotate lisp/calendar/cal-mayan.el @ 3263:82b564084ce6

(file-chase-links): Handle leading .. in symlink target.
author Richard M. Stallman <rms@gnu.org>
date Sat, 29 May 1993 20:13:58 +0000
parents 2c1f0215fcc3
children 037e012d04b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;;; cal-mayan.el --- calendar functions for the Mayan calendars.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 ;; Author: Stewart M. Clamen <clamen@cs.cmu.edu>
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2106
diff changeset
7 ;; Keywords: calendar
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2106
diff changeset
8 ;; Human-Keywords: Mayan calendar, Maya, calendar, diary
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY. No author or distributor
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; accepts responsibility to anyone for the consequences of using it
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; or for whether it serves any particular purpose or works at all,
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; unless he says so in writing. Refer to the GNU Emacs General Public
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; License for full details.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; Everyone is granted permission to copy, modify and redistribute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; GNU Emacs, but only under the conditions described in the
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; GNU Emacs General Public License. A copy of this license is
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; supposed to have been given to you along with GNU Emacs so you
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; can know your rights and responsibilities. It should be in a
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 ;; file named COPYING. Among other things, the copyright notice
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 ;; and this notice must be preserved on all copies.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 ;;; Commentary:
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;; This collection of functions implements the features of calendar.el and
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 ;; diary.el that deal with the Mayan calendar. It was written jointly by
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; Stewart M. Clamen School of Computer Science
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; clamen@cs.cmu.edu Carnegie Mellon University
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; 5000 Forbes Avenue
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; Pittsburgh, PA 15213
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; and
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; Edward M. Reingold Department of Computer Science
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; Urbana, Illinois 61801
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;; Comments, improvements, and bug reports should be sent to Reingold.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; Technical details of the Mayan calendrical calculations can be found in
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;; ``Calendrical Calculations, Part II: Three Historical Calendars''
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;; 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
49 ;; 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
50 ;; pages 383-404.
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 ;;; Code:
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 (require 'calendar)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (defun mayan-mod (m n)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 "Returns M mod N; value is *always* non-negative when N>0."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (let ((v (% m n)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (if (and (> 0 v) (> n 0))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (+ v n)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 v)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (defun mayan-adjusted-mod (m n)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 "Non-negative remainder of M/N with N instead of 0."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 (1+ (mayan-mod (1- m) n)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 (defconst calendar-mayan-days-before-absolute-zero 1137140
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 "Number of days of the Mayan calendar epoch before absolute day 0 (that is,
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 Dec 31, 0 (Gregorian)), according to the Goodman-Martinez-Thompson
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 correlation. This correlation is not universally accepted, as it still a
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 subject of astro-archeological research. Using 1232041 will give you the
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 correlation used by Spinden.")
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 (defconst calendar-mayan-haab-at-epoch '(8 . 18)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 "Mayan haab date at the epoch.")
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 (defconst calendar-mayan-haab-month-name-array
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 ["Pop" "Uo" "Zip" "Zotz" "Tzec" "Xul" "Yaxkin" "Mol" "Chen" "Yax"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 "Zac" "Ceh" "Mac" "Kankin" "Muan" "Pax" "Kayab" "Cumku"])
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 (defconst calendar-mayan-tzolkin-at-epoch '(4 . 20)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 "Mayan tzolkin date at the epoch.")
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 (defconst calendar-mayan-tzolkin-names-array
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 ["Imix" "Ik" "Akbal" "Kan" "Chicchan" "Cimi" "Manik" "Lamat" "Muluc" "Oc"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 "Chuen" "Eb" "Ben" "Ix" "Men" "Cib" "Caban" "Etznab" "Cauac" "Ahau"])
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (defun calendar-mayan-long-count-from-absolute (date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 "Compute the Mayan long count corresponding to the absolute DATE."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (let ((long-count (+ date calendar-mayan-days-before-absolute-zero)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (let* ((baktun (/ long-count 144000))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (remainder (% long-count 144000))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (katun (/ remainder 7200))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 (remainder (% remainder 7200))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (tun (/ remainder 360))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 (remainder (% remainder 360))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (uinal (/ remainder 20))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (kin (% remainder 20)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 (list baktun katun tun uinal kin))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (defun calendar-mayan-long-count-to-string (mayan-long-count)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 "Convert MAYAN-LONG-COUNT into traditional written form."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 (apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (defun calendar-string-to-mayan-long-count (str)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 "Given STR, a string of format \"%d.%d.%d.%d.%d\", return list of nums."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (let ((rlc nil)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (c (length str))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (cc 0))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 (condition-case condition
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (progn
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (while (< cc c)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (let ((datum (read-from-string str cc)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (if (not (integerp (car datum)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (signal 'invalid-read-syntax (car datum))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (setq rlc (cons (car datum) rlc))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (setq cc (cdr datum)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 (if (not (= (length rlc) 5)) (signal 'invalid-read-syntax nil)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 (invalid-read-syntax nil))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (reverse rlc)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (defun calendar-mayan-haab-from-absolute (date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 "Convert absolute DATE into a Mayan haab date (a pair)."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 (day-of-haab
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 (% (+ long-count
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (car calendar-mayan-haab-at-epoch)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 (* 20 (1- (cdr calendar-mayan-haab-at-epoch))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 365))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (day (% day-of-haab 20))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (month (1+ (/ day-of-haab 20))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (cons day month)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (defun calendar-mayan-haab-difference (date1 date2)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 "Number of days from Mayan haab date DATE1 to the next occurrence of Mayan
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 haab date DATE2."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (mayan-mod (+ (* 20 (- (cdr date2) (cdr date1)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (- (car date2) (car date1)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 365))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 (defun calendar-mayan-haab-on-or-before (haab-date date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 "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
143 (- date
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
144 (% (- date
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
145 (calendar-mayan-haab-difference
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
146 (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
147 365)))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (defun calendar-next-haab-date (haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 "Move cursor to next instance of Mayan HAAB-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (interactive (list (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (calendar-mayan-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (+ 365
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (defun calendar-previous-haab-date (haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 "Move cursor to previous instance of Mayan HAAB-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (interactive (list (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (calendar-mayan-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (defun calendar-mayan-haab-to-string (haab)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 "Convert Mayan haab date (a pair) into its traditional written form."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (let ((month (cdr haab))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (day (car haab)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 ;; 19th month consists of 5 special days
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 (if (= month 19)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (format "%d Uayeb" day)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (format "%d %s"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 day
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (aref calendar-mayan-haab-month-name-array (1- month))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (defun calendar-mayan-tzolkin-from-absolute (date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 "Convert absolute DATE into a Mayan tzolkin date (a pair)."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (day (mayan-adjusted-mod
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (+ long-count (car calendar-mayan-tzolkin-at-epoch))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 13))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (name (mayan-adjusted-mod
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (+ long-count (cdr calendar-mayan-tzolkin-at-epoch))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 20)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 (cons day name)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (defun calendar-mayan-tzolkin-difference (date1 date2)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 "Number of days from Mayan tzolkin date DATE1 to the next occurrence of
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 Mayan tzolkin date DATE2."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 (let ((number-difference (- (car date2) (car date1)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (name-difference (- (cdr date2) (cdr date1))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (mayan-mod (+ number-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (* 13 (mayan-mod (* 3 (- number-difference name-difference))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 20)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 260)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (defun calendar-mayan-tzolkin-on-or-before (tzolkin-date date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 "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
206 (- date
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
207 (% (- date (calendar-mayan-tzolkin-difference
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
208 (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
209 tzolkin-date))
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
210 260)))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (defun calendar-next-tzolkin-date (tzolkin-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 "Move cursor to next instance of Mayan TZOLKIN-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (interactive (list (calendar-read-mayan-tzolkin-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (calendar-mayan-tzolkin-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 tzolkin-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (+ 260
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (defun calendar-previous-tzolkin-date (tzolkin-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 "Move cursor to previous instance of Mayan TZOLKIN-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (interactive (list (calendar-read-mayan-tzolkin-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (calendar-mayan-tzolkin-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 tzolkin-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (defun calendar-mayan-tzolkin-to-string (tzolkin)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 "Convert Mayan tzolkin date (a pair) into its traditional written form."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (format "%d %s"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (car tzolkin)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (aref calendar-mayan-tzolkin-names-array (1- (cdr tzolkin)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (defun calendar-mayan-tzolkin-haab-on-or-before (tzolkin-date haab-date date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 "Absolute date of latest date on or before date that is Mayan TZOLKIN-DATE
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 and HAAB-DATE; returns nil if such a tzolkin-haab combination is impossible."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (let* ((haab-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (calendar-mayan-haab-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (calendar-mayan-haab-from-absolute 0)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 haab-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (tzolkin-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (calendar-mayan-tzolkin-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (calendar-mayan-tzolkin-from-absolute 0)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 tzolkin-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (difference (- tzolkin-difference haab-difference)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (if (= (% difference 5) 0)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (- date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (mayan-mod (- date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (+ haab-difference (* 365 difference)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 18980))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 nil)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (defun calendar-read-mayan-haab-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 "Prompt for a Mayan haab date"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (let* ((completion-ignore-case t)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (haab-day (calendar-read
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 "Haab kin (0-19): "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 '(lambda (x) (and (>= x 0) (< x 20)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (haab-month-list (append calendar-mayan-haab-month-name-array
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (and (< haab-day 5) '("Uayeb"))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (haab-month (cdr
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (assoc
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (capitalize
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (completing-read "Haab uinal: "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (mapcar 'list haab-month-list)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 nil t))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (calendar-make-alist
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 haab-month-list 1 'capitalize)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (cons haab-day haab-month)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (defun calendar-read-mayan-tzolkin-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 "Prompt for a Mayan tzolkin date"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (let* ((completion-ignore-case t)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (tzolkin-count (calendar-read
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 "Tzolkin kin (1-13): "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 '(lambda (x) (and (> x 0) (< x 14)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 (tzolkin-name-list (append calendar-mayan-tzolkin-names-array nil))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (tzolkin-name (cdr
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (assoc
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (capitalize
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 (completing-read "Tzolkin uinal: "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 (mapcar 'list tzolkin-name-list)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 nil t))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 (calendar-make-alist
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 tzolkin-name-list 1 'capitalize)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (cons tzolkin-count tzolkin-name)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (defun calendar-next-calendar-round-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (tzolkin-date haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 "Move cursor to next instance of Mayan HAAB-DATE TZOKLIN-DATE combination.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (interactive (list (calendar-read-mayan-tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (let ((date (calendar-mayan-tzolkin-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 tzolkin-date haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (+ 18980 (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (if (not date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 (error "%s, %s does not exist in the Mayan calendar round"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (calendar-mayan-tzolkin-to-string tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 (calendar-mayan-haab-to-string haab-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 (calendar-goto-date (calendar-gregorian-from-absolute date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (or noecho (calendar-print-mayan-date)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (defun calendar-previous-calendar-round-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (tzolkin-date haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 "Move cursor to previous instance of Mayan TZOKLIN-DATE HAAB-DATE
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 combination. Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 (interactive (list (calendar-read-mayan-tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 (let ((date (calendar-mayan-tzolkin-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 tzolkin-date haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 (1- (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (if (not date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 (error "%s, %s does not exist in the Mayan calendar round"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (calendar-mayan-tzolkin-to-string tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (calendar-mayan-haab-to-string haab-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (calendar-goto-date (calendar-gregorian-from-absolute date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (or noecho (calendar-print-mayan-date)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (defun calendar-absolute-from-mayan-long-count (c)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 "Compute the absolute date corresponding to the Mayan Long
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 Count $c$, which is a list (baktun katun tun uinal kin)"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (+ (* (nth 0 c) 144000) ; baktun
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 (* (nth 1 c) 7200) ; katun
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 (* (nth 2 c) 360) ; tun
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 (* (nth 3 c) 20) ; uinal
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 (nth 4 c) ; kin (days)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (- ; days before absolute date 0
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 calendar-mayan-days-before-absolute-zero)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (defun calendar-print-mayan-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 "Show the Mayan long count, tzolkin, and haab equivalents of the date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 under the cursor."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (interactive)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 (let* ((d (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (or (calendar-cursor-to-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (error "Cursor is not on a date!"))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (tzolkin (calendar-mayan-tzolkin-from-absolute d))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (haab (calendar-mayan-haab-from-absolute d))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (long-count (calendar-mayan-long-count-from-absolute d)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (message "Mayan date: Long count = %s; tzolkin = %s; haab = %s"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (calendar-mayan-long-count-to-string long-count)
1353
e5334b44bdab * cal-mayan.el (calendar-print-mayan-date): Fix conversion in
Jim Blandy <jimb@redhat.com>
parents: 957
diff changeset
352 (calendar-mayan-tzolkin-to-string tzolkin)
e5334b44bdab * cal-mayan.el (calendar-print-mayan-date): Fix conversion in
Jim Blandy <jimb@redhat.com>
parents: 957
diff changeset
353 (calendar-mayan-haab-to-string haab))))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (defun calendar-goto-mayan-long-count-date (date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 "Move cursor to Mayan long count DATE. Echo Mayan date unless NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (interactive
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (let (lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (while (not lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (let ((datum
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (calendar-string-to-mayan-long-count
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (read-string "Mayan long count (baktun.katun.tun.uinal.kin): "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (calendar-mayan-long-count-to-string
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (calendar-mayan-long-count-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (calendar-current-date))))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (if (calendar-mayan-long-count-common-era datum)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (setq lc datum))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (list lc)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (calendar-absolute-from-mayan-long-count date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (defun calendar-mayan-long-count-common-era (lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 "T if long count represents date in the Common Era."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (let ((base (calendar-mayan-long-count-from-absolute 1)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (while (and (not (null base)) (= (car lc) (car base)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (setq lc (cdr lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 base (cdr base)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (or (null lc) (> (car lc) (car base)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 (defun diary-mayan-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 "Show the Mayan long count, haab, and tzolkin dates as a diary entry."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (let* ((d (calendar-absolute-from-gregorian date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 (tzolkin (calendar-mayan-tzolkin-from-absolute d))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 (haab (calendar-mayan-haab-from-absolute d))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 (long-count (calendar-mayan-long-count-from-absolute d)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 (format "Mayan date: Long count = %s; tzolkin = %s; haab = %s"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (calendar-mayan-long-count-to-string long-count)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 (calendar-mayan-tzolkin-to-string haab)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 (calendar-mayan-haab-to-string tzolkin))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 (provide 'cal-mayan)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 ;;; cal-mayan.el ends here