Mercurial > emacs
annotate lisp/calendar/cal-julian.el @ 51356:8da3b8a0ca4f
(DECODE_EMACS_MULE_COMPOSITION_CHAR): If coding->flags
is nonzero, accept multibyte form of eight-bit-control chars.
(decode_composition_emacs_mule): Likewise.
(decode_coding_emacs_mule): Likewise.
(encode_coding_emacs_mule): If coding->flags is nonzero, produce
multibyte form of eight-bit-control chars.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 31 May 2003 00:56:42 +0000 |
parents | 0d8b17d428b5 |
children | e7d0572ccca5 d7ddb3e565de |
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 |
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) | |
24189
c70c6c750126
(calendar-goto-julian-date): Use assoc-ignore-case and do not
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
115 (month (cdr (assoc-ignore-case |
13053 | 116 (completing-read |
117 "Julian calendar month name: " | |
118 (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
|
119 nil t) |
c70c6c750126
(calendar-goto-julian-date): Use assoc-ignore-case and do not
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
120 (calendar-make-alist month-array 1)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
121 (last |
13053 | 122 (if (and (zerop (% year 4)) (= month 2)) |
123 29 | |
124 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month)))) | |
125 (day (calendar-read | |
126 (format "Julian calendar day (%d-%d): " | |
127 (if (and (= year 1) (= month 1)) 3 1) last) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
128 '(lambda (x) |
13053 | 129 (and (< (if (and (= year 1) (= month 1)) 2 0) x) |
130 (<= x last)))))) | |
131 (list (list month day year)))) | |
132 (calendar-goto-date (calendar-gregorian-from-absolute | |
133 (calendar-absolute-from-julian date))) | |
134 (or noecho (calendar-print-julian-date))) | |
135 | |
136 (defun holiday-julian (month day string) | |
137 "Holiday on MONTH, DAY (Julian) called STRING. | |
138 If MONTH, DAY (Julian) is visible, the value returned is corresponding | |
139 Gregorian date in the form of the list (((month day year) STRING)). Returns | |
140 nil if it is not visible in the current calendar window." | |
141 (let ((m1 displayed-month) | |
142 (y1 displayed-year) | |
143 (m2 displayed-month) | |
144 (y2 displayed-year) | |
145 (year)) | |
146 (increment-calendar-month m1 y1 -1) | |
147 (increment-calendar-month m2 y2 1) | |
148 (let* ((start-date (calendar-absolute-from-gregorian | |
149 (list m1 1 y1))) | |
150 (end-date (calendar-absolute-from-gregorian | |
151 (list m2 (calendar-last-day-of-month m2 y2) y2))) | |
152 (julian-start (calendar-julian-from-absolute start-date)) | |
153 (julian-end (calendar-julian-from-absolute end-date)) | |
154 (julian-y1 (extract-calendar-year julian-start)) | |
155 (julian-y2 (extract-calendar-year julian-end))) | |
156 (setq year (if (< 10 month) julian-y1 julian-y2)) | |
157 (let ((date (calendar-gregorian-from-absolute | |
158 (calendar-absolute-from-julian | |
159 (list month day year))))) | |
160 (if (calendar-date-is-visible-p date) | |
161 (list (list date string))))))) | |
162 | |
163 (defun diary-julian-date () | |
164 "Julian calendar equivalent of date diary entry." | |
165 (format "Julian date: %s" (calendar-julian-date-string date))) | |
166 | |
167 (defun calendar-absolute-from-astro (d) | |
13673
da11ffac4f8b
(calendar-absolute-from-astro): Doc fix.
Paul Eggert <eggert@twinsun.com>
parents:
13053
diff
changeset
|
168 "Absolute date of astronomical (Julian) day number D." |
13053 | 169 (- d 1721424.5)) |
170 | |
171 (defun calendar-astro-from-absolute (d) | |
172 "Astronomical (Julian) day number of absolute date D." | |
173 (+ d 1721424.5)) | |
174 | |
175 (defun calendar-astro-date-string (&optional date) | |
176 "String of astronomical (Julian) day number after noon UTC of Gregorian DATE. | |
177 Defaults to today's date if DATE is not given." | |
178 (int-to-string | |
179 (ceiling | |
180 (calendar-astro-from-absolute | |
181 (calendar-absolute-from-gregorian | |
182 (or date (calendar-current-date))))))) | |
183 | |
184 (defun calendar-print-astro-day-number () | |
185 "Show astronomical (Julian) day number after noon UTC on date shown by cursor." | |
186 (interactive) | |
187 (message | |
15069
6237f2b08205
Spelling error.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
188 "Astronomical (Julian) day number (at noon UTC): %s.0" |
13053 | 189 (calendar-astro-date-string (calendar-cursor-to-date t)))) |
190 | |
191 (defun calendar-goto-astro-day-number (daynumber &optional noecho) | |
192 "Move cursor to astronomical (Julian) DAYNUMBER. | |
193 Echo astronomical (Julian) day number unless NOECHO is t." | |
194 (interactive (list (calendar-read | |
195 "Astronomical (Julian) day number (>1721425): " | |
196 '(lambda (x) (> x 1721425))))) | |
197 (calendar-goto-date | |
198 (calendar-gregorian-from-absolute | |
199 (floor | |
200 (calendar-absolute-from-astro daynumber)))) | |
201 (or noecho (calendar-print-astro-day-number))) | |
202 | |
203 (defun diary-astro-day-number () | |
204 "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
|
205 (format "Astronomical (Julian) day number at noon UTC: %s.0" |
13053 | 206 (calendar-astro-date-string date))) |
207 | |
208 (provide 'cal-julian) | |
209 | |
210 ;;; cal-julian.el ends here |