annotate lisp/calendar/solar.el @ 13194:7e90c5fce35f

Added menu items for cal-tex.el (a new file).
author Edward M. Reingold <reingold@emr.cs.iit.edu>
date Thu, 12 Oct 1995 15:28:06 +0000
parents 2779e3cf6cfa
children cd9e2bb3e7fe
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
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
3 ;; Copyright (C) 1992, 1993, 1995 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
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
33 ;; Almanac Office, United States Naval Observatory, Washington, 1984, on
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
34 ;; ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
35 ;; Willmann-Bell, Inc., 1985, and on ``Astronomical Algorithms'' by Jean
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
36 ;; Meeus, Willmann-Bell, Inc., 1991.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
37
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;;
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; WARNINGS:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; 1. SUNRISE/SUNSET calculations will be accurate only to +/- 2 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; Locations should be between +/- 65 degrees of latitude.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; Dates should be in the latter half of the 20th century.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;;
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;; 2. Equinox/solstice times will be accurate only to +/- 15 minutes.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; The author would be delighted to have an astronomically more sophisticated
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;; person rewrite the code for the solar calculations in this file!
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; Comments, corrections, and improvements should be sent to
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 ;; Edward M. Reingold Department of Computer Science
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 ;; Urbana, Illinois 61801
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 ;;; Code:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 (if (fboundp 'atan)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (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
59 (error "Solar/lunar calculations impossible since floating point is unavailable."))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
61 (require 'cal-dst)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
62
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
63 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
64 (defvar calendar-time-display-form
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
65 '(12-hours ":" minutes am-pm
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
66 (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
67 "*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
68
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
69 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
70 `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
71 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
72
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
73 For example, the form
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
74
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
75 '(24-hours \":\" minutes
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
76 (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
77
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
78 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
79
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
80 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
81 (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
82 "*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
83
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
84 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
85 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
86 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
87 York City.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
88
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
89 This variable should be set in site-local.el.")
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
90
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
91 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
92 (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
93 "*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
94
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
95 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
96 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
97 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
98 York City.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
99
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
100 This variable should be set in site-local.el.")
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
101
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
102 (defsubst calendar-latitude ()
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
103 "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
104 (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
105 calendar-latitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
106 (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
107 (/ (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
108 (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
109 lat
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
110 (- lat)))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
111
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
112 (defsubst calendar-longitude ()
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
113 "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
114 (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
115 calendar-longitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
116 (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
117 (/ (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
118 (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
119 long
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
120 (- long)))))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
121
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
122 ;;;###autoload
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
123 (defvar calendar-location-name
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
124 '(let ((float-output-format "%.1f"))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
125 (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
126 (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
127 (abs calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
128 (+ (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
129 (/ (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
130 (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
131 (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
132 (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
133 (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
134 (abs calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
135 (+ (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
136 (/ (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
137 (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
138 (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
139 (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
140 "*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
141 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
142 pair.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
143
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
144 This variable should be set in site-local.el.")
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
4863
adfd03a381ca (solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 4766
diff changeset
146 (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
147 '("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
148 "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
149
4863
adfd03a381ca (solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 4766
diff changeset
150 (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
151 '("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
152 "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
153
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (defun solar-setup ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 "Prompt user for latitude, longitude, and time zone."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (beep)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (if (not calendar-longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 (setq calendar-longitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (if (not calendar-latitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (setq calendar-latitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (if (not calendar-time-zone)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (setq calendar-time-zone
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
168 "Enter difference from Coordinated Universal Time (in minutes): "))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (defun solar-get-number (prompt)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 "Return a number from the minibuffer, prompting with PROMPT.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 Returns nil if nothing was entered."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (let ((x (read-string prompt "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (if (not (string-equal x ""))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (string-to-int x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
177 (defsubst solar-sin-degrees (x)
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
178 (sin (degrees-to-radians (mod x 360.0))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
180 (defsubst solar-cosine-degrees (x)
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
181 (cos (degrees-to-radians (mod x 360.0))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
183 (defsubst solar-tangent-degrees (x)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
184 (tan (degrees-to-radians (mod x 360.0))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (defun solar-xy-to-quadrant (x y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 "Determines the quadrant of the point X, Y."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (if (> x 0)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (if (> y 0) 1 4)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (if (> y 0) 2 3)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 (defun solar-degrees-to-quadrant (angle)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 "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
194 (1+ (floor (mod angle 360) 90)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (defun solar-arctan (x quad)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 "Arctangent of X in quadrant QUAD."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (let ((deg (radians-to-degrees (atan x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (cond ((equal quad 2) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 ((equal quad 3) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 ((equal quad 4) (+ deg 360))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (t deg))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (defun solar-arccos (x)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (let ((y (sqrt (- 1 (* x x)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (defun solar-arcsin (y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (let ((x (sqrt (- 1 (* y y)))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (defconst solar-earth-inclination 23.441884
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 "Inclination of earth's equator to its solar orbit in degrees.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (defconst solar-cos-inclination (solar-cosine-degrees solar-earth-inclination)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 "Cosine of earth's inclination.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (defconst solar-sin-inclination (solar-sin-degrees solar-earth-inclination)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 "Sine of earth's inclination.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (defconst solar-earth-orbit-eccentricity 0.016718
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 "Eccentricity of orbit of the earth around the sun.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
224 (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
225 (/ deg 15.0))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
227 (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
228 (/ hour 24.0))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (defun solar-longitude-of-sun (day)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 "Longitude of the sun at DAY in the year."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (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
233 (mod (+ mean-anomaly
c8f5e05c332e (siolar-mode): Remove, since mod now subsumes it. ALl callers changed.
Paul Eggert <eggert@twinsun.com>
parents: 3907
diff changeset
234 (* 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
235 (* 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
236 282.634)
4660
2516bc453477 Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents: 4657
diff changeset
237 360)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (defun solar-right-ascension (longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 "Right ascension of the sun, given its LONGITUDE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (solar-arctan
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (* solar-cos-inclination (solar-tangent-degrees longitude))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (solar-degrees-to-quadrant longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (defun solar-declination (longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 "Declination of the sun, given its LONGITUDE."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (solar-arcsin
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (* solar-sin-inclination
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (solar-sin-degrees longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (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
253 "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
254 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
255 `calendar-longitude'.
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
256
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
257 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
258 that location on that day."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (let* ((day-of-year (calendar-day-number date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (approx-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (+ day-of-year
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (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
263 (- 6 (solar-degrees-to-hours (calendar-longitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (solar-longitude-of-sun-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 (solar-longitude-of-sun approx-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (solar-right-ascension-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (solar-right-ascension solar-longitude-of-sun-at-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (solar-declination-at-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (solar-declination solar-longitude-of-sun-at-sunrise))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (cos-local-sunrise
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (* (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
273 (solar-sin-degrees (calendar-latitude))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (* (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
275 (solar-cosine-degrees (calendar-latitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (if (<= (abs cos-local-sunrise) 1);; otherwise, no sunrise that day
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (let* ((local-sunrise (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (- 360 (solar-arccos cos-local-sunrise))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (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
280 (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
281 (+ (* 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
282 6.622))
4660
2516bc453477 Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents: 4657
diff changeset
283 24)))
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
284 (+ (- local-mean-sunrise (solar-degrees-to-hours (calendar-longitude)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (/ calendar-time-zone 60.0))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (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
288 "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
289 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
290 `calendar-longitude'.
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
291
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
292 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
293 that location on that day."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (let* ((day-of-year (calendar-day-number date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (approx-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 (+ day-of-year
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (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
298 (- 18 (solar-degrees-to-hours (calendar-longitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (solar-longitude-of-sun-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (solar-longitude-of-sun approx-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (solar-right-ascension-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (solar-right-ascension solar-longitude-of-sun-at-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (solar-declination-at-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 (solar-declination solar-longitude-of-sun-at-sunset))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (cos-local-sunset
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 (/ (- (solar-cosine-degrees (+ 90 (/ 50.0 60.0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (* (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
308 (solar-sin-degrees (calendar-latitude))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 (* (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
310 (solar-cosine-degrees (calendar-latitude))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (if (<= (abs cos-local-sunset) 1);; otherwise, no sunset that day
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (let* ((local-sunset (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (solar-arccos cos-local-sunset)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (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
315 (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
316 (+ (* 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
317 24)))
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
318 (+ (- local-mean-sunset (solar-degrees-to-hours (calendar-longitude)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 (/ calendar-time-zone 60.0))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
321 (defun solar-time-string (time time-zone)
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
322 "Printable form for decimal fraction TIME in TIME-ZONE.
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
323 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
324 (let* ((time (round (* 60 time)))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
325 (24-hours (/ time 60))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
326 (minutes (format "%02d" (% time 60)))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
327 (12-hours (format "%d" (1+ (% (+ 24-hours 11) 12))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 (am-pm (if (>= 24-hours 12) "pm" "am"))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (24-hours (format "%02d" 24-hours)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 (mapconcat 'eval calendar-time-display-form "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (defun solar-sunrise-sunset (date)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 "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
334 (let* ((rise (solar-sunrise date))
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
335 (adj-rise (if rise (dst-adjust-time date rise)))
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
336 (set (solar-sunset date))
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
337 (adj-set (if set (dst-adjust-time date set))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (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
339 (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
340 (concat "Sunrise " (apply 'solar-time-string (cdr adj-rise)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 "No sunrise")
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
342 (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
343 (concat "sunset " (apply 'solar-time-string (cdr adj-set)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 "no sunset")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (eval calendar-location-name))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
347 (defun solar-date-next-longitude (d l)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
348 "First moment on or after Julian day number D when sun's longitude is a
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
349 multiple of L degrees at calendar-location-name with that location's
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
350 local time (including any daylight savings rules).
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
351
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
352 L must be an integer divisor of 360.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
353
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
354 Result is in local time expressed astronomical (Julian) day numbers.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
355
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
356 The values of calendar-daylight-savings-starts,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
357 calendar-daylight-savings-starts-time, calendar-daylight-savings-ends,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
358 calendar-daylight-savings-ends-time, calendar-daylight-time-offset, and
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
359 calendar-time-zone are used to interpret local time."
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
360 (let* ((long)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
361 (start d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
362 (start-long (solar-longitude d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
363 (next (mod (* l (1+ (floor (/ start-long l)))) 360))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
364 (end (+ d (* (/ l 360.0) 400)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
365 (end-long (solar-longitude end)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
366 (while ;; bisection search for nearest minute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
367 (< 0.00001 (- end start))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
368 ;; start <= d < end
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
369 ;; start-long <= next < end-long when next != 0
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
370 ;; when next = 0, we look for the discontinuity (start-long is near 360
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
371 ;; and end-long is small (less than l).
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
372 (setq d (/ (+ start end) 2.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
373 (setq long (solar-longitude d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
374 (if (or (and (/= next 0) (< long next))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
375 (and (= next 0) (< l long)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
376 (progn
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
377 (setq start d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
378 (setq start-long long))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
379 (setq end d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
380 (setq end-long long)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
381 (/ (+ start end) 2.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
382
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
383 (defun solar-longitude (d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
384 "Longitude of sun on astronomical (Julian) day number D.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
385 Accurary is about 0.01 degree (about 365.25*24*60*0.01/360 = 15 minutes).
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
386
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
387 The values of calendar-daylight-savings-starts,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
388 calendar-daylight-savings-starts-time, calendar-daylight-savings-ends,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
389 calendar-daylight-savings-ends-time, calendar-daylight-time-offset, and
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
390 calendar-time-zone are used to interpret local time."
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
391 (let* ((a-d (calendar-absolute-from-astro d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
392 (date (calendar-gregorian-from-absolute (floor a-d)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
393 (time (* 24 (- a-d (truncate a-d))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
394 (rounded-abs-date (+ (calendar-absolute-from-gregorian date)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
395 (/ (round (* 60 time)) 60.0 24.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
396 ;; get local standard time
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
397 (a-d (- rounded-abs-date
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
398 (if (dst-in-effect rounded-abs-date)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
399 (/ calendar-daylight-time-offset 24.0 60.0) 0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
400 ;; get Universal Time
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
401 (a-d (- a-d (/ calendar-time-zone 60.0 24.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
402 (date (calendar-astro-from-absolute a-d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
403 ;; get Ephemeris Time
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
404 (date (+ date (solar-ephemeris-correction
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
405 (extract-calendar-year
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
406 (calendar-gregorian-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
407 (floor
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
408 (calendar-absolute-from-astro
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
409 date)))))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
410 (T (/ (- date 2451545.0) 36525.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
411 (Lo (mod (+ 280.46645 (* 36000.76983 T) (* 0.0003032 T T)) 360.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
412 (M (mod (+ 357.52910
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
413 (* 35999.05030 T)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
414 (* -0.0001559 T T)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
415 (* -0.00000048 T T T))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
416 360.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
417 (e (+ 0.016708617 (* -0.000042037 T) (* -0.0000001236 T T)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
418 (C (+ (* (+ 1.914600 (* -0.004817 T) (* -0.000014 T T))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
419 (solar-sin-degrees M))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
420 (* (+ 0.019993 (* -0.000101 T)) (solar-sin-degrees (* 2 M)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
421 (* 0.000290 (solar-sin-degrees (* 3 M)))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
422 (true-longitude (+ Lo C))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
423 (omega (+ 125.04 (* -1934.136 T)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
424 (apparent-longitude (mod
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
425 (+ true-longitude
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
426 -0.00569
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
427 (* -0.00478 (solar-sin-degrees omega)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
428 360.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
429 apparent-longitude))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 (defun solar-ephemeris-correction (year)
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
432 "Ephemeris time minus Universal Time at astronomical (Julian) day D.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
433 Result is in days For the years 1800-1987, the maximum error is 1.9 seconds.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
434 For the other years, the maximum error is about 30 seconds."
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
435 (cond ((and (<= 1988 year) (< year 2020))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
436 (/ (+ year -2000 67.0) 60.0 60.0 24.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
437 ((and (<= 1900 year) (< year 1988))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
438 (let* ((theta (/ (- (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
439 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
440 (list 7 1 year)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
441 (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
442 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
443 '(1 1 1900))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
444 36525.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
445 (theta2 (* theta theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
446 (theta3 (* theta2 theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
447 (theta4 (* theta2 theta2))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
448 (theta5 (* theta3 theta2)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
449 (+ -0.00002
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
450 (* 0.000297 theta)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
451 (* 0.025184 theta2)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
452 (* -0.181133 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
453 (* 0.553040 theta4)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
454 (* -0.861938 theta5)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
455 (* 0.677066 theta3 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
456 (* -0.212591 theta4 theta3))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
457 ((and (<= 1800 year) (< year 1900))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
458 (let* ((theta (/ (- (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
459 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
460 (list 7 1 year)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
461 (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
462 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
463 '(1 1 1900))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
464 36525.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
465 (theta2 (* theta theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
466 (theta3 (* theta2 theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
467 (theta4 (* theta2 theta2))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
468 (theta5 (* theta3 theta2)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
469 (+ -0.000009
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
470 (* 0.003844 theta)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
471 (* 0.083563 theta2)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
472 (* 0.865736 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
473 (* 4.867575 theta4)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
474 (* 15.845535 theta5)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
475 (* 31.332267 theta3 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
476 (* 38.291999 theta4 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
477 (* 28.316289 theta4 theta4)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
478 (* 11.636204 theta4 theta5)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
479 (* 2.043794 theta5 theta5))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
480 ((and (<= 1620 year) (< year 1800))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
481 (let ((x (/ (- year 1600) 10.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
482 (/ (+ (* 2.19167 x x) (* -40.675 x) 196.58333) 60.0 60.0 24.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
483 (t (let* ((tmp (- (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
484 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
485 (list 1 1 year)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
486 2382148))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
487 (second (- (/ (* tmp tmp) 41048480.0) 15)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
488 (/ second 60.0 60.0 24.0)))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 ;;;###autoload
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 (defun sunrise-sunset (&optional arg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 "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
493 If called with an optional prefix argument, prompt for date.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
495 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
496 latitude, time zone, and date, and always use standard time.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 This function is suitable for execution in a .emacs file."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 (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
500 (or arg (setq arg 1))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
501 (if (and (< arg 16)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
502 (not (and calendar-latitude calendar-longitude calendar-time-zone)))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
503 (solar-setup))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 (let* ((calendar-longitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
505 (if (< arg 16) calendar-longitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 (calendar-latitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
509 (if (< arg 16) calendar-latitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 (calendar-time-zone
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
513 (if (< arg 16) calendar-time-zone
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
515 "Enter difference from Coordinated Universal Time (in minutes): ")))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 (calendar-location-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
517 (if (< arg 16) calendar-location-name
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
518 (let ((float-output-format "%.1f"))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
519 (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
520 (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
521 (abs calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
522 (+ (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
523 (/ (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
524 (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
525 (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
526 (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
527 (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
528 (abs calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
529 (+ (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
530 (/ (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
531 (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
532 (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
533 (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
534 "E" "W"))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 (calendar-standard-time-zone-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
536 (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
537 (cond ((= calendar-time-zone 0) "UTC")
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
538 ((< calendar-time-zone 0)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
539 (format "UTC%dmin" calendar-time-zone))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
540 (t (format "UTC+%dmin" calendar-time-zone)))))
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
541 (calendar-daylight-savings-starts
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
542 (if (< arg 16) calendar-daylight-savings-starts))
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
543 (calendar-daylight-savings-ends
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
544 (if (< arg 16) calendar-daylight-savings-ends))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
545 (date (if (< arg 4) (calendar-current-date) (calendar-read-date)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (date-string (calendar-date-string date t))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 (time-string (solar-sunrise-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 (msg (format "%s: %s" date-string time-string))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 (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
550 (if (<= (length msg) (frame-width))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 (message msg)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 (with-output-to-temp-buffer "*temp*"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 (princ (concat date-string "\n" time-string)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 (message (substitute-command-keys
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 (if one-window
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 (if pop-up-windows
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 "Type \\[delete-other-windows] to remove temp window."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 "Type \\[switch-to-buffer] RET to remove temp window.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 "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
560
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 (defun calendar-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 "Local time of sunrise and sunset for date under cursor.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 Accurate to +/- 2 minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 (interactive)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 (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
567 (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
568 (message "%s: %s"
d127e0963a2c (calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents: 5010
diff changeset
569 (calendar-date-string date t t)
d127e0963a2c (calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents: 5010
diff changeset
570 (solar-sunrise-sunset date))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 (defun diary-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 "Local time of sunrise and sunset as a diary entry.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 Accurate to +/- 2 minutes."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 (solar-sunrise-sunset date))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 (defun diary-sabbath-candles ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 "Local time of candle lighting diary entry--applies if date is a Friday.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 No diary entry if there is no sunset on that date."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 (if (= (% (calendar-absolute-from-gregorian date) 7) 5);; Friday
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 (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
586 (light (if sunset
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
587 (dst-adjust-time
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
588 date
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
589 (- 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
590 (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
591 (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
592 (apply 'solar-time-string (cdr light)))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593
5010
9595049f63a9 (solar-equinoxes-solstices): Add autoload.
Richard M. Stallman <rms@gnu.org>
parents: 4863
diff changeset
594 ;;;###autoload
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
595 (defun solar-equinoxes-solstices ()
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 "Date and time of equinoxes and solstices, if visible in the calendar window.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 Requires floating point."
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
598 (let ((m displayed-month)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
599 (y displayed-year))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 (increment-calendar-month m y (cond ((= 1 (% m 3)) -1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 ((= 2 (% m 3)) 1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 (t 0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 (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
604 (if calendar-time-zone calendar-standard-time-zone-name "UTC"))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 (calendar-daylight-savings-starts
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 (if calendar-time-zone calendar-daylight-savings-starts))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 (calendar-daylight-savings-ends
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 (if calendar-time-zone calendar-daylight-savings-ends))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 (calendar-time-zone (if calendar-time-zone calendar-time-zone 0))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 (k (1- (/ m 3)))
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
611 (d (solar-date-next-longitude
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
612 (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
613 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
614 (list (+ 3 (* k 3)) 15 y)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
615 90))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
616 (abs-day (calendar-absolute-from-astro d)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
617 (list
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
618 (list (calendar-gregorian-from-absolute (floor abs-day))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
619 (format "%s %s"
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
620 (nth k (if (and calendar-latitude
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
621 (< (calendar-latitude) 0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
622 solar-s-hemi-seasons
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
623 solar-n-hemi-seasons))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
624 (solar-time-string
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
625 (* 24 (- abs-day (floor abs-day)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
626 (if (dst-in-effect abs-day)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
627 calendar-daylight-time-zone-name
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
628 calendar-standard-time-zone-name))))))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
629
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 (provide 'solar)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 ;;; solar.el ends here