Mercurial > emacs
annotate lisp/calendar/cal-julian.el @ 70487:737e59692915
* mini.texi (Completion Options):
* tramp.texi (Filename completion): Completion of remote files'
method, user name and host name is active only in partial
completion mode.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Sat, 06 May 2006 21:41:27 +0000 |
parents | 8daf7d9a0771 |
children | 7a3f13e2dd57 4b3d39451150 |
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 |
68721 | 3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006 |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65145
diff
changeset
|
4 ;; 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 | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
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 ;; Comments, corrections, and improvements should be sent to |
38 ;; Edward M. Reingold Department of Computer Science | |
39 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
40 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
41 ;; Urbana, Illinois 61801 | |
42 | |
43 ;;; Code: | |
44 | |
65145
ac895e21e622
(date): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
45 (defvar date) |
52112
e7d0572ccca5
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
46 (defvar displayed-month) |
e7d0572ccca5
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
47 (defvar displayed-year) |
e7d0572ccca5
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
48 |
13053 | 49 (require 'calendar) |
50 | |
51 (defun calendar-julian-from-absolute (date) | |
52 "Compute the Julian (month day year) corresponding to the absolute DATE. | |
53 The absolute date is the number of days elapsed since the (imaginary) | |
54 Gregorian date Sunday, December 31, 1 BC." | |
55 (let* ((approx (/ (+ date 2) 366));; Approximation from below. | |
56 (year ;; Search forward from the approximation. | |
57 (+ approx | |
58 (calendar-sum y approx | |
59 (>= date (calendar-absolute-from-julian (list 1 1 (1+ y)))) | |
60 1))) | |
61 (month ;; Search forward from January. | |
62 (1+ (calendar-sum m 1 | |
63 (> date | |
64 (calendar-absolute-from-julian | |
65 (list m | |
66 (if (and (= m 2) (= (% year 4) 0)) | |
67 29 | |
68 (aref [31 28 31 30 31 30 31 31 30 31 30 31] | |
69 (1- m))) | |
70 year))) | |
71 1))) | |
72 (day ;; Calculate the day by subtraction. | |
73 (- date (1- (calendar-absolute-from-julian (list month 1 year)))))) | |
74 (list month day year))) | |
75 | |
76 (defun calendar-absolute-from-julian (date) | |
77 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. | |
78 The Gregorian date Sunday, December 31, 1 BC is imaginary." | |
79 (let ((month (extract-calendar-month date)) | |
80 (day (extract-calendar-day date)) | |
81 (year (extract-calendar-year date))) | |
82 (+ (calendar-day-number date) | |
83 (if (and (= (% year 100) 0) | |
84 (/= (% year 400) 0) | |
85 (> month 2)) | |
86 1 0);; Correct for Julian but not Gregorian leap year. | |
87 (* 365 (1- year)) | |
88 (/ (1- year) 4) | |
89 -2))) | |
90 | |
91 (defun calendar-julian-date-string (&optional date) | |
92 "String of Julian date of Gregorian DATE. | |
93 Defaults to today's date if DATE is not given. | |
94 Driven by the variable `calendar-date-display-form'." | |
95 (calendar-date-string | |
96 (calendar-julian-from-absolute | |
97 (calendar-absolute-from-gregorian | |
98 (or date (calendar-current-date)))) | |
99 nil t)) | |
100 | |
101 (defun calendar-print-julian-date () | |
102 "Show the Julian calendar equivalent of the date under the cursor." | |
103 (interactive) | |
104 (message "Julian date: %s" | |
105 (calendar-julian-date-string (calendar-cursor-to-date t)))) | |
106 | |
107 (defun calendar-goto-julian-date (date &optional noecho) | |
108 "Move cursor to Julian DATE; echo Julian date unless NOECHO is t." | |
109 (interactive | |
110 (let* ((today (calendar-current-date)) | |
111 (year (calendar-read | |
112 "Julian calendar year (>0): " | |
113 '(lambda (x) (> x 0)) | |
114 (int-to-string | |
115 (extract-calendar-year | |
116 (calendar-julian-from-absolute | |
117 (calendar-absolute-from-gregorian | |
118 today)))))) | |
119 (month-array calendar-month-name-array) | |
120 (completion-ignore-case t) | |
54076
9e3e3d184730
(calendar-goto-julian-date): Use assoc-string instead of
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
121 (month (cdr (assoc-string |
13053 | 122 (completing-read |
123 "Julian calendar month name: " | |
124 (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
|
125 nil t) |
54076
9e3e3d184730
(calendar-goto-julian-date): Use assoc-string instead of
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
126 (calendar-make-alist month-array 1) t))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
127 (last |
13053 | 128 (if (and (zerop (% year 4)) (= month 2)) |
129 29 | |
130 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month)))) | |
131 (day (calendar-read | |
132 (format "Julian calendar day (%d-%d): " | |
133 (if (and (= year 1) (= month 1)) 3 1) last) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
134 '(lambda (x) |
13053 | 135 (and (< (if (and (= year 1) (= month 1)) 2 0) x) |
136 (<= x last)))))) | |
137 (list (list month day year)))) | |
138 (calendar-goto-date (calendar-gregorian-from-absolute | |
139 (calendar-absolute-from-julian date))) | |
140 (or noecho (calendar-print-julian-date))) | |
141 | |
142 (defun holiday-julian (month day string) | |
143 "Holiday on MONTH, DAY (Julian) called STRING. | |
144 If MONTH, DAY (Julian) is visible, the value returned is corresponding | |
145 Gregorian date in the form of the list (((month day year) STRING)). Returns | |
146 nil if it is not visible in the current calendar window." | |
147 (let ((m1 displayed-month) | |
148 (y1 displayed-year) | |
149 (m2 displayed-month) | |
150 (y2 displayed-year) | |
151 (year)) | |
152 (increment-calendar-month m1 y1 -1) | |
153 (increment-calendar-month m2 y2 1) | |
154 (let* ((start-date (calendar-absolute-from-gregorian | |
155 (list m1 1 y1))) | |
156 (end-date (calendar-absolute-from-gregorian | |
157 (list m2 (calendar-last-day-of-month m2 y2) y2))) | |
158 (julian-start (calendar-julian-from-absolute start-date)) | |
159 (julian-end (calendar-julian-from-absolute end-date)) | |
160 (julian-y1 (extract-calendar-year julian-start)) | |
161 (julian-y2 (extract-calendar-year julian-end))) | |
162 (setq year (if (< 10 month) julian-y1 julian-y2)) | |
163 (let ((date (calendar-gregorian-from-absolute | |
164 (calendar-absolute-from-julian | |
165 (list month day year))))) | |
166 (if (calendar-date-is-visible-p date) | |
167 (list (list date string))))))) | |
168 | |
169 (defun diary-julian-date () | |
170 "Julian calendar equivalent of date diary entry." | |
171 (format "Julian date: %s" (calendar-julian-date-string date))) | |
172 | |
173 (defun calendar-absolute-from-astro (d) | |
13673
da11ffac4f8b
(calendar-absolute-from-astro): Doc fix.
Paul Eggert <eggert@twinsun.com>
parents:
13053
diff
changeset
|
174 "Absolute date of astronomical (Julian) day number D." |
13053 | 175 (- d 1721424.5)) |
176 | |
177 (defun calendar-astro-from-absolute (d) | |
178 "Astronomical (Julian) day number of absolute date D." | |
179 (+ d 1721424.5)) | |
180 | |
181 (defun calendar-astro-date-string (&optional date) | |
182 "String of astronomical (Julian) day number after noon UTC of Gregorian DATE. | |
183 Defaults to today's date if DATE is not given." | |
184 (int-to-string | |
185 (ceiling | |
186 (calendar-astro-from-absolute | |
187 (calendar-absolute-from-gregorian | |
188 (or date (calendar-current-date))))))) | |
189 | |
190 (defun calendar-print-astro-day-number () | |
191 "Show astronomical (Julian) day number after noon UTC on date shown by cursor." | |
192 (interactive) | |
193 (message | |
15069
6237f2b08205
Spelling error.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
194 "Astronomical (Julian) day number (at noon UTC): %s.0" |
13053 | 195 (calendar-astro-date-string (calendar-cursor-to-date t)))) |
196 | |
197 (defun calendar-goto-astro-day-number (daynumber &optional noecho) | |
198 "Move cursor to astronomical (Julian) DAYNUMBER. | |
199 Echo astronomical (Julian) day number unless NOECHO is t." | |
200 (interactive (list (calendar-read | |
201 "Astronomical (Julian) day number (>1721425): " | |
202 '(lambda (x) (> x 1721425))))) | |
203 (calendar-goto-date | |
204 (calendar-gregorian-from-absolute | |
205 (floor | |
206 (calendar-absolute-from-astro daynumber)))) | |
207 (or noecho (calendar-print-astro-day-number))) | |
208 | |
209 (defun diary-astro-day-number () | |
210 "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
|
211 (format "Astronomical (Julian) day number at noon UTC: %s.0" |
13053 | 212 (calendar-astro-date-string date))) |
213 | |
214 (provide 'cal-julian) | |
215 | |
52401 | 216 ;;; arch-tag: 0520acdd-1c60-4188-9aa8-9b8c24d856ae |
13053 | 217 ;;; cal-julian.el ends here |