annotate lisp/calendar/solar.el @ 12935:f65e672e038e

[HAVE_CONFIG_H]: Include config.h. [! O_RDONLY]: Define it to zero. (main): Use O_RDONLY instead of explicit zero.
author Roland McGrath <roland@gnu.org>
date Wed, 23 Aug 1995 17:42:20 +0000
parents 2aa3e1b05567
children 2779e3cf6cfa
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
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
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
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
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 ;;; Commentary:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
28 ;; This collection of functions implements the features of calendar.el,
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
29 ;; diary.el, and holiday.el that deal with times of day, sunrise/sunset, and
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
30 ;; eqinoxes/solstices.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; Based on the ``Almanac for Computers 1984,'' prepared by the Nautical
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; Almanac Office, United States Naval Observatory, Washington, 1984 and
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; on ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus,
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; Willmann-Bell, Inc., 1985.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;;
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; WARNINGS:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;; 1. SUNRISE/SUNSET calculations will be accurate only to +/- 2 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; Locations should be between +/- 65 degrees of latitude.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; Dates should be in the latter half of the 20th century.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;;
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; 2. Equinox/solstice times will be accurate only to +/- 15 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;; The author would be delighted to have an astronomically more sophisticated
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;; person rewrite the code for the solar calculations in this file!
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;; Comments, corrections, and improvements should be sent to
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;; Edward M. Reingold Department of Computer Science
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;; Urbana, Illinois 61801
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 ;;; Code:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (if (fboundp 'atan)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (require 'lisp-float-type)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
57 (error "Solar/lunar calculations impossible since floating point is unavailable."))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
80 "*Latitude of `calendar-location-name' in degrees.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
81
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
82 The value can be either a decimal fraction (one place of accuracy is
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
83 sufficient), + north, - south, such as 40.7 for New York City, or the value
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
84 can be a vector [degrees minutes north/south] such as [40 50 north] for New
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
85 York City.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
86
12908
2aa3e1b05567 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 12312
diff changeset
87 This variable should be set in `site-init.el'.")
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
88
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
89 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
90 (defvar calendar-longitude nil
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
91 "*Longitude of `calendar-location-name' in degrees.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
92
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
93 The value can be either a decimal fraction (one place of accuracy is
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
94 sufficient), + east, - west, such as -73.9 for New York City, or the value
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
95 can be a vector [degrees minutes east/west] such as [73 55 west] for New
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
96 York City.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
97
12908
2aa3e1b05567 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 12312
diff changeset
98 This variable should be set in `site-init.el'.")
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
99
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
100 (defsubst calendar-latitude ()
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
101 "Convert calendar-latitude to a signed decimal fraction, if needed."
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
102 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
103 calendar-latitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
104 (let ((lat (+ (aref calendar-latitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
105 (/ (aref calendar-latitude 1) 60.0))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
106 (if (equal (aref calendar-latitude 2) 'north)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
107 lat
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
108 (- lat)))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
109
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
110 (defsubst calendar-longitude ()
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
111 "Convert calendar-longitude to a signed decimal fraction, if needed."
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
112 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
113 calendar-longitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
114 (let ((long (+ (aref calendar-longitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
115 (/ (aref calendar-longitude 1) 60.0))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
116 (if (equal (aref calendar-longitude 2) 'east)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
117 long
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
118 (- long)))))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
119
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
120 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
121 (defvar calendar-location-name
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
122 '(let ((float-output-format "%.1f"))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
123 (format "%s%s, %s%s"
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
124 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
125 (abs calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
126 (+ (aref calendar-latitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
127 (/ (aref calendar-latitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
128 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
129 (if (> calendar-latitude 0) "N" "S")
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
130 (if (equal (aref calendar-latitude 2) 'north) "N" "S"))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
131 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
132 (abs calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
133 (+ (aref calendar-longitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
134 (/ (aref calendar-longitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
135 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
136 (if (> calendar-longitude 0) "E" "W")
12312
7816b2769014 Fix bug in determination of output string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 9829
diff changeset
137 (if (equal (aref calendar-longitude 2) 'east) "E" "W"))))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
138 "*Expression evaluating to name of `calendar-longitude', calendar-latitude'.
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
139 For example, \"New York City\". Default value is just the latitude, longitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
140 pair.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
141
12908
2aa3e1b05567 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 12312
diff changeset
142 This variable should be set in `site-init.el'.")
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143
4863
adfd03a381ca (solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 4766
diff changeset
144 (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
145 '("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
146 "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
147
4863
adfd03a381ca (solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 4766
diff changeset
148 (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
149 '("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
150 "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
151
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (defun solar-setup ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 "Prompt user for latitude, longitude, and time zone."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (beep)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (if (not calendar-longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (setq calendar-longitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (if (not calendar-latitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 (setq calendar-latitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (if (not calendar-time-zone)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (setq calendar-time-zone
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
166 "Enter difference from Coordinated Universal Time (in minutes): "))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 (defun solar-get-number (prompt)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 "Return a number from the minibuffer, prompting with PROMPT.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 Returns nil if nothing was entered."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (let ((x (read-string prompt "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (if (not (string-equal x ""))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (string-to-int x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
175 (defsubst solar-sin-degrees (x)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (sin (degrees-to-radians x)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
178 (defsubst solar-cosine-degrees (x)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (cos (degrees-to-radians x)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (defun solar-tangent-degrees (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (tan (degrees-to-radians x)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (defun solar-xy-to-quadrant (x y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 "Determines the quadrant of the point X, Y."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (if (> x 0)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (if (> y 0) 1 4)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (if (> y 0) 2 3)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (defun solar-degrees-to-quadrant (angle)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 "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
192 (1+ (floor (mod angle 360) 90)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (defun solar-arctan (x quad)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 "Arctangent of X in quadrant QUAD."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (let ((deg (radians-to-degrees (atan x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 (cond ((equal quad 2) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 ((equal quad 3) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 ((equal quad 4) (+ deg 360))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (t deg))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (defun solar-arccos (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (let ((y (sqrt (- 1 (* x x)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (defun solar-arcsin (y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (let ((x (sqrt (- 1 (* y y)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (defconst solar-earth-inclination 23.441884
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 "Inclination of earth's equator to its solar orbit in degrees.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (defconst solar-cos-inclination (solar-cosine-degrees solar-earth-inclination)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 "Cosine of earth's inclination.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (defconst solar-sin-inclination (solar-sin-degrees solar-earth-inclination)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 "Sine of earth's inclination.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (defconst solar-earth-orbit-eccentricity 0.016718
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 "Eccentricity of orbit of the earth around the sun.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
222 (defsubst solar-degrees-to-hours (deg)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
223 (/ deg 15.0))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
225 (defsubst solar-hours-to-days (hour)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
226 (/ hour 24.0))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (defun solar-longitude-of-sun (day)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 "Longitude of the sun at DAY in the year."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (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
231 (mod (+ mean-anomaly
c8f5e05c332e (siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents: 3907
diff changeset
232 (* 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
233 (* 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
234 282.634)
4660
2516bc453477 Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents: 4657
diff changeset
235 360)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (defun solar-right-ascension (longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 "Right ascension of the sun, given its LONGITUDE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (solar-arctan
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (* solar-cos-inclination (solar-tangent-degrees longitude))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (solar-degrees-to-quadrant longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (defun solar-declination (longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 "Declination of the sun, given its LONGITUDE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (solar-arcsin
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (* solar-sin-inclination
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (solar-sin-degrees longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (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
251 "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
252 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
253 `calendar-longitude'.
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
254
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
255 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
256 that location on that day."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (let* ((day-of-year (calendar-day-number date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (approx-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (+ day-of-year
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (solar-hours-to-days
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
261 (- 6 (solar-degrees-to-hours (calendar-longitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (solar-longitude-of-sun-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (solar-longitude-of-sun approx-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (solar-right-ascension-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (solar-right-ascension solar-longitude-of-sun-at-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (solar-declination-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (solar-declination solar-longitude-of-sun-at-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (cos-local-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (* (solar-sin-degrees solar-declination-at-sunrise)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
271 (solar-sin-degrees (calendar-latitude))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (* (solar-cosine-degrees solar-declination-at-sunrise)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
273 (solar-cosine-degrees (calendar-latitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (if (<= (abs cos-local-sunrise) 1);; otherwise, no sunrise that day
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 (let* ((local-sunrise (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (- 360 (solar-arccos cos-local-sunrise))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (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
278 (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
279 (+ (* 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
280 6.622))
4660
2516bc453477 Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents: 4657
diff changeset
281 24)))
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
282 (+ (- local-mean-sunrise (solar-degrees-to-hours (calendar-longitude)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 (/ calendar-time-zone 60.0))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (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
286 "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
287 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
288 `calendar-longitude'.
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
289
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
290 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
291 that location on that day."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (let* ((day-of-year (calendar-day-number date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 (approx-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (+ day-of-year
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (solar-hours-to-days
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
296 (- 18 (solar-degrees-to-hours (calendar-longitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (solar-longitude-of-sun-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 (solar-longitude-of-sun approx-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (solar-right-ascension-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (solar-right-ascension solar-longitude-of-sun-at-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (solar-declination-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (solar-declination solar-longitude-of-sun-at-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (cos-local-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (* (solar-sin-degrees solar-declination-at-sunset)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
306 (solar-sin-degrees (calendar-latitude))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (* (solar-cosine-degrees solar-declination-at-sunset)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
308 (solar-cosine-degrees (calendar-latitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 (if (<= (abs cos-local-sunset) 1);; otherwise, no sunset that day
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 (let* ((local-sunset (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (solar-arccos cos-local-sunset)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (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
313 (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
314 (+ (* 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
315 24)))
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
316 (+ (- local-mean-sunset (solar-degrees-to-hours (calendar-longitude)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 (/ calendar-time-zone 60.0))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
319 (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
320 "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
321 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
322 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
323 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
324
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
325 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
326 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
327 'daylight.
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
328
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
329 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
330 `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
331 `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
332 `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
333 `calendar-daylight-savings-offset'."
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
334
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 (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
336 (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
337 (/ (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
338 (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
339 (+ (calendar-absolute-from-gregorian
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
340 (eval calendar-daylight-savings-starts))
4657
5049c683d5e9 (solar-time-string):
Paul Eggert <eggert@twinsun.com>
parents: 4651
diff changeset
341 (/ calendar-daylight-savings-starts-time
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
342 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
343 (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
344 (+ (calendar-absolute-from-gregorian
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
345 (eval calendar-daylight-savings-ends))
4657
5049c683d5e9 (solar-time-string):
Paul Eggert <eggert@twinsun.com>
parents: 4651
diff changeset
346 (/ (- calendar-daylight-savings-ends-time
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
347 calendar-daylight-time-offset)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
348 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
349 (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
350 (or (eq style 'daylight)
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
351 (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
352 (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
353 (<= 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
354 (< 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
355 (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
356 (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
357 (<= 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
358 (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
359 (<= 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
360 (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
361 (< rounded-abs-date dst-ends)))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (time-zone (if dst
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 calendar-daylight-time-zone-name
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 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
365 (time (+ rounded-abs-date
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
366 (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
367 (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
368 (* 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
369 time-zone)))
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
370
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
371 (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
372 "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
373 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
374 (let* ((time (round (* 60 time)))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
375 (24-hours (/ time 60))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
376 (minutes (format "%02d" (% time 60)))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
377 (12-hours (format "%d" (1+ (% (+ 24-hours 11) 12))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (am-pm (if (>= 24-hours 12) "pm" "am"))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (24-hours (format "%02d" 24-hours)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (mapconcat 'eval calendar-time-display-form "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 (defun solar-sunrise-sunset (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 "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
384 (let* ((rise (solar-sunrise date))
9829
0cef7b5644f5 Check for nil time before trying to adjust it for dst.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 9714
diff changeset
385 (adj-rise (if rise (solar-adj-time-for-dst date rise)))
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
386 (set (solar-sunset date))
9829
0cef7b5644f5 Check for nil time before trying to adjust it for dst.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 9714
diff changeset
387 (adj-set (if set (solar-adj-time-for-dst date set))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 (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
389 (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
390 (concat "Sunrise " (apply 'solar-time-string (cdr adj-rise)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 "No sunrise")
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
392 (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
393 (concat "sunset " (apply 'solar-time-string (cdr adj-set)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 "no sunset")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 (eval calendar-location-name))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 (defun solar-apparent-longitude-of-sun (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 "Apparent longitude of the sun on Gregorian DATE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 (let* ((time (/ (- (calendar-absolute-from-gregorian date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 (calendar-absolute-from-gregorian '(1 0.5 1900)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 36525))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 (l (+ 279.69668
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 (* 36000.76892 time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 (* 0.0003025 time time)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 (m (+ 358.47583
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 (* 35999.04975 time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (* -0.000150 time time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (* -0.0000033 time time time)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (c (+ (* (+ 1.919460
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 (* -0.004789 time)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 (* -0.000014 time time))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 (solar-sin-degrees m))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 (* (+ 0.020094
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 (* -0.000100 time))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 (solar-sin-degrees (* 2 m)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 (* 0.000293
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 (solar-sin-degrees (* 3 m)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 (L (+ l c))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 (omega (+ 259.18
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 (* -1934.142 time)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 (app (+ L
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 -0.00569
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 (* -0.00479
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 (solar-sin-degrees omega)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 app))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 (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
428 "Difference in minutes between Ephemeris time and UTC in YEAR.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 Value is only an approximation."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 (let ((T (/ (- year 1900) 100.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 (+ 0.41 (* 1.2053 T) (* 0.4992 T T))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (defun solar-equinoxes/solstices (k year)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 "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
435 solstice; K=2, fall equinox; K=3, winter solstice. Accurate to within
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 several minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 (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
438 app
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 (correction 1000))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 (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
441 (setq app (mod (solar-apparent-longitude-of-sun date) 360))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (setq correction (* 58 (solar-sin-degrees (- (* k 90) app))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 (setq date (list (extract-calendar-month date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (+ (extract-calendar-day date) correction)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 year)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (list (extract-calendar-month date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 (+ (extract-calendar-day date) (/ calendar-time-zone 60.0 24.0)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 (- (/ (solar-ephemeris-correction year) 60.0 24.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 year)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 ;;;###autoload
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 (defun sunrise-sunset (&optional arg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 "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
454 If called with an optional prefix argument, prompt for date.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
456 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
457 latitude, time zone, and date, and always use standard time.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 This function is suitable for execution in a .emacs file."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 (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
461 (or arg (setq arg 1))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
462 (if (and (< arg 16)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
463 (not (and calendar-latitude calendar-longitude calendar-time-zone)))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
464 (solar-setup))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 (let* ((calendar-longitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
466 (if (< arg 16) calendar-longitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (calendar-latitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
470 (if (< arg 16) calendar-latitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 (calendar-time-zone
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
474 (if (< arg 16) calendar-time-zone
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
476 "Enter difference from Coordinated Universal Time (in minutes): ")))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 (calendar-location-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
478 (if (< arg 16) calendar-location-name
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
479 (let ((float-output-format "%.1f"))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
480 (format "%s%s, %s%s"
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
481 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
482 (abs calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
483 (+ (aref calendar-latitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
484 (/ (aref calendar-latitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
485 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
486 (if (> calendar-latitude 0) "N" "S")
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
487 (if (equal (aref calendar-latitude 2) 'north) "N" "S"))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
488 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
489 (abs calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
490 (+ (aref calendar-longitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
491 (/ (aref calendar-longitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
492 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
493 (if (> calendar-longitude 0) "E" "W")
12312
7816b2769014 Fix bug in determination of output string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 9829
diff changeset
494 (if (equal (aref calendar-longitude 2) 'east)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
495 "E" "W"))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 (calendar-standard-time-zone-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
497 (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
498 (cond ((= calendar-time-zone 0) "UTC")
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
499 ((< calendar-time-zone 0)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
500 (format "UTC%dmin" calendar-time-zone))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
501 (t (format "UTC+%dmin" calendar-time-zone)))))
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
502 (calendar-daylight-savings-starts
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
503 (if (< arg 16) calendar-daylight-savings-starts))
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
504 (calendar-daylight-savings-ends
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
505 (if (< arg 16) calendar-daylight-savings-ends))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
506 (date (if (< arg 4) (calendar-current-date) (calendar-read-date)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 (date-string (calendar-date-string date t))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 (time-string (solar-sunrise-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (msg (format "%s: %s" date-string time-string))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (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
511 (if (<= (length msg) (frame-width))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 (message msg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 (with-output-to-temp-buffer "*temp*"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (princ (concat date-string "\n" time-string)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 (message (substitute-command-keys
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 (if one-window
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 (if pop-up-windows
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 "Type \\[delete-other-windows] to remove temp window."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 "Type \\[switch-to-buffer] RET to remove temp window.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 "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
521
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 (defun calendar-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 "Local time of sunrise and sunset for date under cursor.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 Accurate to +/- 2 minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 (interactive)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 (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
528 (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
529 (message "%s: %s"
d127e0963a2c (calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents: 5010
diff changeset
530 (calendar-date-string date t t)
d127e0963a2c (calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents: 5010
diff changeset
531 (solar-sunrise-sunset date))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 (defun diary-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 "Local time of sunrise and sunset as a diary entry.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 Accurate to +/- 2 minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 (solar-sunrise-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 (defun diary-sabbath-candles ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 "Local time of candle lighting diary entry--applies if date is a Friday.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 No diary entry if there is no sunset on that date."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 (if (= (% (calendar-absolute-from-gregorian date) 7) 5);; Friday
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (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
547 (light (if sunset
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
548 (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
549 date
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
550 (- 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
551 (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
552 (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
553 (apply 'solar-time-string (cdr light)))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554
5010
9595049f63a9 (solar-equinoxes-solstices): Add autoload.
Richard M. Stallman <rms@gnu.org>
parents: 4863
diff changeset
555 ;;;###autoload
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
556 (defun solar-equinoxes-solstices ()
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 "Date and time of equinoxes and solstices, if visible in the calendar window.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 Requires floating point."
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
559 (let ((m displayed-month)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
560 (y displayed-year))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 (increment-calendar-month m y (cond ((= 1 (% m 3)) -1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 ((= 2 (% m 3)) 1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 (t 0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 (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
565 (if calendar-time-zone calendar-standard-time-zone-name "UTC"))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 (calendar-daylight-savings-starts
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 (if calendar-time-zone calendar-daylight-savings-starts))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 (calendar-daylight-savings-ends
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 (if calendar-time-zone calendar-daylight-savings-ends))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (calendar-time-zone (if calendar-time-zone calendar-time-zone 0))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 (k (1- (/ m 3)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 (date (solar-equinoxes/solstices k y))
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
573 (s-hemi (and calendar-latitude (< (calendar-latitude) 0)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 (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
575 (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
576 (list (extract-calendar-month date)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 (truncate day)
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
578 (extract-calendar-year date))
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
579 (* 24 (- day (truncate day))))))
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
580 (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
581 (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
582 (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
583 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
584 (apply 'solar-time-string (cdr adj))))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 (provide 'solar)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 ;;; solar.el ends here