annotate lisp/calendar/cal-mayan.el @ 92891:61f4584a0830

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