annotate lisp/calendar/cal-dst.el @ 73875:be323d585de0

Do not assume DST starts/ends on the same date in every year. (calendar-dst-check-each-year-flag): New customizable variable. (calendar-dst-find-data): New function, extracted from calendar-current-time-zone. (calendar-current-time-zone): Use calendar-dst-find-data. (calendar-dst-transition-cache): New variable. (calendar-dst-find-startend, calendar-dst-starts) (calendar-dst-ends): New functions. (calendar-daylight-savings-starts) (calendar-daylight-savings-ends): Change value to use calendar-dst-starts, calendar-dst-ends; respectively.
author Glenn Morris <rgm@gnu.org>
date Fri, 10 Nov 2006 08:54:38 +0000
parents 8daf7d9a0771
children cfa3c02ad6bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 16726
diff changeset
1 ;;; cal-dst.el --- calendar functions for daylight savings rules
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
68721
8daf7d9a0771 Add 2006 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 67465
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995, 1996, 2001, 2002, 2003, 2004, 2005,
8daf7d9a0771 Add 2006 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 67465
diff changeset
4 ;; 2006 Free Software Foundation, Inc.
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 ;; Author: Paul Eggert <eggert@twinsun.com>
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; Keywords: calendar
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; Human-Keywords: daylight savings time, calendar, diary, holidays
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; This file is part of GNU Emacs.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13686
diff changeset
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 56425
diff changeset
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 56425
diff changeset
27 ;; Boston, MA 02110-1301, USA.
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;;; Commentary:
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ;; This collection of functions implements the features of calendar.el and
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; holiday.el that deal with daylight savings time.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; Comments, corrections, and improvements should be sent to
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; Edward M. Reingold Department of Computer Science
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;; Urbana, Illinois 61801
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;;; Code:
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 (require 'calendar)
16726
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
43 (require 'cal-persia)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
73875
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
45 (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
46 "Non-nil means to check each year for DST transitions as needed.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
47 nil means to assume the next two transitions found after the
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
48 current date apply to all years. This is faster, but not always
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
49 correct, since the dates of Daylight Saving transitions sometimes
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
50 change."
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
51 :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
52 :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
53 :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
54
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (defvar calendar-current-time-zone-cache nil
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 "Cache for result of calendar-current-time-zone.")
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (defvar calendar-system-time-basis
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (calendar-absolute-from-gregorian '(1 1 1970))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 "Absolute date of starting date of system clock.")
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 (defun calendar-absolute-from-time (x utc-diff)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 "Absolute local date of time X; local time is UTC-DIFF seconds from UTC.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 X is (HIGH . LOW) or (HIGH LOW . IGNORED) where HIGH and LOW are the
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 high and low 16 bits, respectively, of the number of seconds since
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 1970-01-01 00:00:00 UTC, ignoring leap seconds.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 Returns the pair (ABS-DATE . SECONDS) where SECONDS after local midnight on
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 absolute date ABS-DATE is the equivalent moment to X."
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (let* ((h (car x))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (xtail (cdr x))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (l (+ utc-diff (if (numberp xtail) xtail (car xtail))))
4535
cf77def3abe2 Undo last change.
Roland McGrath <roland@gnu.org>
parents: 4534
diff changeset
74 (u (+ (* 512 (mod h 675)) (floor l 128))))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 ;; Overflow is a terrible thing!
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (cons (+ calendar-system-time-basis
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 ;; 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
78 (* 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
79 ;; (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
80 (+ (* (mod u 675) 128) (mod l 128)))))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 (defun calendar-time-from-absolute (abs-date s)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 "Time of absolute date ABS-DATE, S seconds after midnight.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
56425
5572efece9a6 (calendar-time-from-absolute): Return a list of two integers, instead
Luc Teirlinck <teirllm@auburn.edu>
parents: 52401
diff changeset
85 Returns the list (HIGH LOW) where HIGH and LOW are the high and low
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 16 bits, respectively, of the number of seconds 1970-01-01 00:00:00 UTC,
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 ignoring leap seconds, that is the equivalent moment to S seconds after
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 midnight UTC on absolute date ABS-DATE."
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (let* ((a (- abs-date calendar-system-time-basis))
4535
cf77def3abe2 Undo last change.
Roland McGrath <roland@gnu.org>
parents: 4534
diff changeset
90 (u (+ (* 163 (mod a 512)) (floor s 128))))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 ;; 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
92 (list
5001
f3a55af8f584 (calendar-absolute-from-time): Undo Sep 14 patch.
Richard M. Stallman <rms@gnu.org>
parents: 4756
diff changeset
93 ;; floor((60*60*24*a + s) / 2^16)
4535
cf77def3abe2 Undo last change.
Roland McGrath <roland@gnu.org>
parents: 4534
diff changeset
94 (+ 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
95 ;; (60*60*24*a + s) mod 2^16
4535
cf77def3abe2 Undo last change.
Roland McGrath <roland@gnu.org>
parents: 4534
diff changeset
96 (+ (* 128 (mod u 512)) (mod s 128)))))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (defun calendar-next-time-zone-transition (time)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 "Return the time of the next time zone transition after TIME.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 Both TIME and the result are acceptable arguments to current-time-zone.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 Return nil if no such transition can be found."
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (let* ((base 65536);; 2^16 = base of current-time output
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 (quarter-multiple 120);; approx = (seconds per quarter year) / base
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (time-zone (current-time-zone time))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (time-utc-diff (car time-zone))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 hi
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 hi-zone
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (hi-utc-diff time-utc-diff)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (quarters '(2 1 3)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 ;; Heuristic: probe the time zone offset in the next three calendar
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 ;; quarters, looking for a time zone offset different from TIME.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (while (and quarters (eq time-utc-diff hi-utc-diff))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (setq hi (cons (+ (car time) (* (car quarters) quarter-multiple)) 0))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (setq hi-zone (current-time-zone hi))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (setq hi-utc-diff (car hi-zone))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (setq quarters (cdr quarters)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (and
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 time-utc-diff
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 hi-utc-diff
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (not (eq time-utc-diff hi-utc-diff))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 ;; Now HI is after the next time zone transition.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 ;; Set LO to TIME, and then binary search to increase LO and decrease HI
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 ;; until LO is just before and HI is just after the time zone transition.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (let* ((tail (cdr time))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 (lo (cons (car time) (if (numberp tail) tail (car tail))))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 probe)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (while
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 ;; Set PROBE to halfway between LO and HI, rounding down.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 ;; If PROBE equals LO, we are done.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (let* ((lsum (+ (cdr lo) (cdr hi)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (hsum (+ (car lo) (car hi) (/ lsum base)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (hsumodd (logand 1 hsum)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (setq probe (cons (/ (- hsum hsumodd) 2)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (/ (+ (* hsumodd base) (% lsum base)) 2)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 (not (equal lo probe)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 ;; Set either LO or HI to PROBE, depending on probe results.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (if (eq (car (current-time-zone probe)) hi-utc-diff)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (setq hi probe)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (setq lo probe)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 hi))))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (defun calendar-time-zone-daylight-rules (abs-date utc-diff)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 "Return daylight transition rule for ABS-DATE, UTC-DIFF sec offset from UTC.
16726
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
144 ABS-DATE must specify a day that contains a daylight savings transition.
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 The result has the proper form for calendar-daylight-savings-starts'."
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (let* ((date (calendar-gregorian-from-absolute abs-date))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (weekday (% abs-date 7))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (m (extract-calendar-month date))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (d (extract-calendar-day date))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (y (extract-calendar-year date))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 (last (calendar-last-day-of-month m y))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (candidate-rules
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (append
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 ;; Day D of month M.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (list (list 'list m d 'year))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 ;; The first WEEKDAY of month M.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (if (< d 8)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 (list (list 'calendar-nth-named-day 1 weekday m 'year)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 ;; The last WEEKDAY of month M.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 (if (> d (- last 7))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (list (list 'calendar-nth-named-day -1 weekday m 'year)))
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 ;; The first WEEKDAY after day J of month M, for D-6 < J <= D.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (let (l)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (calendar-for-loop j from (max 2 (- d 6)) to (min d (- last 8)) do
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (setq l
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (cons
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (list 'calendar-nth-named-day 1 weekday m 'year j)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 l)))
16726
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
169 l)
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
170 ;; 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
171 (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
172 '((calendar-gregorian-from-absolute
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
173 (calendar-absolute-from-persian
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
174 (list 1 1 (- year 621))))))
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
175 (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
176 '((calendar-gregorian-from-absolute
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
177 (calendar-absolute-from-persian
475649bca297 (calendar-time-zone-daylight-rules): Add support
Paul Eggert <eggert@twinsun.com>
parents: 14169
diff changeset
178 (list 7 1 (- year 621))))))))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (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
180 (year (1+ y)))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
181 ;; 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
182 (while
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
183 (let ((rules candidate-rules)
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
184 new-rules)
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
185 (while
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
186 (let*
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
187 ((rule (car rules))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
188 (date
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
189 ;; The following is much faster than
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
190 ;; (calendar-absolute-from-gregorian (eval rule)).
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
191 (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
192 (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
193 ((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
194 (eval (car (cdr rule))))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
195 (t (let ((g (eval rule)))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
196 (calendar-absolute-from-gregorian g))))))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
197 (or (equal
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
198 (current-time-zone
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
199 (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
200 (current-time-zone
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
201 (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
202 (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
203 (setq rules (cdr rules))))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
204 ;; 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
205 ;; 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
206 (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
207 (list (car candidate-rules))))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
208 (setq year (1+ year))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
209 (cdr candidate-rules)))
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
210 (car candidate-rules)))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
73875
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
212 ;; 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
213 ;; 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
214 ;; 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
215 ;; 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
216 (defun calendar-dst-find-data (&optional time)
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
217 "Find data on the first Daylight Saving Time transitions after TIME.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
218 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
219 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
220 (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
221 (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
222 (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
223 (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
224 (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
225 ;; 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
226 (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
227 (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
228 (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
229 (if (not t2)
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
230 ;; This locale does not have daylight savings time.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
231 (list (/ t0-utc-diff 60) 0 t0-name t0-name nil nil 0 0)
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
232 ;; Use heuristics to find daylight savings parameters.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
233 (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
234 (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
235 (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
236 (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
237 (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
238 ;; 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
239 ;; 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
240 (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
241 (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
242 (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
243 (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
244 (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
245 (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
246 (cons
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
247 (/ (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
248 (cons
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
249 (/ (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
250 (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
251 (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
252 (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
253 )))))))))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
254
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
255 (defvar calendar-dst-transition-cache nil
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
256 "Internal cal-dst variable storing date of Daylight Saving Time transitions.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
257 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
258 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
259 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
260 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
261
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
262 (defun 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
263 "Find the dates in YEAR on which Daylight Saving Time starts and ends.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
264 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
265 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
266 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
267 data from `calendar-dst-transition-cache', otherwise it calls
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
268 `calendar-dst-find-data' (and adds the results to the 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 (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
270 f)
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
271 (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
272 (progn
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
273 (setq e (calendar-dst-find-data (encode-time 1 0 0 1 1 year))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
274 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
275 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
276 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
277 (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
278 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
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (defun calendar-current-time-zone ()
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 "Return UTC difference, dst offset, names and rules for current time zone.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
283 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
284 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
285 system knows:
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 UTC-DIFF is an integer specifying the number of minutes difference between
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 standard time in the current time zone and Coordinated Universal Time
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 (Greenwich Mean Time). A negative value means west of Greenwich.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 DST-OFFSET is an integer giving the daylight savings time offset in minutes.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 STD-ZONE is a string giving the name of the time zone when no seasonal time
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 adjustment is in effect.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 DST-ZONE is a string giving the name of the time zone when there is a seasonal
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 time adjustment in effect.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 DST-STARTS and DST-ENDS are sexps in the variable `year' giving the daylight
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
296 savings time start and end rules, in the form expected by
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 `calendar-daylight-savings-starts'.
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
298 DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
299 after midnight that daylight savings time starts and ends.
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
301 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
302 DST-ZONE are equal, and all the DST-* integer variables are 0.
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 Some operating systems cannot provide all this information to Emacs; in this
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 case, `calendar-current-time-zone' returns a list containing nil for the data
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 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
307 (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
308 (setq calendar-current-time-zone-cache (calendar-dst-find-data))))
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309
13049
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
310 ;;; The following eight defvars relating to daylight savings time should NOT be
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 ;;; dumped. These variables' appropriate values depend on the conditions under
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 ;;; which the code is INVOKED; so it's inappropriate to initialize them when
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 ;;; 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
315 ;;; They default to US Eastern time if time zone info is not available.
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 (calendar-current-time-zone)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
319 (defvar calendar-time-zone (or (car calendar-current-time-zone-cache) -300)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 "*Number of minutes difference between local standard time at
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 `calendar-location-name' and Coordinated Universal (Greenwich) Time. For
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 example, -300 for New York City, -480 for Los Angeles.")
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (defvar calendar-daylight-time-offset
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
325 (or (car (cdr calendar-current-time-zone-cache)) 60)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 "*Number of minutes difference between daylight savings and standard time.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38422
diff changeset
327
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 If the locale never uses daylight savings time, set this to 0.")
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 (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
331 (or (car (nthcdr 2 calendar-current-time-zone-cache)) "EST")
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 "*Abbreviated name of standard time zone at `calendar-location-name'.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 For example, \"EST\" in New York City, \"PST\" for Los Angeles.")
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 (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
336 (or (car (nthcdr 3 calendar-current-time-zone-cache)) "EDT")
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 "*Abbreviated name of daylight-savings time zone at `calendar-location-name'.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 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
339
73875
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
340
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
341 (defun calendar-dst-starts (year)
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
342 "Return the date of YEAR on which Daylight Saving Time starts.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
343 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
344 (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
345 (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
346 (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
347 (if expr (eval expr)))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
348 (and (not (zerop calendar-daylight-time-offset))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
349 (calendar-nth-named-day 1 0 4 year))))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
350
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
351 (defun calendar-dst-ends (year)
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
352 "Return the date of YEAR on which Daylight Saving Time ends.
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
353 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
354 (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
355 (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
356 (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
357 (if expr (eval expr)))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
358 (and (not (zerop calendar-daylight-time-offset))
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
359 (calendar-nth-named-day -1 0 10 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
be323d585de0 Do not assume DST starts/ends on the same date in every year.
Glenn Morris <rgm@gnu.org>
parents: 68721
diff changeset
361
6735
4930c18bb456 (calendar-daylight-savings-ends)
Richard M. Stallman <rms@gnu.org>
parents: 5001
diff changeset
362 ;;;###autoload
4930c18bb456 (calendar-daylight-savings-ends)
Richard M. Stallman <rms@gnu.org>
parents: 5001
diff changeset
363 (put 'calendar-daylight-savings-starts 'risky-local-variable t)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (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
365 '(calendar-dst-starts year)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 "*Sexp giving the date on which daylight savings time starts.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 This is an expression in the variable `year' whose value gives the Gregorian
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 date in the form (month day year) on which daylight savings time starts. It is
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 used to determine the starting date of daylight savings time for the holiday
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 list and for correcting times of day in the solar and lunar calculations.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 For example, if daylight savings time is mandated to start on October 1,
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 you would set `calendar-daylight-savings-starts' to
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 '(10 1 year)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376
4667
dbe2da5db2f7 (calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents: 4659
diff changeset
377 If it starts on the first Sunday in April, you would set it to
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
4667
dbe2da5db2f7 (calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents: 4659
diff changeset
379 '(calendar-nth-named-day 1 0 4 year)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 If the locale never uses daylight savings time, set this to nil.")
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
6735
4930c18bb456 (calendar-daylight-savings-ends)
Richard M. Stallman <rms@gnu.org>
parents: 5001
diff changeset
383 ;;;###autoload
7746
abd7e801de63 (calendar-daylight-savings-ends): Fix typo in put.
Richard M. Stallman <rms@gnu.org>
parents: 7300
diff changeset
384 (put 'calendar-daylight-savings-ends 'risky-local-variable t)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (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
386 '(calendar-dst-ends year)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 "*Sexp giving the date on which daylight savings time ends.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 This is an expression in the variable `year' whose value gives the Gregorian
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 date in the form (month day year) on which daylight savings time ends. It is
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 used to determine the starting date of daylight savings time for the holiday
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 list and for correcting times of day in the solar and lunar calculations.
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392
4667
dbe2da5db2f7 (calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents: 4659
diff changeset
393 For example, if daylight savings time ends on the last Sunday in October:
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394
4667
dbe2da5db2f7 (calendar-time-zone-daylight-rules): Remove special case for Israel.
Paul Eggert <eggert@twinsun.com>
parents: 4659
diff changeset
395 '(calendar-nth-named-day -1 0 10 year)
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 If the locale never uses daylight savings time, set this to nil.")
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38422
diff changeset
398
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
399 (defvar calendar-daylight-savings-starts-time
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
400 (or (car (nthcdr 6 calendar-current-time-zone-cache)) 120)
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
401 "*Number of minutes after midnight that daylight savings time starts.")
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38422
diff changeset
402
4659
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
403 (defvar calendar-daylight-savings-ends-time
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
404 (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
405 calendar-daylight-savings-starts-time)
031aaf217dc3 (calendar-time-zone-daylight-rules): Scan through the
Paul Eggert <eggert@twinsun.com>
parents: 4535
diff changeset
406 "*Number of minutes after midnight that daylight savings time ends.")
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407
13049
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
408 (defun dst-in-effect (date)
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
409 "True if on absolute DATE daylight savings 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
410 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
411 (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
412 (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
413 (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
414 (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
415 (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
416 (+ (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
417 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
418 (/ 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
419 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
420 (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
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-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
423 (/ (- 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
424 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
425 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
426 (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
427 (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
428 (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
429 (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
430
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
431 (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
432 "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
433 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
434 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
435 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
436
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
437 Optional parameter STYLE forces the result time to be standard time when its
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
438 value is 'standard and daylight savings time (if available) when its value is
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
439 'daylight.
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
440
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
441 Conversion to daylight savings time is done according to
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
442 `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
443 `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
444 `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
445 `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
446
fac816f95bd8 Minor fixes; moved some code here from other calendar files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7749
diff changeset
447 (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
448 (/ (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
449 (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
450 (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
451 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
452 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
453 (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
454 (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
455 (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
456 (* 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
457 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
458
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 (provide 'cal-dst)
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
461 ;;; arch-tag: a141d204-213c-4ca5-bdc6-f9df3aa92aad
3872
923a207e7967 * cal-dst.el: New file.
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 ;;; cal-dst.el ends here