annotate lisp/calendar/solar.el @ 4417:02b7d9476fae

(read_key_sequence): Use XFASTINT to convert value of Flength to an int.
author Richard M. Stallman <rms@gnu.org>
date Mon, 02 Aug 1993 07:29:53 +0000
parents 72da559fedd2
children c8f5e05c332e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;;; solar.el --- calendar functions for solar events.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY. No author or distributor
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; accepts responsibility to anyone for the consequences of using it
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; or for whether it serves any particular purpose or works at all,
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; unless he says so in writing. Refer to the GNU Emacs General Public
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; License for full details.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; Everyone is granted permission to copy, modify and redistribute
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; GNU Emacs, but only under the conditions described in the
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; GNU Emacs General Public License. A copy of this license is
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; supposed to have been given to you along with GNU Emacs so you
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; can know your rights and responsibilities. It should be in a
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 ;; file named COPYING. Among other things, the copyright notice
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 ;; and this notice must be preserved on all copies.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 ;;; Commentary:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;; 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
30 ;; 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
31 ;; eqinoxes/solstices.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; Based on the ``Almanac for Computers 1984,'' prepared by the Nautical
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; Almanac Office, United States Naval Observatory, Washington, 1984 and
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; on ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus,
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; Willmann-Bell, Inc., 1985.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;;
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;; WARNINGS:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; 1. SUNRISE/SUNSET calculations will be accurate only to +/- 2 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; Locations should be between +/- 65 degrees of latitude.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; Dates should be in the latter half of the 20th century.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;;
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;; 2. Equinox/solstice times will be accurate only to +/- 15 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;; The author would be delighted to have an astronomically more sophisticated
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; person rewrite the code for the solar calculations in this file!
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;; Comments, corrections, and improvements should be sent to
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; Edward M. Reingold Department of Computer Science
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 ;; Urbana, Illinois 61801
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 ;;; Code:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (if (fboundp 'atan)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 (require 'lisp-float-type)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (error "Solar calculations impossible since floating point is unavailable."))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
60 (require 'cal-dst)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
61
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
62 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
63 (defvar calendar-time-display-form
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
64 '(12-hours ":" minutes am-pm
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
65 (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
66 "*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
67
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
68 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
69 `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
70 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
71
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
72 For example, the form
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
73
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
74 '(24-hours \":\" minutes
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
75 (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
76
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
77 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
78
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
79 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
80 (defvar calendar-latitude nil
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
81 "*Latitude of `calendar-location-name' in degrees, + north, - south.
3907
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
82 For example, 40.7 for New York City.
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
83 It may not be a good idea to set this in advance for your site;
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
84 if there may be users running Emacs at your site
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
85 who are physically located elsewhere, they would get the wrong
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
86 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
87
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
88 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
89 (defvar calendar-longitude nil
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
90 "*Longitude of `calendar-location-name' in degrees, + east, - west.
3907
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
91 For example, -74.0 for New York City.
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
92 It may not be a good idea to set this in advance for your site;
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
93 if there may be users running Emacs at your site
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
94 who are physically located elsewhere, they would get the wrong
72da559fedd2 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 3866
diff changeset
95 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
96
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
97 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
98 (defvar calendar-location-name
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
99 '(let ((float-output-format "%.1f"))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
100 (format "%s%s, %s%s"
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
101 (abs calendar-latitude)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
102 (if (> calendar-latitude 0) "N" "S")
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
103 (abs calendar-longitude)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
104 (if (> calendar-longitude 0) "E" "W")))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
105 "*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
106 Default value is just the latitude, longitude pair.")
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (defun solar-setup ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 "Prompt user for latitude, longitude, and time zone."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 (beep)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (if (not calendar-longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (setq calendar-longitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (if (not calendar-latitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (setq calendar-latitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 (if (not calendar-time-zone)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (setq calendar-time-zone
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
122 "Enter difference from Coordinated Universal Time (in minutes): "))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (defun solar-get-number (prompt)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 "Return a number from the minibuffer, prompting with PROMPT.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 Returns nil if nothing was entered."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (let ((x (read-string prompt "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 (if (not (string-equal x ""))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (string-to-int x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (defun solar-sin-degrees (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (sin (degrees-to-radians x)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (defun solar-cosine-degrees (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 (cos (degrees-to-radians x)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (defun solar-tangent-degrees (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (tan (degrees-to-radians x)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 (defun solar-xy-to-quadrant (x y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 "Determines the quadrant of the point X, Y."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (if (> x 0)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 (if (> y 0) 1 4)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (if (> y 0) 2 3)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (defun solar-degrees-to-quadrant (angle)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 "Determines the quadrant of ANGLE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (1+ (truncate (/ (solar-mod angle 360.0) 90.0))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (defun solar-arctan (x quad)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 "Arctangent of X in quadrant QUAD."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (let ((deg (radians-to-degrees (atan x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (cond ((equal quad 2) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 ((equal quad 3) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 ((equal quad 4) (+ deg 360))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (t deg))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 (defun solar-arccos (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (let ((y (sqrt (- 1 (* x x)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (defun solar-arcsin (y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (let ((x (sqrt (- 1 (* y y)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (defun solar-mod (x y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 "Returns X mod Y; value is *always* non-negative."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 (let ((v (% x y)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (if (> 0 v)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (+ v y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 v)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (defconst solar-earth-inclination 23.441884
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 "Inclination of earth's equator to its solar orbit in degrees.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (defconst solar-cos-inclination (solar-cosine-degrees solar-earth-inclination)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 "Cosine of earth's inclination.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (defconst solar-sin-inclination (solar-sin-degrees solar-earth-inclination)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 "Sine of earth's inclination.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (defconst solar-earth-orbit-eccentricity 0.016718
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 "Eccentricity of orbit of the earth around the sun.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (defmacro solar-degrees-to-hours (deg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (list '/ deg 15))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (defmacro solar-hours-to-days (hour)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (list '/ hour 24))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 (defun solar-longitude-of-sun (day)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 "Longitude of the sun at DAY in the year."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (let ((mean-anomaly (- (* 0.9856 day) 3.289)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (solar-mod (+ mean-anomaly
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (* 1.916 (solar-sin-degrees mean-anomaly))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (* 0.020 (solar-sin-degrees (* 2 mean-anomaly)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 282.634)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 360)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (defun solar-right-ascension (longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 "Right ascension of the sun, given its LONGITUDE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (solar-arctan
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (* solar-cos-inclination (solar-tangent-degrees longitude))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (solar-degrees-to-quadrant longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (defun solar-declination (longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 "Declination of the sun, given its LONGITUDE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (solar-arcsin
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (* solar-sin-inclination
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (solar-sin-degrees longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (defun solar-sunrise (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 "Calculates the *standard* time of sunrise for Gregorian DATE for location
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 given by `calendar-latitude' and `calendar-longitude'. Returns a decimal fraction
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 of hours. Returns nil if the sun does not rise at that location on that day."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (let* ((day-of-year (calendar-day-number date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (approx-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (+ day-of-year
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (solar-hours-to-days
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (- 6 (solar-degrees-to-hours calendar-longitude)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (solar-longitude-of-sun-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (solar-longitude-of-sun approx-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (solar-right-ascension-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (solar-right-ascension solar-longitude-of-sun-at-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (solar-declination-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (solar-declination solar-longitude-of-sun-at-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (cos-local-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (* (solar-sin-degrees solar-declination-at-sunrise)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (solar-sin-degrees calendar-latitude)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (* (solar-cosine-degrees solar-declination-at-sunrise)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (solar-cosine-degrees calendar-latitude)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (if (<= (abs cos-local-sunrise) 1);; otherwise, no sunrise that day
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (let* ((local-sunrise (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (- 360 (solar-arccos cos-local-sunrise))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (local-mean-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (solar-mod (- (+ local-sunrise solar-right-ascension-at-sunrise)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (+ (* 0.065710 approx-sunrise)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 6.622))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 24)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (+ (- local-mean-sunrise (solar-degrees-to-hours calendar-longitude))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (/ calendar-time-zone 60.0))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (defun solar-sunset (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 "Calculates the *standard* time of sunset for Gregorian DATE for location
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 given by `calendar-latitude' and `calendar-longitude'. Returns a decimal fractions
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 of hours. Returns nil if the sun does not set at that location on that day."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (let* ((day-of-year (calendar-day-number date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (approx-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (+ day-of-year
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (solar-hours-to-days
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (- 18 (solar-degrees-to-hours calendar-longitude)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (solar-longitude-of-sun-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (solar-longitude-of-sun approx-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (solar-right-ascension-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (solar-right-ascension solar-longitude-of-sun-at-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (solar-declination-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (solar-declination solar-longitude-of-sun-at-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (cos-local-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (* (solar-sin-degrees solar-declination-at-sunset)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (solar-sin-degrees calendar-latitude)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (* (solar-cosine-degrees solar-declination-at-sunset)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (solar-cosine-degrees calendar-latitude)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (if (<= (abs cos-local-sunset) 1);; otherwise, no sunset that day
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (let* ((local-sunset (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (solar-arccos cos-local-sunset)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (local-mean-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (solar-mod (- (+ local-sunset solar-right-ascension-at-sunset)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (+ (* 0.065710 approx-sunset) 6.622))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 24)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 (+ (- local-mean-sunset (solar-degrees-to-hours calendar-longitude))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (/ calendar-time-zone 60.0))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
276 (defun solar-time-string (time date &optional style)
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
277 "Printable form for decimal fraction *standard* TIME on DATE.
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
278 Optional parameter STYLE forces the time to be standard time when its value
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
279 is 'standard and daylight savings time (if available) when its value is
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
280 'daylight.
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
281
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 Format used is given by `calendar-time-display-form'. Converted to daylight
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
283 savings time according to `calendar-daylight-savings-starts',
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
284 `calendar-daylight-savings-ends', `calendar-daylight-switchover-time', and
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
285 `calendar-daylight-savings-offset'."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (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
287 (time (round (* 60 time)))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
288 (rounded-abs-date (+ (calendar-absolute-from-gregorian date)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
289 (/ 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
290 (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
291 (+ (calendar-absolute-from-gregorian
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
292 (eval calendar-daylight-savings-starts))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
293 (/ calendar-daylight-savings-switchover-time
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
294 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
295 (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
296 (+ (calendar-absolute-from-gregorian
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
297 (eval calendar-daylight-savings-ends))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
298 (/ (- calendar-daylight-savings-switchover-time
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
299 calendar-daylight-time-offset)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
300 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 (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
302 (or (eq style 'daylight)
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
303 (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
304 (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
305 (<= 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
306 (< 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
307 (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
308 (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
309 (<= 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
310 (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
311 (<= 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
312 (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
313 (< rounded-abs-date dst-ends)))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (time-zone (if dst
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 calendar-daylight-time-zone-name
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 calendar-standard-time-zone-name))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
317 (time (+ time (if dst calendar-daylight-time-offset 0)))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
318 (24-hours (/ time 60))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
319 (minutes (format "%02d" (% time 60)))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
320 (12-hours (format "%d" (1+ (% (+ 24-hours 11) 12))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (am-pm (if (>= 24-hours 12) "pm" "am"))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (24-hours (format "%02d" 24-hours)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 (mapconcat 'eval calendar-time-display-form "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (defun solar-sunrise-sunset (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 "String giving local times of sunrise and sunset on Gregorian DATE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (let ((rise (solar-sunrise date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 (set (solar-sunset date)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (format "%s, %s at %s"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 (if rise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 (concat "Sunrise " (solar-time-string rise date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 "No sunrise")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 (if set
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 (concat "sunset " (solar-time-string set date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 "no sunset")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 (eval calendar-location-name))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (defun solar-apparent-longitude-of-sun (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 "Apparent longitude of the sun on Gregorian DATE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (let* ((time (/ (- (calendar-absolute-from-gregorian date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 (calendar-absolute-from-gregorian '(1 0.5 1900)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 36525))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (l (+ 279.69668
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 (* 36000.76892 time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (* 0.0003025 time time)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (m (+ 358.47583
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (* 35999.04975 time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (* -0.000150 time time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (* -0.0000033 time time time)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (c (+ (* (+ 1.919460
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (* -0.004789 time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (* -0.000014 time time))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 (solar-sin-degrees m))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (* (+ 0.020094
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (* -0.000100 time))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (solar-sin-degrees (* 2 m)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (* 0.000293
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (solar-sin-degrees (* 3 m)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (L (+ l c))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (omega (+ 259.18
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (* -1934.142 time)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (app (+ L
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 -0.00569
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (* -0.00479
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (solar-sin-degrees omega)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 app))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (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
369 "Difference in minutes between Ephemeris time and UTC in YEAR.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 Value is only an approximation."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (let ((T (/ (- year 1900) 100.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (+ 0.41 (* 1.2053 T) (* 0.4992 T T))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 (defun solar-equinoxes/solstices (k year)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 "Date of equinox/solstice K for YEAR. K=0, spring equinox; K=1, summer
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 solstice; K=2, fall equinox; K=3, winter solstice. Accurate to within
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 several minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (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
379 app
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (correction 1000))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (while (> correction 0.00001)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 (setq app (solar-mod (solar-apparent-longitude-of-sun date) 360.0))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 (setq correction (* 58 (solar-sin-degrees (- (* k 90) app))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 (setq date (list (extract-calendar-month date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (+ (extract-calendar-day date) correction)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 year)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 (list (extract-calendar-month date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 (+ (extract-calendar-day date) (/ calendar-time-zone 60.0 24.0)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 (- (/ (solar-ephemeris-correction year) 60.0 24.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 year)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 ;;;###autoload
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 (defun sunrise-sunset (&optional arg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 "Local time of sunrise and sunset for today. Accurate to +/- 2 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 If called with an optional prefix argument, prompts for date.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 If called with an optional double prefix argument, prompts for longitude,
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 latitude, time zone, and date.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 This function is suitable for execution in a .emacs file."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 (interactive "p")
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
402 (if (and (< arg 16)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
403 (not (and calendar-latitude calendar-longitude calendar-time-zone)))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
404 (solar-setup))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 (let* ((calendar-longitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
406 (if (< arg 16) calendar-longitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (calendar-latitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
410 (if (< arg 16) calendar-latitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 (calendar-time-zone
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
414 (if (< arg 16) calendar-time-zone
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
416 "Enter difference from Coordinated Universal Time (in minutes): ")))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 (calendar-location-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
418 (if (< arg 16) calendar-location-name
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
419 (let ((float-output-format "%.1f"))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
420 (format "%s%s, %s%s"
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
421 (abs calendar-latitude)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
422 (if (> calendar-latitude 0) "N" "S")
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
423 (abs calendar-longitude)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
424 (if (> calendar-longitude 0) "E" "W")))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (calendar-standard-time-zone-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
426 (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
427 (cond ((= calendar-time-zone 0) "UTC")
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
428 ((< calendar-time-zone 0)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
429 (format "UTC%dmin" calendar-time-zone))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
430 (t (format "UTC+%dmin" calendar-time-zone)))))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
431 (calendar-daylight-savings-starts
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
432 (if (< arg 16) calendar-daylight-savings-starts))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
433 (calendar-daylight-savings-ends
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
434 (if (< arg 16) calendar-daylight-savings-ends))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
435 (date (if (< arg 4) (calendar-current-date) (calendar-read-date)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 (date-string (calendar-date-string date t))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 (time-string (solar-sunrise-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 (msg (format "%s: %s" date-string time-string))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 (one-window (one-window-p t)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 (if (<= (length msg) (screen-width))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 (message msg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (with-output-to-temp-buffer "*temp*"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 (princ (concat date-string "\n" time-string)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (message (substitute-command-keys
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 (if one-window
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (if pop-up-windows
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 "Type \\[delete-other-windows] to remove temp window."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 "Type \\[switch-to-buffer] RET to remove temp window.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 "Type \\[switch-to-buffer-other-window] RET to restore old contents of temp window."))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 (defun calendar-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 "Local time of sunrise and sunset for date under cursor.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 Accurate to +/- 2 minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 (interactive)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 (message
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 (solar-sunrise-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 (or (calendar-cursor-to-date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (error "Cursor is not on a date!")))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 (defun diary-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 "Local time of sunrise and sunset as a diary entry.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 Accurate to +/- 2 minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (solar-sunrise-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (defun diary-sabbath-candles ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 "Local time of candle lighting diary entry--applies if date is a Friday.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 No diary entry if there is no sunset on that date."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 (if (= (% (calendar-absolute-from-gregorian date) 7) 5);; Friday
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 (let* ((sunset (solar-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 (light (if sunset (- sunset (/ 18.0 60.0)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 (if light (format "%s Sabbath candle lighting"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 (solar-time-string light date))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
480 (defun solar-equinoxes-solstices ()
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 "Date and time of equinoxes and solstices, if visible in the calendar window.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 Requires floating point."
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
483 (let ((m displayed-month)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
484 (y displayed-year))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 (increment-calendar-month m y (cond ((= 1 (% m 3)) -1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 ((= 2 (% m 3)) 1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 (t 0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 (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
489 (if calendar-time-zone calendar-standard-time-zone-name "UTC"))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 (calendar-daylight-savings-starts
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 (if calendar-time-zone calendar-daylight-savings-starts))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 (calendar-daylight-savings-ends
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 (if calendar-time-zone calendar-daylight-savings-ends))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 (calendar-time-zone (if calendar-time-zone calendar-time-zone 0))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 (k (1- (/ m 3)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 (date (solar-equinoxes/solstices k y))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 (day (extract-calendar-day date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 (time (* 24 (- day (truncate day))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 ;; Time zone/DST can't move the date out of range,
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 ;; so let solar-time-string do the conversion.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 (date (list (extract-calendar-month date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 (truncate day)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 (extract-calendar-year date))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 (list (list date
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 (format "%s %s"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 (cond ((= k 0) "Vernal Equinox")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 ((= k 1) "Summer Solstice")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 ((= k 2) "Fall Equinox")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 ((= k 3) "Winter Solstice"))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (solar-time-string time date)))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 (provide 'solar)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 ;;; solar.el ends here