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