annotate lisp/calendar/cal-mayan.el @ 12675:8c9369149a9d

Move #define of bcopy to after #include <string.h>.
author David J. MacKenzie <djm@gnu.org>
date Wed, 26 Jul 1995 17:54:50 +0000
parents 51b28b893fea
children 6c21adf788d5
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
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
3 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
957
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
6736
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 6006
diff changeset
12 ;; 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
13 ;; 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
14 ;; 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
15 ;; any later version.
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
6736
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 6006
diff changeset
17 ;; 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
18 ;; 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
19 ;; 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
20 ;; 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
21
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 6006
diff changeset
22 ;; You should have received a copy of the GNU General Public License
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 6006
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 6006
diff changeset
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 ;;; Commentary:
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 ;; This collection of functions implements the features of calendar.el and
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;; 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
30
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ;; Stewart M. Clamen School of Computer Science
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; clamen@cs.cmu.edu Carnegie Mellon University
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; 5000 Forbes Avenue
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; Pittsburgh, PA 15213
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; and
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;; Edward M. Reingold Department of Computer Science
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; Urbana, Illinois 61801
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;; Comments, improvements, and bug reports should be sent to Reingold.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;; Technical details of the Mayan calendrical calculations can be found in
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; ``Calendrical Calculations, Part II: Three Historical Calendars''
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;; 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
48 ;; 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
49 ;; pages 383-404.
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;;; Code:
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (require 'calendar)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (defun mayan-adjusted-mod (m n)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 "Non-negative remainder of M/N with N instead of 0."
4521
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
57 (1+ (mod (1- m) n)))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (defconst calendar-mayan-days-before-absolute-zero 1137140
3869
037e012d04b0 * cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents: 2945
diff changeset
60 "Number of days of the Mayan calendar epoch before absolute day 0.
037e012d04b0 * cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents: 2945
diff changeset
61 According to the Goodman-Martinez-Thompson correlation. This correlation is
037e012d04b0 * cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents: 2945
diff changeset
62 not universally accepted, as it still a subject of astro-archeological
10131
51b28b893fea Mention Hochleitner's correlation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 6736
diff changeset
63 research. Using 1232041 will give you Spinden's correlation; using
51b28b893fea Mention Hochleitner's correlation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 6736
diff changeset
64 1142840 will give you Hochleitner's correlation.")
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (defconst calendar-mayan-haab-at-epoch '(8 . 18)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 "Mayan haab date at the epoch.")
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 (defconst calendar-mayan-haab-month-name-array
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 ["Pop" "Uo" "Zip" "Zotz" "Tzec" "Xul" "Yaxkin" "Mol" "Chen" "Yax"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 "Zac" "Ceh" "Mac" "Kankin" "Muan" "Pax" "Kayab" "Cumku"])
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (defconst calendar-mayan-tzolkin-at-epoch '(4 . 20)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 "Mayan tzolkin date at the epoch.")
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (defconst calendar-mayan-tzolkin-names-array
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 ["Imix" "Ik" "Akbal" "Kan" "Chicchan" "Cimi" "Manik" "Lamat" "Muluc" "Oc"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 "Chuen" "Eb" "Ben" "Ix" "Men" "Cib" "Caban" "Etznab" "Cauac" "Ahau"])
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 (defun calendar-mayan-long-count-from-absolute (date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 "Compute the Mayan long count corresponding to the absolute DATE."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 (let ((long-count (+ date calendar-mayan-days-before-absolute-zero)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (let* ((baktun (/ long-count 144000))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 (remainder (% long-count 144000))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 (katun (/ remainder 7200))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 (remainder (% remainder 7200))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (tun (/ remainder 360))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (remainder (% remainder 360))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (uinal (/ remainder 20))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (kin (% remainder 20)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (list baktun katun tun uinal kin))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (defun calendar-mayan-long-count-to-string (mayan-long-count)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 "Convert MAYAN-LONG-COUNT into traditional written form."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (apply 'format (cons "%s.%s.%s.%s.%s" mayan-long-count)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (defun calendar-string-to-mayan-long-count (str)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 "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
99 (let ((rlc nil)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (c (length str))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (cc 0))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (condition-case condition
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 (progn
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (while (< cc c)
6006
dc6d45202fb9 (calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents: 5834
diff changeset
105 (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
106 (end (match-end 0))
dc6d45202fb9 (calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents: 5834
diff changeset
107 datum)
dc6d45202fb9 (calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents: 5834
diff changeset
108 (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
109 (setq rlc (cons datum rlc))
dc6d45202fb9 (calendar-string-to-mayan-long-count): Don't
Richard M. Stallman <rms@gnu.org>
parents: 5834
diff changeset
110 (setq cc end)))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (if (not (= (length rlc) 5)) (signal 'invalid-read-syntax nil)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (invalid-read-syntax nil))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (reverse rlc)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (defun calendar-mayan-haab-from-absolute (date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 "Convert absolute DATE into a Mayan haab date (a pair)."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 (day-of-haab
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 (% (+ long-count
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (car calendar-mayan-haab-at-epoch)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (* 20 (1- (cdr calendar-mayan-haab-at-epoch))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 365))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (day (% day-of-haab 20))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (month (1+ (/ day-of-haab 20))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 (cons day month)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (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
128 "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
129 (mod (+ (* 20 (- (cdr date2) (cdr date1)))
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
130 (- (car date2) (car date1)))
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
131 365))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (defun calendar-mayan-haab-on-or-before (haab-date date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 "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
135 (- date
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
136 (% (- date
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
137 (calendar-mayan-haab-difference
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
138 (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
139 365)))
957
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-next-haab-date (haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 "Move cursor to next instance of Mayan HAAB-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (interactive (list (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (calendar-mayan-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (+ 365
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (defun calendar-previous-haab-date (haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 "Move cursor to previous instance of Mayan HAAB-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (interactive (list (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (calendar-mayan-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (defun calendar-mayan-haab-to-string (haab)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 "Convert Mayan haab date (a pair) into its traditional written form."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (let ((month (cdr haab))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (day (car haab)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 ;; 19th month consists of 5 special days
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (if (= month 19)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (format "%d Uayeb" day)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (format "%d %s"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 day
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (aref calendar-mayan-haab-month-name-array (1- month))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (defun calendar-mayan-tzolkin-from-absolute (date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 "Convert absolute DATE into a Mayan tzolkin date (a pair)."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 (let* ((long-count (+ date calendar-mayan-days-before-absolute-zero))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (day (mayan-adjusted-mod
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (+ long-count (car calendar-mayan-tzolkin-at-epoch))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 13))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (name (mayan-adjusted-mod
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (+ long-count (cdr calendar-mayan-tzolkin-at-epoch))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 20)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (cons day name)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (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
187 "Number of days from Mayan tzolkin DATE1 to next occurrence of tzolkin DATE2."
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (let ((number-difference (- (car date2) (car date1)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (name-difference (- (cdr date2) (cdr date1))))
4521
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
190 (mod (+ number-difference
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
191 (* 13 (mod (* 3 (- number-difference name-difference))
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
192 20)))
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
193 260)))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (defun calendar-mayan-tzolkin-on-or-before (tzolkin-date date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 "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
197 (- date
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
198 (% (- date (calendar-mayan-tzolkin-difference
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
199 (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
200 tzolkin-date))
f90250f69413 * cal-mayan.el (calendar-mayan-haab-on-or-before,
Jim Blandy <jimb@redhat.com>
parents: 1353
diff changeset
201 260)))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (defun calendar-next-tzolkin-date (tzolkin-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 "Move cursor to next instance of Mayan TZOLKIN-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (interactive (list (calendar-read-mayan-tzolkin-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (calendar-mayan-tzolkin-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 tzolkin-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (+ 260
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (defun calendar-previous-tzolkin-date (tzolkin-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 "Move cursor to previous instance of Mayan TZOLKIN-DATE.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (interactive (list (calendar-read-mayan-tzolkin-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (calendar-mayan-tzolkin-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 tzolkin-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (1- (calendar-absolute-from-gregorian (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (defun calendar-mayan-tzolkin-to-string (tzolkin)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 "Convert Mayan tzolkin date (a pair) into its traditional written form."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (format "%d %s"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (car tzolkin)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (aref calendar-mayan-tzolkin-names-array (1- (cdr tzolkin)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (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
233 "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
234 Latest such date on or before DATE.
037e012d04b0 * cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents: 2945
diff changeset
235 Returns nil if such a tzolkin-haab combination is impossible."
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (let* ((haab-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (calendar-mayan-haab-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (calendar-mayan-haab-from-absolute 0)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 haab-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (tzolkin-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (calendar-mayan-tzolkin-difference
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (calendar-mayan-tzolkin-from-absolute 0)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 tzolkin-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (difference (- tzolkin-difference haab-difference)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (if (= (% difference 5) 0)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (- date
4521
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
247 (mod (- date
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
248 (+ haab-difference (* 365 difference)))
2308b366bfc8 (calendar-/, calendar-%): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 3869
diff changeset
249 18980))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 nil)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (defun calendar-read-mayan-haab-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 "Prompt for a Mayan haab date"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (let* ((completion-ignore-case t)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (haab-day (calendar-read
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 "Haab kin (0-19): "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 '(lambda (x) (and (>= x 0) (< x 20)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (haab-month-list (append calendar-mayan-haab-month-name-array
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (and (< haab-day 5) '("Uayeb"))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (haab-month (cdr
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (assoc
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (capitalize
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (completing-read "Haab uinal: "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (mapcar 'list haab-month-list)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 nil t))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (calendar-make-alist
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 haab-month-list 1 'capitalize)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (cons haab-day haab-month)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (defun calendar-read-mayan-tzolkin-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 "Prompt for a Mayan tzolkin date"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (let* ((completion-ignore-case t)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 (tzolkin-count (calendar-read
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 "Tzolkin kin (1-13): "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 '(lambda (x) (and (> x 0) (< x 14)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (tzolkin-name-list (append calendar-mayan-tzolkin-names-array nil))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (tzolkin-name (cdr
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (assoc
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (capitalize
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (completing-read "Tzolkin uinal: "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (mapcar 'list tzolkin-name-list)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 nil t))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 (calendar-make-alist
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 tzolkin-name-list 1 'capitalize)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (cons tzolkin-count tzolkin-name)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (defun calendar-next-calendar-round-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 (tzolkin-date haab-date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 "Move cursor to next instance of Mayan HAAB-DATE TZOKLIN-DATE combination.
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 Echo Mayan date if NOECHO is t."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 (interactive (list (calendar-read-mayan-tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (let ((date (calendar-mayan-tzolkin-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 tzolkin-date haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (+ 18980 (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (if (not date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 (error "%s, %s does not exist in the Mayan calendar round"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (calendar-mayan-tzolkin-to-string tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (calendar-mayan-haab-to-string haab-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (calendar-goto-date (calendar-gregorian-from-absolute date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (or noecho (calendar-print-mayan-date)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 (defun calendar-previous-calendar-round-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (tzolkin-date haab-date &optional noecho)
3869
037e012d04b0 * cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents: 2945
diff changeset
306 "Move to previous instance of Mayan TZOKLIN-DATE HAAB-DATE combination.
037e012d04b0 * cal-mayan.el (calendar-mayan-days-before-absolute-zero,
Jim Blandy <jimb@redhat.com>
parents: 2945
diff changeset
307 Echo Mayan date if NOECHO is t."
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 (interactive (list (calendar-read-mayan-tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 (calendar-read-mayan-haab-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (let ((date (calendar-mayan-tzolkin-haab-on-or-before
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 tzolkin-date haab-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (1- (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (calendar-cursor-to-date))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (if (not date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 (error "%s, %s does not exist in the Mayan calendar round"
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 (calendar-mayan-tzolkin-to-string tzolkin-date)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 (calendar-mayan-haab-to-string haab-date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 (calendar-goto-date (calendar-gregorian-from-absolute date))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 (or noecho (calendar-print-mayan-date)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (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
322 "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
323 Long count is a list (baktun katun tun uinal kin)"
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (+ (* (nth 0 c) 144000) ; baktun
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (* (nth 1 c) 7200) ; katun
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (* (nth 2 c) 360) ; tun
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (* (nth 3 c) 20) ; uinal
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 (nth 4 c) ; kin (days)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (- ; days before absolute date 0
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 calendar-mayan-days-before-absolute-zero)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
5700
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
332 (defun calendar-mayan-date-string (&optional date)
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
333 "String of Mayan date of Gregorian DATE.
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
334 Defaults to today's date if DATE is not given."
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
335 (let* ((d (calendar-absolute-from-gregorian
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
336 (or date (calendar-current-date))))
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
337 (tzolkin (calendar-mayan-tzolkin-from-absolute d))
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
338 (haab (calendar-mayan-haab-from-absolute d))
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
339 (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
340 (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
341 (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
342 (calendar-mayan-tzolkin-to-string tzolkin)
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
343 (calendar-mayan-haab-to-string haab))))
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
344
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (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
346 "Show the Mayan long count, tzolkin, and haab equivalents of date."
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (interactive)
5700
6620aa507202 (calendar-mayan-date-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4521
diff changeset
348 (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
349 (calendar-mayan-date-string (calendar-cursor-to-date t))))
957
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (defun calendar-goto-mayan-long-count-date (date &optional noecho)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 "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
353 (interactive
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (let (lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (while (not lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (let ((datum
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (calendar-string-to-mayan-long-count
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (read-string "Mayan long count (baktun.katun.tun.uinal.kin): "
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (calendar-mayan-long-count-to-string
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (calendar-mayan-long-count-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (calendar-absolute-from-gregorian
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (calendar-current-date))))))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (if (calendar-mayan-long-count-common-era datum)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (setq lc datum))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (list lc)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (calendar-goto-date
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (calendar-gregorian-from-absolute
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (calendar-absolute-from-mayan-long-count date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (or noecho (calendar-print-mayan-date)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (defun calendar-mayan-long-count-common-era (lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 "T if long count represents date in the Common Era."
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (let ((base (calendar-mayan-long-count-from-absolute 1)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 (while (and (not (null base)) (= (car lc) (car base)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (setq lc (cdr lc)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 base (cdr base)))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (or (null lc) (> (car lc) (car base)))))
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (defun diary-mayan-date ()
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 "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
381 (format "Mayan date: %s" (calendar-mayan-date-string date)))
957
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 (provide 'cal-mayan)
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384
2619b7a9c11e entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 ;;; cal-mayan.el ends here