Mercurial > emacs
annotate lisp/calendar/cal-dst.el @ 78076:dc2000c17cdd
*** empty log message ***
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sat, 07 Jul 2007 03:01:31 +0000 |
parents | c56fcbc72ab0 |
children | 93e11478c954 e6fdae9180d4 |
rev | line source |
---|---|
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
1 ;;; cal-dst.el --- calendar functions for daylight saving rules |
3872 | 2 |
68721 | 3 ;; Copyright (C) 1993, 1994, 1995, 1996, 2001, 2002, 2003, 2004, 2005, |
75346 | 4 ;; 2006, 2007 Free Software Foundation, Inc. |
3872 | 5 |
6 ;; Author: Paul Eggert <eggert@twinsun.com> | |
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu> | |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
64085
diff
changeset
|
8 ;; Maintainer: Glenn Morris <rgm@gnu.org> |
3872 | 9 ;; Keywords: calendar |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
10 ;; Human-Keywords: daylight saving time, calendar, diary, holidays |
3872 | 11 |
12 ;; This file is part of GNU Emacs. | |
13 | |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6735
diff
changeset
|
14 ;; 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:
6735
diff
changeset
|
15 ;; 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:
6735
diff
changeset
|
16 ;; 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:
6735
diff
changeset
|
17 ;; any later version. |
3872 | 18 |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6735
diff
changeset
|
19 ;; 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:
6735
diff
changeset
|
20 ;; 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:
6735
diff
changeset
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6735
diff
changeset
|
22 ;; GNU General Public License for more details. |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6735
diff
changeset
|
23 |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
6735
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
14169 | 25 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
3872 | 28 |
29 ;;; Commentary: | |
30 | |
31 ;; This collection of functions implements the features of calendar.el and | |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
32 ;; holiday.el that deal with daylight saving time. |
3872 | 33 |
34 ;;; Code: | |
35 | |
36 (require 'calendar) | |
16726
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
37 (require 'cal-persia) |
3872 | 38 |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
39 (defcustom calendar-dst-check-each-year-flag t |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
40 "Non-nil means to check each year for DST transitions as needed. |
73894
cfa3c02ad6bf
(calendar-dst-check-each-year-flag): Avoid
Andreas Schwab <schwab@suse.de>
parents:
73875
diff
changeset
|
41 Otherwise assume the next two transitions found after the |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
42 current date apply to all years. This is faster, but not always |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
43 correct, since the dates of daylight saving transitions sometimes |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
44 change." |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
45 :type 'boolean |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
46 :version "22.1" |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
47 :group 'calendar) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
48 |
3872 | 49 (defvar calendar-current-time-zone-cache nil |
74870
06cc5e77c85a
(calendar-dst-starts): Default to second Sunday in March.
Richard M. Stallman <rms@gnu.org>
parents:
73894
diff
changeset
|
50 "Cache for result of `calendar-current-time-zone'.") |
06cc5e77c85a
(calendar-dst-starts): Default to second Sunday in March.
Richard M. Stallman <rms@gnu.org>
parents:
73894
diff
changeset
|
51 (put 'calendar-current-time-zone-cache 'risky-local-variable t) |
3872 | 52 |
53 (defvar calendar-system-time-basis | |
54 (calendar-absolute-from-gregorian '(1 1 1970)) | |
55 "Absolute date of starting date of system clock.") | |
56 | |
57 (defun calendar-absolute-from-time (x utc-diff) | |
58 "Absolute local date of time X; local time is UTC-DIFF seconds from UTC. | |
59 | |
60 X is (HIGH . LOW) or (HIGH LOW . IGNORED) where HIGH and LOW are the | |
61 high and low 16 bits, respectively, of the number of seconds since | |
62 1970-01-01 00:00:00 UTC, ignoring leap seconds. | |
63 | |
64 Returns the pair (ABS-DATE . SECONDS) where SECONDS after local midnight on | |
65 absolute date ABS-DATE is the equivalent moment to X." | |
66 (let* ((h (car x)) | |
67 (xtail (cdr x)) | |
68 (l (+ utc-diff (if (numberp xtail) xtail (car xtail)))) | |
4535 | 69 (u (+ (* 512 (mod h 675)) (floor l 128)))) |
3872 | 70 ;; Overflow is a terrible thing! |
71 (cons (+ calendar-system-time-basis | |
72 ;; floor((2^16 h +l) / (60*60*24)) | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
73 (* 512 (floor h 675)) (floor u 675)) |
5001
f3a55af8f584
(calendar-absolute-from-time): Undo Sep 14 patch.
Richard M. Stallman <rms@gnu.org>
parents:
4756
diff
changeset
|
74 ;; (2^16 h +l) mod (60*60*24) |
f3a55af8f584
(calendar-absolute-from-time): Undo Sep 14 patch.
Richard M. Stallman <rms@gnu.org>
parents:
4756
diff
changeset
|
75 (+ (* (mod u 675) 128) (mod l 128))))) |
3872 | 76 |
77 (defun calendar-time-from-absolute (abs-date s) | |
78 "Time of absolute date ABS-DATE, S seconds after midnight. | |
79 | |
56425
5572efece9a6
(calendar-time-from-absolute): Return a list of two integers, instead
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
80 Returns the list (HIGH LOW) where HIGH and LOW are the high and low |
3872 | 81 16 bits, respectively, of the number of seconds 1970-01-01 00:00:00 UTC, |
82 ignoring leap seconds, that is the equivalent moment to S seconds after | |
83 midnight UTC on absolute date ABS-DATE." | |
84 (let* ((a (- abs-date calendar-system-time-basis)) | |
4535 | 85 (u (+ (* 163 (mod a 512)) (floor s 128)))) |
3872 | 86 ;; Overflow is a terrible thing! |
56425
5572efece9a6
(calendar-time-from-absolute): Return a list of two integers, instead
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
87 (list |
5001
f3a55af8f584
(calendar-absolute-from-time): Undo Sep 14 patch.
Richard M. Stallman <rms@gnu.org>
parents:
4756
diff
changeset
|
88 ;; floor((60*60*24*a + s) / 2^16) |
4535 | 89 (+ a (* 163 (floor a 512)) (floor u 512)) |
5001
f3a55af8f584
(calendar-absolute-from-time): Undo Sep 14 patch.
Richard M. Stallman <rms@gnu.org>
parents:
4756
diff
changeset
|
90 ;; (60*60*24*a + s) mod 2^16 |
4535 | 91 (+ (* 128 (mod u 512)) (mod s 128))))) |
3872 | 92 |
93 (defun calendar-next-time-zone-transition (time) | |
94 "Return the time of the next time zone transition after TIME. | |
95 Both TIME and the result are acceptable arguments to current-time-zone. | |
96 Return nil if no such transition can be found." | |
97 (let* ((base 65536);; 2^16 = base of current-time output | |
98 (quarter-multiple 120);; approx = (seconds per quarter year) / base | |
99 (time-zone (current-time-zone time)) | |
100 (time-utc-diff (car time-zone)) | |
101 hi | |
102 hi-zone | |
103 (hi-utc-diff time-utc-diff) | |
104 (quarters '(2 1 3))) | |
105 ;; Heuristic: probe the time zone offset in the next three calendar | |
106 ;; quarters, looking for a time zone offset different from TIME. | |
107 (while (and quarters (eq time-utc-diff hi-utc-diff)) | |
108 (setq hi (cons (+ (car time) (* (car quarters) quarter-multiple)) 0)) | |
109 (setq hi-zone (current-time-zone hi)) | |
110 (setq hi-utc-diff (car hi-zone)) | |
111 (setq quarters (cdr quarters))) | |
112 (and | |
113 time-utc-diff | |
114 hi-utc-diff | |
115 (not (eq time-utc-diff hi-utc-diff)) | |
116 ;; Now HI is after the next time zone transition. | |
117 ;; Set LO to TIME, and then binary search to increase LO and decrease HI | |
118 ;; until LO is just before and HI is just after the time zone transition. | |
119 (let* ((tail (cdr time)) | |
120 (lo (cons (car time) (if (numberp tail) tail (car tail)))) | |
121 probe) | |
122 (while | |
123 ;; Set PROBE to halfway between LO and HI, rounding down. | |
124 ;; If PROBE equals LO, we are done. | |
125 (let* ((lsum (+ (cdr lo) (cdr hi))) | |
126 (hsum (+ (car lo) (car hi) (/ lsum base))) | |
127 (hsumodd (logand 1 hsum))) | |
128 (setq probe (cons (/ (- hsum hsumodd) 2) | |
129 (/ (+ (* hsumodd base) (% lsum base)) 2))) | |
130 (not (equal lo probe))) | |
131 ;; Set either LO or HI to PROBE, depending on probe results. | |
132 (if (eq (car (current-time-zone probe)) hi-utc-diff) | |
133 (setq hi probe) | |
134 (setq lo probe))) | |
135 hi)))) | |
136 | |
137 (defun calendar-time-zone-daylight-rules (abs-date utc-diff) | |
138 "Return daylight transition rule for ABS-DATE, UTC-DIFF sec offset from UTC. | |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
139 ABS-DATE must specify a day that contains a daylight saving transition. |
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
140 The result has the proper form for `calendar-daylight-savings-starts'." |
3872 | 141 (let* ((date (calendar-gregorian-from-absolute abs-date)) |
142 (weekday (% abs-date 7)) | |
143 (m (extract-calendar-month date)) | |
144 (d (extract-calendar-day date)) | |
145 (y (extract-calendar-year date)) | |
146 (last (calendar-last-day-of-month m y)) | |
147 (candidate-rules | |
148 (append | |
149 ;; Day D of month M. | |
150 (list (list 'list m d 'year)) | |
151 ;; The first WEEKDAY of month M. | |
152 (if (< d 8) | |
153 (list (list 'calendar-nth-named-day 1 weekday m 'year))) | |
154 ;; The last WEEKDAY of month M. | |
155 (if (> d (- last 7)) | |
156 (list (list 'calendar-nth-named-day -1 weekday m 'year))) | |
157 ;; The first WEEKDAY after day J of month M, for D-6 < J <= D. | |
158 (let (l) | |
159 (calendar-for-loop j from (max 2 (- d 6)) to (min d (- last 8)) do | |
160 (setq l | |
161 (cons | |
162 (list 'calendar-nth-named-day 1 weekday m 'year j) | |
163 l))) | |
16726
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
164 l) |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
165 ;; 01-01 and 07-01 for this year's Persian calendar. |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
166 (if (and (= m 3) (<= 20 d) (<= d 21)) |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
167 '((calendar-gregorian-from-absolute |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
168 (calendar-absolute-from-persian |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
169 (list 1 1 (- year 621)))))) |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
170 (if (and (= m 9) (<= 22 d) (<= d 23)) |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
171 '((calendar-gregorian-from-absolute |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
172 (calendar-absolute-from-persian |
475649bca297
(calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
173 (list 7 1 (- year 621)))))))) |
3872 | 174 (prevday-sec (- -1 utc-diff)) ;; last sec of previous local day |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
175 (year (1+ y))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
176 ;; Scan through the next few years until only one rule remains. |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
177 (while |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
178 (let ((rules candidate-rules) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
179 new-rules) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
180 (while |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
181 (let* |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
182 ((rule (car rules)) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
183 (date |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
184 ;; The following is much faster than |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
185 ;; (calendar-absolute-from-gregorian (eval rule)). |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
186 (cond ((eq (car rule) 'calendar-nth-named-day) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
187 (eval (cons 'calendar-nth-named-absday (cdr rule)))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
188 ((eq (car rule) 'calendar-gregorian-from-absolute) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
189 (eval (car (cdr rule)))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
190 (t (let ((g (eval rule))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
191 (calendar-absolute-from-gregorian g)))))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
192 (or (equal |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
193 (current-time-zone |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
194 (calendar-time-from-absolute date prevday-sec)) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
195 (current-time-zone |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
196 (calendar-time-from-absolute (1+ date) prevday-sec))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
197 (setq new-rules (cons rule new-rules))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
198 (setq rules (cdr rules)))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
199 ;; If no rules remain, just use the first candidate rule; |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
200 ;; it's wrong in general, but it's right for at least one year. |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
201 (setq candidate-rules (if new-rules (nreverse new-rules) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
202 (list (car candidate-rules)))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
203 (setq year (1+ year)) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
204 (cdr candidate-rules))) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
205 (car candidate-rules))) |
3872 | 206 |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
207 ;; TODO it might be better to extract this information directly from |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
208 ;; the system timezone database. But cross-platform...? |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
209 ;; See thread |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
210 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2006-11/msg00060.html |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
211 (defun calendar-dst-find-data (&optional time) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
212 "Find data on the first daylight saving time transitions after TIME. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
213 TIME defaults to `current-time'. Return value is as described |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
214 for `calendar-current-time-zone'." |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
215 (let* ((t0 (or time (current-time))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
216 (t0-zone (current-time-zone t0)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
217 (t0-utc-diff (car t0-zone)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
218 (t0-name (car (cdr t0-zone)))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
219 (if (not t0-utc-diff) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
220 ;; Little or no time zone information is available. |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
221 (list nil nil t0-name t0-name nil nil nil nil) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
222 (let* ((t1 (calendar-next-time-zone-transition t0)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
223 (t2 (and t1 (calendar-next-time-zone-transition t1)))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
224 (if (not t2) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
225 ;; This locale does not have daylight saving time. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
226 (list (/ t0-utc-diff 60) 0 t0-name t0-name nil nil 0 0) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
227 ;; Use heuristics to find daylight saving parameters. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
228 (let* ((t1-zone (current-time-zone t1)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
229 (t1-utc-diff (car t1-zone)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
230 (t1-name (car (cdr t1-zone))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
231 (t1-date-sec (calendar-absolute-from-time t1 t0-utc-diff)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
232 (t2-date-sec (calendar-absolute-from-time t2 t1-utc-diff)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
233 ;; TODO When calendar-dst-check-each-year-flag is non-nil, |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
234 ;; the rules can be simpler than they currently are. |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
235 (t1-rules (calendar-time-zone-daylight-rules |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
236 (car t1-date-sec) t0-utc-diff)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
237 (t2-rules (calendar-time-zone-daylight-rules |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
238 (car t2-date-sec) t1-utc-diff)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
239 (t1-time (/ (cdr t1-date-sec) 60)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
240 (t2-time (/ (cdr t2-date-sec) 60))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
241 (cons |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
242 (/ (min t0-utc-diff t1-utc-diff) 60) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
243 (cons |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
244 (/ (abs (- t0-utc-diff t1-utc-diff)) 60) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
245 (if (< t0-utc-diff t1-utc-diff) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
246 (list t0-name t1-name t1-rules t2-rules t1-time t2-time) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
247 (list t1-name t0-name t2-rules t1-rules t2-time t1-time) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
248 ))))))))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
249 |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
250 (defvar calendar-dst-transition-cache nil |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
251 "Internal cal-dst variable storing date of daylight saving time transitions. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
252 Value is a list with elements of the form (YEAR START END), where |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
253 START and END are expressions that when evaluated return the |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
254 start and end dates (respectively) for DST in YEAR. Used by the |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
255 function `calendar-dst-find-startend'.") |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
256 |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
257 (defun calendar-dst-find-startend (year) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
258 "Find the dates in YEAR on which daylight saving time starts and ends. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
259 Returns a list (YEAR START END), where START and END are |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
260 expressions that when evaluated return the start and end dates, |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
261 respectively. This function first attempts to use pre-calculated |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
262 data from `calendar-dst-transition-cache', otherwise it calls |
77277
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
263 `calendar-dst-find-data' (and adds the results to the cache). |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
264 If dates in YEAR cannot be handled by `encode-time' (e.g. if they |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
265 are too large to be represented as a lisp integer), then rather |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
266 than an error this function returns the result appropriate for |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
267 the current year." |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
268 (let ((e (assoc year calendar-dst-transition-cache)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
269 f) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
270 (or e |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
271 (progn |
77277
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
272 (setq e (calendar-dst-find-data |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
273 (condition-case nil |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
274 (encode-time 1 0 0 1 1 year) |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
275 (error |
c56fcbc72ab0
(calendar-dst-find-startend): If YEAR cannot be encoded, fall back to
Glenn Morris <rgm@gnu.org>
parents:
76476
diff
changeset
|
276 (encode-time 1 0 0 1 1 (nth 5 (decode-time)))))) |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
277 f (nth 4 e) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
278 e (list year f (nth 5 e)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
279 calendar-dst-transition-cache |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
280 (append calendar-dst-transition-cache (list e))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
281 e)))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
282 |
3872 | 283 (defun calendar-current-time-zone () |
284 "Return UTC difference, dst offset, names and rules for current time zone. | |
285 | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
286 Returns (UTC-DIFF DST-OFFSET STD-ZONE DST-ZONE DST-STARTS DST-ENDS |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
287 DST-STARTS-TIME DST-ENDS-TIME), based on a heuristic probing of what the |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
288 system knows: |
3872 | 289 |
290 UTC-DIFF is an integer specifying the number of minutes difference between | |
291 standard time in the current time zone and Coordinated Universal Time | |
292 (Greenwich Mean Time). A negative value means west of Greenwich. | |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
293 DST-OFFSET is an integer giving the daylight saving time offset in minutes. |
3872 | 294 STD-ZONE is a string giving the name of the time zone when no seasonal time |
295 adjustment is in effect. | |
296 DST-ZONE is a string giving the name of the time zone when there is a seasonal | |
297 time adjustment in effect. | |
298 DST-STARTS and DST-ENDS are sexps in the variable `year' giving the daylight | |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
299 saving time start and end rules, in the form expected by |
3872 | 300 `calendar-daylight-savings-starts'. |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
301 DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
302 after midnight that daylight saving time starts and ends. |
3872 | 303 |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
304 If the local area does not use a seasonal time adjustment, STD-ZONE and |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
305 DST-ZONE are equal, and all the DST-* integer variables are 0. |
3872 | 306 |
307 Some operating systems cannot provide all this information to Emacs; in this | |
308 case, `calendar-current-time-zone' returns a list containing nil for the data | |
309 it can't find." | |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
310 (unless calendar-current-time-zone-cache |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
311 (setq calendar-current-time-zone-cache (calendar-dst-find-data)))) |
3872 | 312 |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
313 ;;; The following eight defvars relating to daylight saving time should NOT be |
3872 | 314 ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is |
315 ;;; dumped. These variables' appropriate values depend on the conditions under | |
316 ;;; which the code is INVOKED; so it's inappropriate to initialize them when | |
317 ;;; Emacs is dumped---they should be initialized when calendar.el is loaded. | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
318 ;;; They default to US Eastern time if time zone info is not available. |
3872 | 319 |
320 (calendar-current-time-zone) | |
321 | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
322 (defvar calendar-time-zone (or (car calendar-current-time-zone-cache) -300) |
3872 | 323 "*Number of minutes difference between local standard time at |
324 `calendar-location-name' and Coordinated Universal (Greenwich) Time. For | |
325 example, -300 for New York City, -480 for Los Angeles.") | |
326 | |
327 (defvar calendar-daylight-time-offset | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
328 (or (car (cdr calendar-current-time-zone-cache)) 60) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
329 "*Number of minutes difference between daylight saving and standard time. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
330 |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
331 If the locale never uses daylight saving time, set this to 0.") |
3872 | 332 |
333 (defvar calendar-standard-time-zone-name | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
334 (or (car (nthcdr 2 calendar-current-time-zone-cache)) "EST") |
3872 | 335 "*Abbreviated name of standard time zone at `calendar-location-name'. |
336 For example, \"EST\" in New York City, \"PST\" for Los Angeles.") | |
337 | |
338 (defvar calendar-daylight-time-zone-name | |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
339 (or (car (nthcdr 3 calendar-current-time-zone-cache)) "EDT") |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
340 "*Abbreviated name of daylight saving time zone at `calendar-location-name'. |
3872 | 341 For example, \"EDT\" in New York City, \"PDT\" for Los Angeles.") |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
342 |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
343 |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
344 (defun calendar-dst-starts (year) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
345 "Return the date of YEAR on which daylight saving time starts. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
346 This function respects the value of `calendar-dst-check-each-year-flag'." |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
347 (or (let ((expr (if calendar-dst-check-each-year-flag |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
348 (cadr (calendar-dst-find-startend year)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
349 (nth 4 calendar-current-time-zone-cache)))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
350 (if expr (eval expr))) |
74871 | 351 ;; New US rules commencing 2007. ftp://elsie.nci.nih.gov/pub/. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
352 (and (not (zerop calendar-daylight-time-offset)) |
74870
06cc5e77c85a
(calendar-dst-starts): Default to second Sunday in March.
Richard M. Stallman <rms@gnu.org>
parents:
73894
diff
changeset
|
353 (calendar-nth-named-day 2 0 3 year)))) |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
354 |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
355 (defun calendar-dst-ends (year) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
356 "Return the date of YEAR on which daylight saving time ends. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
357 This function respects the value of `calendar-dst-check-each-year-flag'." |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
358 (or (let ((expr (if calendar-dst-check-each-year-flag |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
359 (nth 2 (calendar-dst-find-startend year)) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
360 (nth 5 calendar-current-time-zone-cache)))) |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
361 (if expr (eval expr))) |
74871 | 362 ;; New US rules commencing 2007. ftp://elsie.nci.nih.gov/pub/. |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
363 (and (not (zerop calendar-daylight-time-offset)) |
74870
06cc5e77c85a
(calendar-dst-starts): Default to second Sunday in March.
Richard M. Stallman <rms@gnu.org>
parents:
73894
diff
changeset
|
364 (calendar-nth-named-day 1 0 11 year)))) |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
365 |
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
366 |
6735
4930c18bb456
(calendar-daylight-savings-ends)
Richard M. Stallman <rms@gnu.org>
parents:
5001
diff
changeset
|
367 ;;;###autoload |
4930c18bb456
(calendar-daylight-savings-ends)
Richard M. Stallman <rms@gnu.org>
parents:
5001
diff
changeset
|
368 (put 'calendar-daylight-savings-starts 'risky-local-variable t) |
3872 | 369 (defvar calendar-daylight-savings-starts |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
370 '(calendar-dst-starts year) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
371 "*Sexp giving the date on which daylight saving time starts. |
3872 | 372 This is an expression in the variable `year' whose value gives the Gregorian |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
373 date in the form (month day year) on which daylight saving time starts. It is |
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
374 used to determine the starting date of daylight saving time for the holiday |
3872 | 375 list and for correcting times of day in the solar and lunar calculations. |
376 | |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
377 For example, if daylight saving time is mandated to start on October 1, |
3872 | 378 you would set `calendar-daylight-savings-starts' to |
379 | |
380 '(10 1 year) | |
381 | |
4667
dbe2da5db2f7
(calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents:
4659
diff
changeset
|
382 If it starts on the first Sunday in April, you would set it to |
3872 | 383 |
4667
dbe2da5db2f7
(calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents:
4659
diff
changeset
|
384 '(calendar-nth-named-day 1 0 4 year) |
3872 | 385 |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
386 If the locale never uses daylight saving time, set this to nil.") |
3872 | 387 |
6735
4930c18bb456
(calendar-daylight-savings-ends)
Richard M. Stallman <rms@gnu.org>
parents:
5001
diff
changeset
|
388 ;;;###autoload |
7746
abd7e801de63
(calendar-daylight-savings-ends): Fix typo in put.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
389 (put 'calendar-daylight-savings-ends 'risky-local-variable t) |
3872 | 390 (defvar calendar-daylight-savings-ends |
73875
be323d585de0
Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents:
68721
diff
changeset
|
391 '(calendar-dst-ends year) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
392 "*Sexp giving the date on which daylight saving time ends. |
3872 | 393 This is an expression in the variable `year' whose value gives the Gregorian |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
394 date in the form (month day year) on which daylight saving time ends. It is |
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
395 used to determine the starting date of daylight saving time for the holiday |
3872 | 396 list and for correcting times of day in the solar and lunar calculations. |
397 | |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
398 For example, if daylight saving time ends on the last Sunday in October: |
3872 | 399 |
4667
dbe2da5db2f7
(calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents:
4659
diff
changeset
|
400 '(calendar-nth-named-day -1 0 10 year) |
3872 | 401 |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
402 If the locale never uses daylight saving time, set this to nil.") |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
403 |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
404 (defvar calendar-daylight-savings-starts-time |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
405 (or (car (nthcdr 6 calendar-current-time-zone-cache)) 120) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
406 "*Number of minutes after midnight that daylight saving time starts.") |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
407 |
4659
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
408 (defvar calendar-daylight-savings-ends-time |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
409 (or (car (nthcdr 7 calendar-current-time-zone-cache)) |
031aaf217dc3
(calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents:
4535
diff
changeset
|
410 calendar-daylight-savings-starts-time) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
411 "*Number of minutes after midnight that daylight saving time ends.") |
3872 | 412 |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
413 (defun dst-in-effect (date) |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
414 "True if on absolute DATE daylight saving time is in effect. |
13686
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
415 Fractional part of DATE is local standard time of day." |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
416 (let* ((year (extract-calendar-year |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
417 (calendar-gregorian-from-absolute (floor date)))) |
13686
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
418 (dst-starts-gregorian (eval calendar-daylight-savings-starts)) |
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
419 (dst-ends-gregorian (eval calendar-daylight-savings-ends)) |
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
420 (dst-starts (and dst-starts-gregorian |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
421 (+ (calendar-absolute-from-gregorian |
13686
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
422 dst-starts-gregorian) |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
423 (/ calendar-daylight-savings-starts-time |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
424 60.0 24.0)))) |
13686
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
425 (dst-ends (and dst-ends-gregorian |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
426 (+ (calendar-absolute-from-gregorian |
13686
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
427 dst-ends-gregorian) |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
428 (/ (- calendar-daylight-savings-ends-time |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
429 calendar-daylight-time-offset) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
430 60.0 24.0))))) |
13686
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
431 (and dst-starts dst-ends |
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
432 (if (< dst-starts dst-ends) |
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
433 (and (<= dst-starts date) (< date dst-ends)) |
6e3b9c9595eb
Fixed dst-in-effect for southern hemisphere. Also made doc string clearer.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
13049
diff
changeset
|
434 (or (<= dst-starts date) (< date dst-ends)))))) |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
435 |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
436 (defun dst-adjust-time (date time &optional style) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
437 "Adjust, to account for dst on DATE, decimal fraction standard TIME. |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
438 Returns a list (date adj-time zone) where `date' and `adj-time' are the values |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
439 adjusted for `zone'; here `date' is a list (month day year), `adj-time' is a |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
440 decimal fraction time, and `zone' is a string. |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
441 |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
442 Optional parameter STYLE forces the result time to be standard time when its |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
443 value is 'standard and daylight saving time (if available) when its value is |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
444 'daylight. |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
445 |
76476
3878691bdbb7
Change "daylight savings time" -> "daylight saving time" throughout.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
446 Conversion to daylight saving time is done according to |
13049
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
447 `calendar-daylight-savings-starts', `calendar-daylight-savings-ends', |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
448 `calendar-daylight-savings-starts-time', |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
449 `calendar-daylight-savings-ends-time', and |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
450 `calendar-daylight-savings-offset'." |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
451 |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
452 (let* ((rounded-abs-date (+ (calendar-absolute-from-gregorian date) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
453 (/ (round (* 60 time)) 60.0 24.0))) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
454 (dst (dst-in-effect rounded-abs-date)) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
455 (time-zone (if dst |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
456 calendar-daylight-time-zone-name |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
457 calendar-standard-time-zone-name)) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
458 (time (+ rounded-abs-date |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
459 (if dst (/ calendar-daylight-time-offset 24.0 60.0) 0)))) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
460 (list (calendar-gregorian-from-absolute (truncate time)) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
461 (* 24.0 (- time (truncate time))) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
462 time-zone))) |
fac816f95bd8
Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7749
diff
changeset
|
463 |
3872 | 464 (provide 'cal-dst) |
465 | |
52401 | 466 ;;; arch-tag: a141d204-213c-4ca5-bdc6-f9df3aa92aad |
3872 | 467 ;;; cal-dst.el ends here |