Mercurial > emacs
annotate lisp/calendar/cal-julian.el @ 92659:678337768a80
(diary-bahai-mark-entries)
(diary-bahai-insert-entry, diary-bahai-insert-monthly-entry)
(diary-bahai-insert-yearly-entry): Doc fixes.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 08 Mar 2008 21:36:14 +0000 |
parents | 18dc9ef91100 |
children | 8863bb0c2832 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
24189
diff
changeset
|
1 ;;; cal-julian.el --- calendar functions for the Julian calendar |
13053 | 2 |
92608
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
4 ;; 2008 Free Software Foundation, Inc. |
13053 | 5 |
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65145
diff
changeset
|
7 ;; Maintainer: Glenn Morris <rgm@gnu.org> |
13053 | 8 ;; Keywords: calendar |
9 ;; Human-Keywords: Julian calendar, Julian day number, calendar, diary | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; 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
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
13053 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
13053 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This collection of functions implements the features of calendar.el and | |
31 ;; diary.el that deal with the Julian calendar. | |
32 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
33 ;; Technical details of all the 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:
54076
diff
changeset
|
34 ;; ``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:
54076
diff
changeset
|
35 ;; and Nachum Dershowitz, Cambridge University Press (2001). |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
36 |
13053 | 37 ;;; Code: |
38 | |
52112
e7d0572ccca5
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
39 (defvar displayed-month) |
e7d0572ccca5
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
40 (defvar displayed-year) |
e7d0572ccca5
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
41 |
13053 | 42 (require 'calendar) |
43 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
44 ;;;###autoload |
13053 | 45 (defun calendar-julian-from-absolute (date) |
46 "Compute the Julian (month day year) corresponding to the absolute DATE. | |
47 The absolute date is the number of days elapsed since the (imaginary) | |
48 Gregorian date Sunday, December 31, 1 BC." | |
49 (let* ((approx (/ (+ date 2) 366));; Approximation from below. | |
50 (year ;; Search forward from the approximation. | |
51 (+ approx | |
52 (calendar-sum y approx | |
53 (>= date (calendar-absolute-from-julian (list 1 1 (1+ y)))) | |
54 1))) | |
55 (month ;; Search forward from January. | |
56 (1+ (calendar-sum m 1 | |
57 (> date | |
58 (calendar-absolute-from-julian | |
59 (list m | |
60 (if (and (= m 2) (= (% year 4) 0)) | |
61 29 | |
62 (aref [31 28 31 30 31 30 31 31 30 31 30 31] | |
63 (1- m))) | |
64 year))) | |
65 1))) | |
66 (day ;; Calculate the day by subtraction. | |
67 (- date (1- (calendar-absolute-from-julian (list month 1 year)))))) | |
68 (list month day year))) | |
69 | |
70 (defun calendar-absolute-from-julian (date) | |
71 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. | |
72 The Gregorian date Sunday, December 31, 1 BC is imaginary." | |
73 (let ((month (extract-calendar-month date)) | |
74 (day (extract-calendar-day date)) | |
75 (year (extract-calendar-year date))) | |
76 (+ (calendar-day-number date) | |
92608
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
77 (if (and (zerop (% year 100)) |
13053 | 78 (/= (% year 400) 0) |
79 (> month 2)) | |
80 1 0);; Correct for Julian but not Gregorian leap year. | |
81 (* 365 (1- year)) | |
82 (/ (1- year) 4) | |
83 -2))) | |
84 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
85 ;;;###autoload |
13053 | 86 (defun calendar-julian-date-string (&optional date) |
87 "String of Julian date of Gregorian DATE. | |
88 Defaults to today's date if DATE is not given. | |
89 Driven by the variable `calendar-date-display-form'." | |
90 (calendar-date-string | |
91 (calendar-julian-from-absolute | |
92 (calendar-absolute-from-gregorian | |
93 (or date (calendar-current-date)))) | |
94 nil t)) | |
95 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
96 ;;;###autoload |
13053 | 97 (defun calendar-print-julian-date () |
98 "Show the Julian calendar equivalent of the date under the cursor." | |
99 (interactive) | |
100 (message "Julian date: %s" | |
101 (calendar-julian-date-string (calendar-cursor-to-date t)))) | |
102 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
103 ;;;###autoload |
13053 | 104 (defun calendar-goto-julian-date (date &optional noecho) |
105 "Move cursor to Julian DATE; echo Julian date unless NOECHO is t." | |
106 (interactive | |
107 (let* ((today (calendar-current-date)) | |
108 (year (calendar-read | |
109 "Julian calendar year (>0): " | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
110 (lambda (x) (> x 0)) |
13053 | 111 (int-to-string |
112 (extract-calendar-year | |
113 (calendar-julian-from-absolute | |
114 (calendar-absolute-from-gregorian | |
115 today)))))) | |
116 (month-array calendar-month-name-array) | |
117 (completion-ignore-case t) | |
54076
9e3e3d184730
(calendar-goto-julian-date): Use assoc-string instead of
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
118 (month (cdr (assoc-string |
13053 | 119 (completing-read |
120 "Julian calendar month name: " | |
121 (mapcar 'list (append month-array nil)) | |
24189
c70c6c750126
(calendar-goto-julian-date): Use assoc-ignore-case and do not
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
122 nil t) |
54076
9e3e3d184730
(calendar-goto-julian-date): Use assoc-string instead of
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
123 (calendar-make-alist month-array 1) t))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
124 (last |
13053 | 125 (if (and (zerop (% year 4)) (= month 2)) |
126 29 | |
127 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month)))) | |
128 (day (calendar-read | |
129 (format "Julian calendar day (%d-%d): " | |
130 (if (and (= year 1) (= month 1)) 3 1) last) | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
131 (lambda (x) |
13053 | 132 (and (< (if (and (= year 1) (= month 1)) 2 0) x) |
133 (<= x last)))))) | |
134 (list (list month day year)))) | |
135 (calendar-goto-date (calendar-gregorian-from-absolute | |
136 (calendar-absolute-from-julian date))) | |
137 (or noecho (calendar-print-julian-date))) | |
138 | |
139 (defun holiday-julian (month day string) | |
140 "Holiday on MONTH, DAY (Julian) called STRING. | |
141 If MONTH, DAY (Julian) is visible, the value returned is corresponding | |
142 Gregorian date in the form of the list (((month day year) STRING)). Returns | |
143 nil if it is not visible in the current calendar window." | |
144 (let ((m1 displayed-month) | |
145 (y1 displayed-year) | |
146 (m2 displayed-month) | |
147 (y2 displayed-year) | |
148 (year)) | |
149 (increment-calendar-month m1 y1 -1) | |
150 (increment-calendar-month m2 y2 1) | |
151 (let* ((start-date (calendar-absolute-from-gregorian | |
152 (list m1 1 y1))) | |
153 (end-date (calendar-absolute-from-gregorian | |
154 (list m2 (calendar-last-day-of-month m2 y2) y2))) | |
155 (julian-start (calendar-julian-from-absolute start-date)) | |
156 (julian-end (calendar-julian-from-absolute end-date)) | |
157 (julian-y1 (extract-calendar-year julian-start)) | |
158 (julian-y2 (extract-calendar-year julian-end))) | |
159 (setq year (if (< 10 month) julian-y1 julian-y2)) | |
160 (let ((date (calendar-gregorian-from-absolute | |
161 (calendar-absolute-from-julian | |
162 (list month day year))))) | |
163 (if (calendar-date-is-visible-p date) | |
164 (list (list date string))))))) | |
165 | |
92608
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
166 (defvar date) |
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
167 |
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
168 ;; To be called from list-sexp-diary-entries, where DATE is bound. |
13053 | 169 (defun diary-julian-date () |
170 "Julian calendar equivalent of date diary entry." | |
171 (format "Julian date: %s" (calendar-julian-date-string date))) | |
172 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
173 ;;;###autoload |
13053 | 174 (defun calendar-absolute-from-astro (d) |
13673
da11ffac4f8b
(calendar-absolute-from-astro): Doc fix.
Paul Eggert <eggert@twinsun.com>
parents:
13053
diff
changeset
|
175 "Absolute date of astronomical (Julian) day number D." |
13053 | 176 (- d 1721424.5)) |
177 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
178 ;;;###autoload |
13053 | 179 (defun calendar-astro-from-absolute (d) |
180 "Astronomical (Julian) day number of absolute date D." | |
181 (+ d 1721424.5)) | |
182 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
183 ;;;###autoload |
13053 | 184 (defun calendar-astro-date-string (&optional date) |
185 "String of astronomical (Julian) day number after noon UTC of Gregorian DATE. | |
186 Defaults to today's date if DATE is not given." | |
187 (int-to-string | |
188 (ceiling | |
189 (calendar-astro-from-absolute | |
190 (calendar-absolute-from-gregorian | |
191 (or date (calendar-current-date))))))) | |
192 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
193 ;;;###autoload |
13053 | 194 (defun calendar-print-astro-day-number () |
195 "Show astronomical (Julian) day number after noon UTC on date shown by cursor." | |
196 (interactive) | |
197 (message | |
15069
6237f2b08205
Spelling error.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
198 "Astronomical (Julian) day number (at noon UTC): %s.0" |
13053 | 199 (calendar-astro-date-string (calendar-cursor-to-date t)))) |
200 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
201 ;;;###autoload |
13053 | 202 (defun calendar-goto-astro-day-number (daynumber &optional noecho) |
203 "Move cursor to astronomical (Julian) DAYNUMBER. | |
204 Echo astronomical (Julian) day number unless NOECHO is t." | |
205 (interactive (list (calendar-read | |
206 "Astronomical (Julian) day number (>1721425): " | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
207 (lambda (x) (> x 1721425))))) |
13053 | 208 (calendar-goto-date |
209 (calendar-gregorian-from-absolute | |
210 (floor | |
211 (calendar-absolute-from-astro daynumber)))) | |
212 (or noecho (calendar-print-astro-day-number))) | |
213 | |
92608
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
214 ;; To be called from list-sexp-diary-entries, where DATE is bound. |
13053 | 215 (defun diary-astro-day-number () |
216 "Astronomical (Julian) day number diary entry." | |
17380
ba0844956fde
(diary-astro-day-number): Change format string.
Richard M. Stallman <rms@gnu.org>
parents:
15069
diff
changeset
|
217 (format "Astronomical (Julian) day number at noon UTC: %s.0" |
13053 | 218 (calendar-astro-date-string date))) |
219 | |
220 (provide 'cal-julian) | |
221 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
222 ;; Local Variables: |
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
223 ;; generated-autoload-file: "cal-loaddefs.el" |
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
224 ;; End: |
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
225 |
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
226 ;; arch-tag: 0520acdd-1c60-4188-9aa8-9b8c24d856ae |
13053 | 227 ;;; cal-julian.el ends here |