Mercurial > emacs
annotate lisp/calendar/cal-julian.el @ 93111:f84051049637
* intervals.c (temp_set_point, temp_set_point_both): Use EMACS_INT.
(set_point, set_point_both): Use EMACS_INT. Remove `buffer' arg,
work on current_buffer only instead (that was already the case
for some of the code anyway).
* buffer.h (set_point, set_point_both): Remove buffer arg, use long int.
(temp_set_point, temp_set_point_both): Use EMACS_INT.
(SET_PT, SET_PT_BOTH): Adjust.
* intervals.h (set_point, temp_set_point, set_point_both)
(temp_set_point_both): Remove redundant declarations.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 20 Mar 2008 18:38:34 +0000 |
parents | bf22321f752b |
children | 1a690de051ab |
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 | |
39 (require 'calendar) | |
40 | |
92912 | 41 (defun calendar-absolute-from-julian (date) |
42 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. | |
43 The Gregorian date Sunday, December 31, 1 BC is imaginary." | |
44 (let ((month (extract-calendar-month date)) | |
45 (year (extract-calendar-year date))) | |
46 (+ (calendar-day-number date) | |
47 (if (and (zerop (% year 100)) | |
48 (not (zerop (% year 400))) | |
49 (> month 2)) | |
50 1 0) ; correct for Julian but not Gregorian leap year | |
51 (* 365 (1- year)) | |
52 (/ (1- year) 4) | |
53 -2))) | |
54 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
55 ;;;###cal-autoload |
13053 | 56 (defun calendar-julian-from-absolute (date) |
57 "Compute the Julian (month day year) corresponding to the absolute DATE. | |
58 The absolute date is the number of days elapsed since the (imaginary) | |
59 Gregorian date Sunday, December 31, 1 BC." | |
92819 | 60 (let* ((approx (/ (+ date 2) 366)) ; approximation from below |
61 (year ; search forward from the approximation | |
13053 | 62 (+ approx |
63 (calendar-sum y approx | |
92912 | 64 (>= date (calendar-absolute-from-julian |
65 (list 1 1 (1+ y)))) | |
66 1))) | |
92819 | 67 (month ; search forward from January |
13053 | 68 (1+ (calendar-sum m 1 |
92912 | 69 (> date |
70 (calendar-absolute-from-julian | |
71 (list m | |
72 (if (and (= m 2) (zerop (% year 4))) | |
73 29 | |
74 (aref [31 28 31 30 31 30 31 | |
75 31 30 31 30 31] | |
76 (1- m))) | |
77 year))) | |
78 1))) | |
92819 | 79 (day ; calculate the day by subtraction |
13053 | 80 (- date (1- (calendar-absolute-from-julian (list month 1 year)))))) |
81 (list month day year))) | |
82 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
83 ;;;###cal-autoload |
13053 | 84 (defun calendar-julian-date-string (&optional date) |
85 "String of Julian date of Gregorian DATE. | |
86 Defaults to today's date if DATE is not given. | |
87 Driven by the variable `calendar-date-display-form'." | |
88 (calendar-date-string | |
89 (calendar-julian-from-absolute | |
92912 | 90 (calendar-absolute-from-gregorian (or date (calendar-current-date)))) |
13053 | 91 nil t)) |
92 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
93 ;;;###cal-autoload |
13053 | 94 (defun calendar-print-julian-date () |
95 "Show the Julian calendar equivalent of the date under the cursor." | |
96 (interactive) | |
97 (message "Julian date: %s" | |
98 (calendar-julian-date-string (calendar-cursor-to-date t)))) | |
99 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
100 ;;;###cal-autoload |
13053 | 101 (defun calendar-goto-julian-date (date &optional noecho) |
92912 | 102 "Move cursor to Julian DATE; echo Julian date unless NOECHO is non-nil." |
13053 | 103 (interactive |
104 (let* ((today (calendar-current-date)) | |
105 (year (calendar-read | |
106 "Julian calendar year (>0): " | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
107 (lambda (x) (> x 0)) |
13053 | 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) | |
54076
9e3e3d184730
(calendar-goto-julian-date): Use assoc-string instead of
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
115 (month (cdr (assoc-string |
92912 | 116 (completing-read |
117 "Julian calendar month name: " | |
118 (mapcar 'list (append month-array nil)) | |
119 nil t) | |
54076
9e3e3d184730
(calendar-goto-julian-date): Use assoc-string instead of
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
120 (calendar-make-alist month-array 1) t))) |
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) | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
128 (lambda (x) |
92912 | 129 (and (< (if (and (= year 1) (= month 1)) 2 0) x) |
130 (<= x last)))))) | |
13053 | 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 | |
92819 | 136 (defvar displayed-month) |
137 (defvar displayed-year) | |
138 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
139 ;;;###holiday-autoload |
13053 | 140 (defun holiday-julian (month day string) |
92819 | 141 "Holiday on MONTH, DAY (Julian) called STRING. |
13053 | 142 If MONTH, DAY (Julian) is visible, the value returned is corresponding |
143 Gregorian date in the form of the list (((month day year) STRING)). Returns | |
144 nil if it is not visible in the current calendar window." | |
145 (let ((m1 displayed-month) | |
146 (y1 displayed-year) | |
147 (m2 displayed-month) | |
148 (y2 displayed-year) | |
149 (year)) | |
150 (increment-calendar-month m1 y1 -1) | |
151 (increment-calendar-month m2 y2 1) | |
152 (let* ((start-date (calendar-absolute-from-gregorian | |
153 (list m1 1 y1))) | |
154 (end-date (calendar-absolute-from-gregorian | |
155 (list m2 (calendar-last-day-of-month m2 y2) y2))) | |
156 (julian-start (calendar-julian-from-absolute start-date)) | |
157 (julian-end (calendar-julian-from-absolute end-date)) | |
158 (julian-y1 (extract-calendar-year julian-start)) | |
159 (julian-y2 (extract-calendar-year julian-end))) | |
160 (setq year (if (< 10 month) julian-y1 julian-y2)) | |
161 (let ((date (calendar-gregorian-from-absolute | |
162 (calendar-absolute-from-julian | |
163 (list month day year))))) | |
164 (if (calendar-date-is-visible-p date) | |
165 (list (list date string))))))) | |
166 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
167 ;;;###cal-autoload |
13053 | 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 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
172 ;;;###cal-autoload |
13053 | 173 (defun calendar-astro-from-absolute (d) |
174 "Astronomical (Julian) day number of absolute date D." | |
175 (+ d 1721424.5)) | |
176 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
177 ;;;###cal-autoload |
13053 | 178 (defun calendar-astro-date-string (&optional date) |
179 "String of astronomical (Julian) day number after noon UTC of Gregorian DATE. | |
180 Defaults to today's date if DATE is not given." | |
181 (int-to-string | |
182 (ceiling | |
183 (calendar-astro-from-absolute | |
92912 | 184 (calendar-absolute-from-gregorian (or date (calendar-current-date))))))) |
13053 | 185 |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
186 ;;;###cal-autoload |
13053 | 187 (defun calendar-print-astro-day-number () |
92819 | 188 "Show astronomical (Julian) day number after noon UTC on cursor date." |
13053 | 189 (interactive) |
190 (message | |
15069
6237f2b08205
Spelling error.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
14169
diff
changeset
|
191 "Astronomical (Julian) day number (at noon UTC): %s.0" |
13053 | 192 (calendar-astro-date-string (calendar-cursor-to-date t)))) |
193 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
194 ;;;###cal-autoload |
13053 | 195 (defun calendar-goto-astro-day-number (daynumber &optional noecho) |
196 "Move cursor to astronomical (Julian) DAYNUMBER. | |
92912 | 197 Echo astronomical (Julian) day number unless NOECHO is non-nil." |
13053 | 198 (interactive (list (calendar-read |
199 "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
|
200 (lambda (x) (> x 1721425))))) |
13053 | 201 (calendar-goto-date |
202 (calendar-gregorian-from-absolute | |
203 (floor | |
204 (calendar-absolute-from-astro daynumber)))) | |
205 (or noecho (calendar-print-astro-day-number))) | |
206 | |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
207 |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
208 (defvar date) |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
209 |
92608
18dc9ef91100
(calendar-absolute-from-julian): Use zerop.
Glenn Morris <rgm@gnu.org>
parents:
92587
diff
changeset
|
210 ;; To be called from list-sexp-diary-entries, where DATE is bound. |
92834
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
211 ;;;###diary-autoload |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
212 (defun diary-julian-date () |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
213 "Julian calendar equivalent of date diary entry." |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
214 (format "Julian date: %s" (calendar-julian-date-string date))) |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
215 |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
216 ;; To be called from list-sexp-diary-entries, where DATE is bound. |
3e0b7b9e8f11
(diary-julian-date): Move to end.
Glenn Morris <rgm@gnu.org>
parents:
92819
diff
changeset
|
217 ;;;###diary-autoload |
13053 | 218 (defun diary-astro-day-number () |
219 "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
|
220 (format "Astronomical (Julian) day number at noon UTC: %s.0" |
13053 | 221 (calendar-astro-date-string date))) |
222 | |
223 (provide 'cal-julian) | |
224 | |
92587
267241a78df9
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
225 ;; arch-tag: 0520acdd-1c60-4188-9aa8-9b8c24d856ae |
13053 | 226 ;;; cal-julian.el ends here |