Mercurial > emacs
annotate lisp/calendar/cal-julian.el @ 20892:18f3cb26243f before-miles-orphaned-changes gcc-2_8_1-980401 gcc-2_8_1-980407 gcc-2_8_1-980412 gcc-2_8_1-980413 gcc-2_8_1-RELEASE gcc_2_8_1-980315 libc-980214 libc-980215 libc-980216 libc-980217 libc-980218 libc-980219 libc-980220 libc-980221 libc-980222 libc-980223 libc-980224 libc-980225 libc-980226 libc-980227 libc-980228 libc-980301 libc-980302 libc-980303 libc-980304 libc-980306 libc-980307 libc-980308 libc-980309 libc-980310 libc-980311 libc-980312 libc-980313 libc-980314 libc-980315 libc-980316 libc-980317 libc-980318 libc-980319 libc-980320 libc-980321 libc-980322 libc-980323 libc-980324 libc-980325 libc-980326 libc-980327 libc-980328 libc-980329 libc-980330 libc-980331 libc-980401 libc-980402 libc-980403 libc-980404 libc-980405 libc-980406 libc-980407 libc-980408 libc-980409 libc-980410 libc-980411 libc-980412 libc-980413 libc-980414 libc-980428 libc-980429 libc-980430 libc-980501 libc-980502 libc-980503 libc-980504 libc-980505 libc-980506 libc-980507 libc-980508 libc-980509 libc-980510 libc-980512 libc-980513 libc-980514 libc-980515 libc-980516 libc-980517 libc-980518 libc-980519 libc-980520 libc-980521 libc-980522 libc-980523 libc-980524 libc-980525 libc-980526 libc-980527 libc-980528 libc-980529 libc-980530 libc-980531 libc-980601 libc-980602 libc-980603 libc-980604 libc-980605 libc-980606 libc-980607 libc-980608 libc-980609 libc-980610 libc-980611 libc-980612 libc-980613
Add PentiumII (i786). Add '7' to all i[3456] entries.
Add AMD and Cyrix names for P5 and P6.
author | Richard Kenner <kenner@gnu.org> |
---|---|
date | Fri, 13 Feb 1998 12:16:46 +0000 |
parents | d179de7ad92e |
children | c70c6c750126 |
rev | line source |
---|---|
13053 | 1 ;;; cal-julian.el --- calendar functions for the Julian calendar. |
2 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
3 ;; Copyright (C) 1995, 1997 Free Software Foundation, Inc. |
13053 | 4 |
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
6 ;; Keywords: calendar | |
7 ;; Human-Keywords: Julian calendar, Julian day number, calendar, diary | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
13053 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the features of calendar.el and | |
29 ;; diary.el that deal with the Julian calendar. | |
30 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
31 ;; Technical details of all the calendrical calculations can be found in |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
32 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold, |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
33 ;; Cambridge University Press (1997). |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17380
diff
changeset
|
34 |
13053 | 35 ;; Comments, corrections, and improvements should be sent to |
36 ;; Edward M. Reingold Department of Computer Science | |
37 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
38 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
39 ;; Urbana, Illinois 61801 | |
40 | |
41 ;;; Code: | |
42 | |
43 (require 'calendar) | |
44 | |
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) | |
77 (if (and (= (% year 100) 0) | |
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 | |
85 (defun calendar-julian-date-string (&optional date) | |
86 "String of Julian date of Gregorian DATE. | |
87 Defaults to today's date if DATE is not given. | |
88 Driven by the variable `calendar-date-display-form'." | |
89 (calendar-date-string | |
90 (calendar-julian-from-absolute | |
91 (calendar-absolute-from-gregorian | |
92 (or date (calendar-current-date)))) | |
93 nil t)) | |
94 | |
95 (defun calendar-print-julian-date () | |
96 "Show the Julian calendar equivalent of the date under the cursor." | |
97 (interactive) | |
98 (message "Julian date: %s" | |
99 (calendar-julian-date-string (calendar-cursor-to-date t)))) | |
100 | |
101 (defun calendar-goto-julian-date (date &optional noecho) | |
102 "Move cursor to Julian DATE; echo Julian date unless NOECHO is t." | |
103 (interactive | |
104 (let* ((today (calendar-current-date)) | |
105 (year (calendar-read | |
106 "Julian calendar year (>0): " | |
107 '(lambda (x) (> x 0)) | |
108 (int-to-string | |
109 (extract-calendar-year | |
110 (calendar-julian-from-absolute | |
111 (calendar-absolute-from-gregorian | |
112 today)))))) | |
113 (month-array calendar-month-name-array) | |
114 (completion-ignore-case t) | |
115 (month (cdr (assoc | |
116 (capitalize | |
117 (completing-read | |
118 "Julian calendar month name: " | |
119 (mapcar 'list (append month-array nil)) | |
120 nil t)) | |
121 (calendar-make-alist month-array 1 'capitalize)))) | |
122 (last | |
123 (if (and (zerop (% year 4)) (= month 2)) | |
124 29 | |
125 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month)))) | |
126 (day (calendar-read | |
127 (format "Julian calendar day (%d-%d): " | |
128 (if (and (= year 1) (= month 1)) 3 1) last) | |
129 '(lambda (x) | |
130 (and (< (if (and (= year 1) (= month 1)) 2 0) x) | |
131 (<= x last)))))) | |
132 (list (list month day year)))) | |
133 (calendar-goto-date (calendar-gregorian-from-absolute | |
134 (calendar-absolute-from-julian date))) | |
135 (or noecho (calendar-print-julian-date))) | |
136 | |
137 (defun holiday-julian (month day string) | |
138 "Holiday on MONTH, DAY (Julian) called STRING. | |
139 If MONTH, DAY (Julian) is visible, the value returned is corresponding | |
140 Gregorian date in the form of the list (((month day year) STRING)). Returns | |
141 nil if it is not visible in the current calendar window." | |
142 (let ((m1 displayed-month) | |
143 (y1 displayed-year) | |
144 (m2 displayed-month) | |
145 (y2 displayed-year) | |
146 (year)) | |
147 (increment-calendar-month m1 y1 -1) | |
148 (increment-calendar-month m2 y2 1) | |
149 (let* ((start-date (calendar-absolute-from-gregorian | |
150 (list m1 1 y1))) | |
151 (end-date (calendar-absolute-from-gregorian | |
152 (list m2 (calendar-last-day-of-month m2 y2) y2))) | |
153 (julian-start (calendar-julian-from-absolute start-date)) | |
154 (julian-end (calendar-julian-from-absolute end-date)) | |
155 (julian-y1 (extract-calendar-year julian-start)) | |
156 (julian-y2 (extract-calendar-year julian-end))) | |
157 (setq year (if (< 10 month) julian-y1 julian-y2)) | |
158 (let ((date (calendar-gregorian-from-absolute | |
159 (calendar-absolute-from-julian | |
160 (list month day year))))) | |
161 (if (calendar-date-is-visible-p date) | |
162 (list (list date string))))))) | |
163 | |
164 (defun diary-julian-date () | |
165 "Julian calendar equivalent of date diary entry." | |
166 (format "Julian date: %s" (calendar-julian-date-string date))) | |
167 | |
168 (defun calendar-absolute-from-astro (d) | |
13673
da11ffac4f8b
(calendar-absolute-from-astro): Doc fix.
Paul Eggert <eggert@twinsun.com>
parents:
13053
diff
changeset
|
169 "Absolute date of astronomical (Julian) day number D." |
13053 | 170 (- d 1721424.5)) |
171 | |
172 (defun calendar-astro-from-absolute (d) | |
173 "Astronomical (Julian) day number of absolute date D." | |
174 (+ d 1721424.5)) | |
175 | |
176 (defun calendar-astro-date-string (&optional date) | |
177 "String of astronomical (Julian) day number after noon UTC of Gregorian DATE. | |
178 Defaults to today's date if DATE is not given." | |
179 (int-to-string | |
180 (ceiling | |
181 (calendar-astro-from-absolute | |
182 (calendar-absolute-from-gregorian | |
183 (or date (calendar-current-date))))))) | |
184 | |
185 (defun calendar-print-astro-day-number () | |
186 "Show astronomical (Julian) day number after noon UTC on date shown by cursor." | |
187 (interactive) | |
188 (message | |
15069
6237f2b08205
Spelling error.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
189 "Astronomical (Julian) day number (at noon UTC): %s.0" |
13053 | 190 (calendar-astro-date-string (calendar-cursor-to-date t)))) |
191 | |
192 (defun calendar-goto-astro-day-number (daynumber &optional noecho) | |
193 "Move cursor to astronomical (Julian) DAYNUMBER. | |
194 Echo astronomical (Julian) day number unless NOECHO is t." | |
195 (interactive (list (calendar-read | |
196 "Astronomical (Julian) day number (>1721425): " | |
197 '(lambda (x) (> x 1721425))))) | |
198 (calendar-goto-date | |
199 (calendar-gregorian-from-absolute | |
200 (floor | |
201 (calendar-absolute-from-astro daynumber)))) | |
202 (or noecho (calendar-print-astro-day-number))) | |
203 | |
204 (defun diary-astro-day-number () | |
205 "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
|
206 (format "Astronomical (Julian) day number at noon UTC: %s.0" |
13053 | 207 (calendar-astro-date-string date))) |
208 | |
209 (provide 'cal-julian) | |
210 | |
211 ;;; cal-julian.el ends here |