Mercurial > emacs
annotate lisp/calendar/solar.el @ 7885:bc6406a90796
(init_eval_once): Call xmalloc, not malloc.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 14 Jun 1994 19:48:19 +0000 |
parents | b0e2bd1e825a |
children | c14b023ca6fe |
rev | line source |
---|---|
956 | 1 ;;; solar.el --- calendar functions for solar events. |
2 | |
5835
1c685c3bd5a9
(calendar-sunrise-sunset): Use new error arg to calendar-cursor-to-date.
Richard M. Stallman <rms@gnu.org>
parents:
5698
diff
changeset
|
3 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. |
956 | 4 |
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
2249
94fc2ce49c55
Corrected Keywords header
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2248
diff
changeset
|
6 ;; Keywords: calendar |
94fc2ce49c55
Corrected Keywords header
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2248
diff
changeset
|
7 ;; Human-Keywords: sunrise, sunset, equinox, solstice, calendar, diary, |
94fc2ce49c55
Corrected Keywords header
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2248
diff
changeset
|
8 ;; holidays |
956 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
15 ;; any later version. |
956 | 16 |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
20 ;; GNU General Public License for more details. |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
21 |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5835
diff
changeset
|
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
956 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the features of calendar.el and | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
29 ;; diary.el that deal with times of day, sunrise/sunset, and |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
30 ;; eqinoxes/solstices. |
956 | 31 |
32 ;; Based on the ``Almanac for Computers 1984,'' prepared by the Nautical | |
33 ;; Almanac Office, United States Naval Observatory, Washington, 1984 and | |
34 ;; on ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus, | |
35 ;; Willmann-Bell, Inc., 1985. | |
36 ;; | |
37 ;; WARNINGS: | |
38 ;; 1. SUNRISE/SUNSET calculations will be accurate only to +/- 2 minutes. | |
39 ;; Locations should be between +/- 65 degrees of latitude. | |
40 ;; Dates should be in the latter half of the 20th century. | |
41 ;; | |
42 ;; 2. Equinox/solstice times will be accurate only to +/- 15 minutes. | |
43 | |
44 ;; The author would be delighted to have an astronomically more sophisticated | |
45 ;; person rewrite the code for the solar calculations in this file! | |
46 | |
47 ;; Comments, corrections, and improvements should be sent to | |
48 ;; Edward M. Reingold Department of Computer Science | |
49 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
50 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
51 ;; Urbana, Illinois 61801 | |
52 | |
53 ;;; Code: | |
54 | |
55 (if (fboundp 'atan) | |
56 (require 'lisp-float-type) | |
57 (error "Solar calculations impossible since floating point is unavailable.")) | |
58 | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
59 (require 'cal-dst) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
60 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
61 ;;;###autoload |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
62 (defvar calendar-time-display-form |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
63 '(12-hours ":" minutes am-pm |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
64 (if time-zone " (") time-zone (if time-zone ")")) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
65 "*The pseudo-pattern that governs the way a time of day is formatted. |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
66 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
67 A pseudo-pattern is a list of expressions that can involve the keywords |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
68 `12-hours', `24-hours', and `minutes', all numbers in string form, |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
69 and `am-pm' and `time-zone', both alphabetic strings. |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
70 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
71 For example, the form |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
72 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
73 '(24-hours \":\" minutes |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
74 (if time-zone \" (\") time-zone (if time-zone \")\")) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
75 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
76 would give military-style times like `21:07 (UTC)'.") |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
77 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
78 ;;;###autoload |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
79 (defvar calendar-latitude nil |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
80 "*Latitude of `calendar-location-name' in degrees, + north, - south. |
3907 | 81 For example, 40.7 for New York City. |
82 It may not be a good idea to set this in advance for your site; | |
83 if there may be users running Emacs at your site | |
84 who are physically located elsewhere, they would get the wrong | |
85 value and might not know how to override it.") | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
86 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
87 ;;;###autoload |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
88 (defvar calendar-longitude nil |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
89 "*Longitude of `calendar-location-name' in degrees, + east, - west. |
3907 | 90 For example, -74.0 for New York City. |
91 It may not be a good idea to set this in advance for your site; | |
92 if there may be users running Emacs at your site | |
93 who are physically located elsewhere, they would get the wrong | |
94 value and might not know how to override it.") | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
95 |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
96 ;;;###autoload |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
97 (defvar calendar-location-name |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
98 '(let ((float-output-format "%.1f")) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
99 (format "%s%s, %s%s" |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
100 (abs calendar-latitude) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
101 (if (> calendar-latitude 0) "N" "S") |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
102 (abs calendar-longitude) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
103 (if (> calendar-longitude 0) "E" "W"))) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
104 "*Expression evaluating to name of `calendar-longitude', calendar-latitude'. |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
105 Default value is just the latitude, longitude pair.") |
956 | 106 |
4863
adfd03a381ca
(solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
4766
diff
changeset
|
107 (defvar solar-n-hemi-seasons |
4766
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
108 '("Vernal Equinox" "Summer Solstice" "Autumnal Equinox" "Winter Solstice") |
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
109 "List of season changes for the northern hemisphere.") |
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
110 |
4863
adfd03a381ca
(solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
4766
diff
changeset
|
111 (defvar solar-s-hemi-seasons |
4766
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
112 '("Autumnal Equinox" "Winter Solstice" "Vernal Equinox" "Summer Solstice") |
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
113 "List of season changes for the southern hemisphere.") |
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
114 |
956 | 115 (defun solar-setup () |
116 "Prompt user for latitude, longitude, and time zone." | |
117 (beep) | |
118 (if (not calendar-longitude) | |
119 (setq calendar-longitude | |
120 (solar-get-number | |
121 "Enter longitude (decimal fraction; + east, - west): "))) | |
122 (if (not calendar-latitude) | |
123 (setq calendar-latitude | |
124 (solar-get-number | |
125 "Enter latitude (decimal fraction; + north, - south): "))) | |
126 (if (not calendar-time-zone) | |
127 (setq calendar-time-zone | |
128 (solar-get-number | |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
129 "Enter difference from Coordinated Universal Time (in minutes): ")))) |
956 | 130 |
131 (defun solar-get-number (prompt) | |
132 "Return a number from the minibuffer, prompting with PROMPT. | |
133 Returns nil if nothing was entered." | |
134 (let ((x (read-string prompt ""))) | |
135 (if (not (string-equal x "")) | |
136 (string-to-int x)))) | |
137 | |
138 (defun solar-sin-degrees (x) | |
139 (sin (degrees-to-radians x))) | |
140 | |
141 (defun solar-cosine-degrees (x) | |
142 (cos (degrees-to-radians x))) | |
143 | |
144 (defun solar-tangent-degrees (x) | |
145 (tan (degrees-to-radians x))) | |
146 | |
147 (defun solar-xy-to-quadrant (x y) | |
148 "Determines the quadrant of the point X, Y." | |
149 (if (> x 0) | |
150 (if (> y 0) 1 4) | |
151 (if (> y 0) 2 3))) | |
152 | |
153 (defun solar-degrees-to-quadrant (angle) | |
154 "Determines the quadrant of ANGLE." | |
4660
2516bc453477
Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents:
4657
diff
changeset
|
155 (1+ (floor (mod angle 360) 90))) |
956 | 156 |
157 (defun solar-arctan (x quad) | |
158 "Arctangent of X in quadrant QUAD." | |
159 (let ((deg (radians-to-degrees (atan x)))) | |
160 (cond ((equal quad 2) (+ deg 180)) | |
161 ((equal quad 3) (+ deg 180)) | |
162 ((equal quad 4) (+ deg 360)) | |
163 (t deg)))) | |
164 | |
165 (defun solar-arccos (x) | |
166 (let ((y (sqrt (- 1 (* x x))))) | |
167 (solar-arctan (/ y x) (solar-xy-to-quadrant x y)))) | |
168 | |
169 (defun solar-arcsin (y) | |
170 (let ((x (sqrt (- 1 (* y y))))) | |
171 (solar-arctan (/ y x) (solar-xy-to-quadrant x y)))) | |
172 | |
173 (defconst solar-earth-inclination 23.441884 | |
174 "Inclination of earth's equator to its solar orbit in degrees.") | |
175 | |
176 (defconst solar-cos-inclination (solar-cosine-degrees solar-earth-inclination) | |
177 "Cosine of earth's inclination.") | |
178 | |
179 (defconst solar-sin-inclination (solar-sin-degrees solar-earth-inclination) | |
180 "Sine of earth's inclination.") | |
181 | |
182 (defconst solar-earth-orbit-eccentricity 0.016718 | |
183 "Eccentricity of orbit of the earth around the sun.") | |
184 | |
185 (defmacro solar-degrees-to-hours (deg) | |
7248
48ef5c3465ae
(solar-degrees-to-hours, solar-hours-to-days): Force floating result.
Richard M. Stallman <rms@gnu.org>
parents:
6736
diff
changeset
|
186 (list '/ deg 15.0)) |
956 | 187 |
188 (defmacro solar-hours-to-days (hour) | |
7248
48ef5c3465ae
(solar-degrees-to-hours, solar-hours-to-days): Force floating result.
Richard M. Stallman <rms@gnu.org>
parents:
6736
diff
changeset
|
189 (list '/ hour 24.0)) |
956 | 190 |
191 (defun solar-longitude-of-sun (day) | |
192 "Longitude of the sun at DAY in the year." | |
193 (let ((mean-anomaly (- (* 0.9856 day) 3.289))) | |
4519
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
194 (mod (+ mean-anomaly |
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
195 (* 1.916 (solar-sin-degrees mean-anomaly)) |
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
196 (* 0.020 (solar-sin-degrees (* 2 mean-anomaly))) |
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
197 282.634) |
4660
2516bc453477
Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents:
4657
diff
changeset
|
198 360))) |
956 | 199 |
200 (defun solar-right-ascension (longitude) | |
201 "Right ascension of the sun, given its LONGITUDE." | |
202 (solar-degrees-to-hours | |
203 (solar-arctan | |
204 (* solar-cos-inclination (solar-tangent-degrees longitude)) | |
205 (solar-degrees-to-quadrant longitude)))) | |
206 | |
207 (defun solar-declination (longitude) | |
208 "Declination of the sun, given its LONGITUDE." | |
209 (solar-arcsin | |
210 (* solar-sin-inclination | |
211 (solar-sin-degrees longitude)))) | |
212 | |
213 (defun solar-sunrise (date) | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
214 "Calculates the *standard* time of sunrise for Gregorian DATE. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
215 Calculation is for location given by `calendar-latitude' and |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
216 `calendar-longitude'. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
217 |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
218 Returns a decimal fraction of hours. Returns nil if the sun does not rise at |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
219 that location on that day." |
956 | 220 (let* ((day-of-year (calendar-day-number date)) |
221 (approx-sunrise | |
222 (+ day-of-year | |
223 (solar-hours-to-days | |
224 (- 6 (solar-degrees-to-hours calendar-longitude))))) | |
225 (solar-longitude-of-sun-at-sunrise | |
226 (solar-longitude-of-sun approx-sunrise)) | |
227 (solar-right-ascension-at-sunrise | |
228 (solar-right-ascension solar-longitude-of-sun-at-sunrise)) | |
229 (solar-declination-at-sunrise | |
230 (solar-declination solar-longitude-of-sun-at-sunrise)) | |
231 (cos-local-sunrise | |
232 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0))) | |
233 (* (solar-sin-degrees solar-declination-at-sunrise) | |
234 (solar-sin-degrees calendar-latitude))) | |
235 (* (solar-cosine-degrees solar-declination-at-sunrise) | |
236 (solar-cosine-degrees calendar-latitude))))) | |
237 (if (<= (abs cos-local-sunrise) 1);; otherwise, no sunrise that day | |
238 (let* ((local-sunrise (solar-degrees-to-hours | |
239 (- 360 (solar-arccos cos-local-sunrise)))) | |
240 (local-mean-sunrise | |
4519
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
241 (mod (- (+ local-sunrise solar-right-ascension-at-sunrise) |
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
242 (+ (* 0.065710 approx-sunrise) |
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
243 6.622)) |
4660
2516bc453477
Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents:
4657
diff
changeset
|
244 24))) |
956 | 245 (+ (- local-mean-sunrise (solar-degrees-to-hours calendar-longitude)) |
246 (/ calendar-time-zone 60.0)))))) | |
247 | |
248 (defun solar-sunset (date) | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
249 "Calculates the *standard* time of sunset for Gregorian DATE. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
250 Calculation is for location given by `calendar-latitude' and |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
251 `calendar-longitude'. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
252 |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
253 Returns a decimal fractions of hours. Returns nil if the sun does not set at |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
254 that location on that day." |
956 | 255 (let* ((day-of-year (calendar-day-number date)) |
256 (approx-sunset | |
257 (+ day-of-year | |
258 (solar-hours-to-days | |
259 (- 18 (solar-degrees-to-hours calendar-longitude))))) | |
260 (solar-longitude-of-sun-at-sunset | |
261 (solar-longitude-of-sun approx-sunset)) | |
262 (solar-right-ascension-at-sunset | |
263 (solar-right-ascension solar-longitude-of-sun-at-sunset)) | |
264 (solar-declination-at-sunset | |
265 (solar-declination solar-longitude-of-sun-at-sunset)) | |
266 (cos-local-sunset | |
267 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0))) | |
268 (* (solar-sin-degrees solar-declination-at-sunset) | |
269 (solar-sin-degrees calendar-latitude))) | |
270 (* (solar-cosine-degrees solar-declination-at-sunset) | |
271 (solar-cosine-degrees calendar-latitude))))) | |
272 (if (<= (abs cos-local-sunset) 1);; otherwise, no sunset that day | |
273 (let* ((local-sunset (solar-degrees-to-hours | |
274 (solar-arccos cos-local-sunset))) | |
275 (local-mean-sunset | |
4519
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
276 (mod (- (+ local-sunset solar-right-ascension-at-sunset) |
c8f5e05c332e
(siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents:
3907
diff
changeset
|
277 (+ (* 0.065710 approx-sunset) 6.622)) |
4660
2516bc453477
Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents:
4657
diff
changeset
|
278 24))) |
956 | 279 (+ (- local-mean-sunset (solar-degrees-to-hours calendar-longitude)) |
280 (/ calendar-time-zone 60.0)))))) | |
281 | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
282 (defun solar-adj-time-for-dst (date time &optional style) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
283 "Adjust decimal fraction standard TIME on DATE to account for dst. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
284 Returns a list (date adj-time zone) where `date' and `time' are the values |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
285 adjusted for `zone'; here `date' is a list (month day year), `time' is a |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
286 decimal fraction time, and `zone' is a string. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
287 |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
288 Optional parameter STYLE forces the result time to be standard time when its |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
289 value is 'standard and daylight savings time (if available) when its value is |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
290 'daylight. |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
291 |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
292 Conversion to daylight savings time is done according to |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
293 `calendar-daylight-savings-starts', `calendar-daylight-savings-ends', |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
294 `calendar-daylight-savings-starts-time', |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
295 `calendar-daylight-savings-ends-time', and |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
296 `calendar-daylight-savings-offset'." |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
297 |
956 | 298 (let* ((year (extract-calendar-year date)) |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
299 (rounded-abs-date (+ (calendar-absolute-from-gregorian date) |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
300 (/ (round (* 60 time)) 60.0 24.0))) |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
301 (dst-starts (and calendar-daylight-savings-starts |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
302 (+ (calendar-absolute-from-gregorian |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
303 (eval calendar-daylight-savings-starts)) |
4657 | 304 (/ calendar-daylight-savings-starts-time |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
305 60.0 24.0)))) |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
306 (dst-ends (and calendar-daylight-savings-ends |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
307 (+ (calendar-absolute-from-gregorian |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
308 (eval calendar-daylight-savings-ends)) |
4657 | 309 (/ (- calendar-daylight-savings-ends-time |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
310 calendar-daylight-time-offset) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
311 60.0 24.0)))) |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
312 (dst (and (not (eq style 'standard)) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
313 (or (eq style 'daylight) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
314 (and dst-starts dst-ends |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
315 (or (and (< dst-starts dst-ends);; northern hemi. |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
316 (<= dst-starts rounded-abs-date) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
317 (< rounded-abs-date dst-ends)) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
318 (and (< dst-ends dst-starts);; southern hemi. |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
319 (or (< rounded-abs-date dst-ends) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
320 (<= dst-starts rounded-abs-date))))) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
321 (and dst-starts (not dst-ends) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
322 (<= dst-starts rounded-abs-date)) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
323 (and dst-ends (not dst-starts) |
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
324 (< rounded-abs-date dst-ends))))) |
956 | 325 (time-zone (if dst |
326 calendar-daylight-time-zone-name | |
327 calendar-standard-time-zone-name)) | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
328 (time (+ rounded-abs-date |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
329 (if dst (/ calendar-daylight-time-offset 24.0 60.0) 0)))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
330 (list (calendar-gregorian-from-absolute (truncate time)) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
331 (* 24.0 (- time (truncate time))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
332 time-zone))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
333 |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
334 (defun solar-time-string (time time-zone) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
335 "Printable form for decimal fraction TIME on DATE. |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
336 Format used is given by `calendar-time-display-form'." |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
337 (let* ((time (round (* 60 time))) |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
338 (24-hours (/ time 60)) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
339 (minutes (format "%02d" (% time 60))) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
340 (12-hours (format "%d" (1+ (% (+ 24-hours 11) 12)))) |
956 | 341 (am-pm (if (>= 24-hours 12) "pm" "am")) |
342 (24-hours (format "%02d" 24-hours))) | |
343 (mapconcat 'eval calendar-time-display-form ""))) | |
344 | |
345 (defun solar-sunrise-sunset (date) | |
346 "String giving local times of sunrise and sunset on Gregorian DATE." | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
347 (let* ((rise (solar-sunrise date)) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
348 (adj-rise (solar-adj-time-for-dst date rise)) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
349 (set (solar-sunset date)) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
350 (adj-set (solar-adj-time-for-dst date set))) |
956 | 351 (format "%s, %s at %s" |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
352 (if (and rise (calendar-date-equal date (car adj-rise))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
353 (concat "Sunrise " (apply 'solar-time-string (cdr adj-rise))) |
956 | 354 "No sunrise") |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
355 (if (and set (calendar-date-equal date (car adj-set))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
356 (concat "sunset " (apply 'solar-time-string (cdr adj-set))) |
956 | 357 "no sunset") |
358 (eval calendar-location-name)))) | |
359 | |
360 (defun solar-apparent-longitude-of-sun (date) | |
361 "Apparent longitude of the sun on Gregorian DATE." | |
362 (let* ((time (/ (- (calendar-absolute-from-gregorian date) | |
363 (calendar-absolute-from-gregorian '(1 0.5 1900))) | |
364 36525)) | |
365 (l (+ 279.69668 | |
366 (* 36000.76892 time) | |
367 (* 0.0003025 time time))) | |
368 (m (+ 358.47583 | |
369 (* 35999.04975 time) | |
370 (* -0.000150 time time) | |
371 (* -0.0000033 time time time))) | |
372 (c (+ (* (+ 1.919460 | |
373 (* -0.004789 time) | |
374 (* -0.000014 time time)) | |
375 (solar-sin-degrees m)) | |
376 (* (+ 0.020094 | |
377 (* -0.000100 time)) | |
378 (solar-sin-degrees (* 2 m))) | |
379 (* 0.000293 | |
380 (solar-sin-degrees (* 3 m))))) | |
381 (L (+ l c)) | |
382 (omega (+ 259.18 | |
383 (* -1934.142 time))) | |
384 (app (+ L | |
385 -0.00569 | |
386 (* -0.00479 | |
387 (solar-sin-degrees omega))))) | |
388 app)) | |
389 | |
390 (defun solar-ephemeris-correction (year) | |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
391 "Difference in minutes between Ephemeris time and UTC in YEAR. |
956 | 392 Value is only an approximation." |
393 (let ((T (/ (- year 1900) 100.0))) | |
394 (+ 0.41 (* 1.2053 T) (* 0.4992 T T)))) | |
395 | |
396 (defun solar-equinoxes/solstices (k year) | |
397 "Date of equinox/solstice K for YEAR. K=0, spring equinox; K=1, summer | |
398 solstice; K=2, fall equinox; K=3, winter solstice. Accurate to within | |
399 several minutes." | |
400 (let ((date (list (+ 3 (* k 3)) 21 year)) | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
401 app |
956 | 402 (correction 1000)) |
403 (while (> correction 0.00001) | |
4660
2516bc453477
Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents:
4657
diff
changeset
|
404 (setq app (mod (solar-apparent-longitude-of-sun date) 360)) |
956 | 405 (setq correction (* 58 (solar-sin-degrees (- (* k 90) app)))) |
406 (setq date (list (extract-calendar-month date) | |
407 (+ (extract-calendar-day date) correction) | |
408 year))) | |
409 (list (extract-calendar-month date) | |
410 (+ (extract-calendar-day date) (/ calendar-time-zone 60.0 24.0) | |
411 (- (/ (solar-ephemeris-correction year) 60.0 24.0))) | |
412 year))) | |
413 | |
414 ;;;###autoload | |
415 (defun sunrise-sunset (&optional arg) | |
416 "Local time of sunrise and sunset for today. Accurate to +/- 2 minutes. | |
7255
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
417 If called with an optional prefix argument, prompt for date. |
956 | 418 |
7255
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
419 If called with an optional double prefix argument, prompt for longitude, |
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
420 latitude, time zone, and date, and always use standard time. |
956 | 421 |
422 This function is suitable for execution in a .emacs file." | |
423 (interactive "p") | |
5835
1c685c3bd5a9
(calendar-sunrise-sunset): Use new error arg to calendar-cursor-to-date.
Richard M. Stallman <rms@gnu.org>
parents:
5698
diff
changeset
|
424 (or arg (setq arg 1)) |
998 | 425 (if (and (< arg 16) |
426 (not (and calendar-latitude calendar-longitude calendar-time-zone))) | |
427 (solar-setup)) | |
956 | 428 (let* ((calendar-longitude |
998 | 429 (if (< arg 16) calendar-longitude |
956 | 430 (solar-get-number |
431 "Enter longitude (decimal fraction; + east, - west): "))) | |
432 (calendar-latitude | |
998 | 433 (if (< arg 16) calendar-latitude |
956 | 434 (solar-get-number |
435 "Enter latitude (decimal fraction; + north, - south): "))) | |
436 (calendar-time-zone | |
998 | 437 (if (< arg 16) calendar-time-zone |
956 | 438 (solar-get-number |
3779
e9961fa24193
*solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
439 "Enter difference from Coordinated Universal Time (in minutes): "))) |
956 | 440 (calendar-location-name |
998 | 441 (if (< arg 16) calendar-location-name |
442 (let ((float-output-format "%.1f")) | |
443 (format "%s%s, %s%s" | |
444 (abs calendar-latitude) | |
445 (if (> calendar-latitude 0) "N" "S") | |
446 (abs calendar-longitude) | |
447 (if (> calendar-longitude 0) "E" "W"))))) | |
956 | 448 (calendar-standard-time-zone-name |
998 | 449 (if (< arg 16) calendar-standard-time-zone-name |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
450 (cond ((= calendar-time-zone 0) "UTC") |
998 | 451 ((< calendar-time-zone 0) |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
452 (format "UTC%dmin" calendar-time-zone)) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
453 (t (format "UTC+%dmin" calendar-time-zone))))) |
7255
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
454 (calendar-daylight-savings-starts |
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
455 (if (< arg 16) calendar-daylight-savings-starts)) |
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
456 (calendar-daylight-savings-ends |
c79c14e28d71
(sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
7248
diff
changeset
|
457 (if (< arg 16) calendar-daylight-savings-ends)) |
998 | 458 (date (if (< arg 4) (calendar-current-date) (calendar-read-date))) |
956 | 459 (date-string (calendar-date-string date t)) |
460 (time-string (solar-sunrise-sunset date)) | |
461 (msg (format "%s: %s" date-string time-string)) | |
462 (one-window (one-window-p t))) | |
4651
7ca17b5fd85e
* solar.el (solar-sunrise, solar-sunset, solar-longitude-of-sun):
Jim Blandy <jimb@redhat.com>
parents:
4519
diff
changeset
|
463 (if (<= (length msg) (frame-width)) |
956 | 464 (message msg) |
465 (with-output-to-temp-buffer "*temp*" | |
466 (princ (concat date-string "\n" time-string))) | |
467 (message (substitute-command-keys | |
468 (if one-window | |
469 (if pop-up-windows | |
470 "Type \\[delete-other-windows] to remove temp window." | |
471 "Type \\[switch-to-buffer] RET to remove temp window.") | |
472 "Type \\[switch-to-buffer-other-window] RET to restore old contents of temp window.")))))) | |
473 | |
474 (defun calendar-sunrise-sunset () | |
475 "Local time of sunrise and sunset for date under cursor. | |
476 Accurate to +/- 2 minutes." | |
477 (interactive) | |
478 (if (not (and calendar-latitude calendar-longitude calendar-time-zone)) | |
479 (solar-setup)) | |
5835
1c685c3bd5a9
(calendar-sunrise-sunset): Use new error arg to calendar-cursor-to-date.
Richard M. Stallman <rms@gnu.org>
parents:
5698
diff
changeset
|
480 (let ((date (calendar-cursor-to-date t))) |
5698
d127e0963a2c
(calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents:
5010
diff
changeset
|
481 (message "%s: %s" |
d127e0963a2c
(calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents:
5010
diff
changeset
|
482 (calendar-date-string date t t) |
d127e0963a2c
(calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents:
5010
diff
changeset
|
483 (solar-sunrise-sunset date)))) |
956 | 484 |
485 (defun diary-sunrise-sunset () | |
486 "Local time of sunrise and sunset as a diary entry. | |
487 Accurate to +/- 2 minutes." | |
488 (if (not (and calendar-latitude calendar-longitude calendar-time-zone)) | |
489 (solar-setup)) | |
490 (solar-sunrise-sunset date)) | |
491 | |
492 (defun diary-sabbath-candles () | |
493 "Local time of candle lighting diary entry--applies if date is a Friday. | |
494 No diary entry if there is no sunset on that date." | |
495 (if (not (and calendar-latitude calendar-longitude calendar-time-zone)) | |
496 (solar-setup)) | |
497 (if (= (% (calendar-absolute-from-gregorian date) 7) 5);; Friday | |
498 (let* ((sunset (solar-sunset date)) | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
499 (light (if sunset |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
500 (solar-adj-time-for-dst |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
501 date |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
502 (- sunset (/ 18.0 60.0)))))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
503 (if (and light (calendar-date-equal date (car light))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
504 (format "%s Sabbath candle lighting" |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
505 (apply 'solar-time-string (cdr light))))))) |
956 | 506 |
5010
9595049f63a9
(solar-equinoxes-solstices): Add autoload.
Richard M. Stallman <rms@gnu.org>
parents:
4863
diff
changeset
|
507 ;;;###autoload |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
508 (defun solar-equinoxes-solstices () |
956 | 509 "Date and time of equinoxes and solstices, if visible in the calendar window. |
510 Requires floating point." | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
511 (let ((m displayed-month) |
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
512 (y displayed-year)) |
956 | 513 (increment-calendar-month m y (cond ((= 1 (% m 3)) -1) |
514 ((= 2 (% m 3)) 1) | |
515 (t 0))) | |
516 (let* ((calendar-standard-time-zone-name | |
3866
c97c63c1a920
* solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents:
3779
diff
changeset
|
517 (if calendar-time-zone calendar-standard-time-zone-name "UTC")) |
956 | 518 (calendar-daylight-savings-starts |
519 (if calendar-time-zone calendar-daylight-savings-starts)) | |
520 (calendar-daylight-savings-ends | |
521 (if calendar-time-zone calendar-daylight-savings-ends)) | |
522 (calendar-time-zone (if calendar-time-zone calendar-time-zone 0)) | |
523 (k (1- (/ m 3))) | |
524 (date (solar-equinoxes/solstices k y)) | |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
525 (s-hemi (and calendar-latitude (< calendar-latitude 0))) |
956 | 526 (day (extract-calendar-day date)) |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
527 (adj (solar-adj-time-for-dst |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
528 (list (extract-calendar-month date) |
956 | 529 (truncate day) |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
530 (extract-calendar-year date)) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
531 (* 24 (- day (truncate day)))))) |
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
532 (list (list (car adj) |
4766
ec8c8721b7e3
(s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents:
4660
diff
changeset
|
533 (format "%s %s" |
4863
adfd03a381ca
(solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
4766
diff
changeset
|
534 (nth k (if s-hemi solar-s-hemi-seasons |
adfd03a381ca
(solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents:
4766
diff
changeset
|
535 solar-n-hemi-seasons)) |
7778
b0e2bd1e825a
(solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7255
diff
changeset
|
536 (apply 'solar-time-string (cdr adj)))))))) |
956 | 537 |
538 (provide 'solar) | |
539 | |
540 ;;; solar.el ends here |