2007-03-17 17:49:59 +00:00
|
|
|
;;; cal-dst.el --- calendar functions for daylight saving rules
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
2006-02-08 07:54:11 +00:00
|
|
|
;; Copyright (C) 1993, 1994, 1995, 1996, 2001, 2002, 2003, 2004, 2005,
|
2008-01-07 01:14:52 +00:00
|
|
|
;; 2006, 2007, 2008 Free Software Foundation, Inc.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
;; Author: Paul Eggert <eggert@twinsun.com>
|
2008-03-13 06:29:28 +00:00
|
|
|
;; Edward M. Reingold <reingold@cs.uiuc.edu>
|
2005-12-10 05:46:09 +00:00
|
|
|
;; Maintainer: Glenn Morris <rgm@gnu.org>
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
;; Keywords: calendar
|
2007-03-17 17:49:59 +00:00
|
|
|
;; Human-Keywords: daylight saving time, calendar, diary, holidays
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
1994-04-07 20:30:18 +00:00
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2007-07-25 03:51:22 +00:00
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
1994-04-07 20:30:18 +00:00
|
|
|
;; any later version.
|
|
|
|
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
1994-04-07 20:30:18 +00:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
2005-07-04 17:55:18 +00:00
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-04-01 02:39:52 +00:00
|
|
|
;; See calendar.el.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'calendar)
|
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
|
|
|
|
(defgroup calendar-dst nil
|
|
|
|
"Options related to Daylight Saving Time."
|
|
|
|
:prefix "calendar-"
|
|
|
|
:group 'calendar)
|
|
|
|
|
|
|
|
|
2006-11-10 08:54:38 +00:00
|
|
|
(defcustom calendar-dst-check-each-year-flag t
|
|
|
|
"Non-nil means to check each year for DST transitions as needed.
|
2006-11-10 15:04:03 +00:00
|
|
|
Otherwise assume the next two transitions found after the
|
2006-11-10 08:54:38 +00:00
|
|
|
current date apply to all years. This is faster, but not always
|
2007-03-17 17:49:59 +00:00
|
|
|
correct, since the dates of daylight saving transitions sometimes
|
2006-11-10 08:54:38 +00:00
|
|
|
change."
|
|
|
|
:type 'boolean
|
|
|
|
:version "22.1"
|
|
|
|
:group 'calendar)
|
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
;;;###autoload
|
|
|
|
(put 'calendar-daylight-savings-starts 'risky-local-variable t)
|
|
|
|
(defcustom calendar-daylight-savings-starts '(calendar-dst-starts year)
|
|
|
|
"Sexp giving the date on which daylight saving time starts.
|
|
|
|
This is an expression in the variable `year' whose value gives the Gregorian
|
|
|
|
date in the form (month day year) on which daylight saving time starts. It is
|
|
|
|
used to determine the starting date of daylight saving time for the holiday
|
|
|
|
list and for correcting times of day in the solar and lunar calculations.
|
|
|
|
|
|
|
|
For example, if daylight saving time is mandated to start on October 1,
|
|
|
|
you would set `calendar-daylight-savings-starts' to
|
|
|
|
|
|
|
|
'(10 1 year)
|
|
|
|
|
|
|
|
If it starts on the first Sunday in April, you would set it to
|
|
|
|
|
|
|
|
'(calendar-nth-named-day 1 0 4 year)
|
|
|
|
|
|
|
|
If the locale never uses daylight saving time, set this to nil."
|
|
|
|
:type 'sexp
|
|
|
|
:group 'calendar-dst)
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(put 'calendar-daylight-savings-ends 'risky-local-variable t)
|
|
|
|
(defcustom calendar-daylight-savings-ends '(calendar-dst-ends year)
|
|
|
|
"Sexp giving the date on which daylight saving time ends.
|
|
|
|
This is an expression in the variable `year' whose value gives the Gregorian
|
|
|
|
date in the form (month day year) on which daylight saving time ends. It is
|
|
|
|
used to determine the starting date of daylight saving time for the holiday
|
|
|
|
list and for correcting times of day in the solar and lunar calculations.
|
|
|
|
|
|
|
|
For example, if daylight saving time ends on the last Sunday in October:
|
|
|
|
|
|
|
|
'(calendar-nth-named-day -1 0 10 year)
|
|
|
|
|
|
|
|
If the locale never uses daylight saving time, set this to nil."
|
|
|
|
:type 'sexp
|
|
|
|
:group 'calendar-dst)
|
|
|
|
|
|
|
|
;;; More defcustoms below.
|
|
|
|
|
|
|
|
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(defvar calendar-current-time-zone-cache nil
|
2006-12-24 02:58:41 +00:00
|
|
|
"Cache for result of `calendar-current-time-zone'.")
|
2008-03-07 05:13:00 +00:00
|
|
|
(put 'calendar-current-time-zone-cache 'risky-local-variable t) ; why?
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
(defvar calendar-system-time-basis
|
|
|
|
(calendar-absolute-from-gregorian '(1 1 1970))
|
|
|
|
"Absolute date of starting date of system clock.")
|
|
|
|
|
|
|
|
(defun calendar-absolute-from-time (x utc-diff)
|
|
|
|
"Absolute local date of time X; local time is UTC-DIFF seconds from UTC.
|
|
|
|
|
|
|
|
X is (HIGH . LOW) or (HIGH LOW . IGNORED) where HIGH and LOW are the
|
|
|
|
high and low 16 bits, respectively, of the number of seconds since
|
|
|
|
1970-01-01 00:00:00 UTC, ignoring leap seconds.
|
|
|
|
|
|
|
|
Returns the pair (ABS-DATE . SECONDS) where SECONDS after local midnight on
|
|
|
|
absolute date ABS-DATE is the equivalent moment to X."
|
|
|
|
(let* ((h (car x))
|
2008-03-13 06:29:28 +00:00
|
|
|
(xtail (cdr x))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(l (+ utc-diff (if (numberp xtail) xtail (car xtail))))
|
1993-08-10 17:57:31 +00:00
|
|
|
(u (+ (* 512 (mod h 675)) (floor l 128))))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
;; Overflow is a terrible thing!
|
|
|
|
(cons (+ calendar-system-time-basis
|
2008-03-13 06:29:28 +00:00
|
|
|
;; floor((2^16 h +l) / (60*60*24))
|
|
|
|
(* 512 (floor h 675)) (floor u 675))
|
|
|
|
;; (2^16 h +l) mod (60*60*24)
|
|
|
|
(+ (* (mod u 675) 128) (mod l 128)))))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
(defun calendar-time-from-absolute (abs-date s)
|
|
|
|
"Time of absolute date ABS-DATE, S seconds after midnight.
|
|
|
|
|
2004-07-14 23:22:14 +00:00
|
|
|
Returns the list (HIGH LOW) where HIGH and LOW are the high and low
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
16 bits, respectively, of the number of seconds 1970-01-01 00:00:00 UTC,
|
|
|
|
ignoring leap seconds, that is the equivalent moment to S seconds after
|
|
|
|
midnight UTC on absolute date ABS-DATE."
|
|
|
|
(let* ((a (- abs-date calendar-system-time-basis))
|
1993-08-10 17:57:31 +00:00
|
|
|
(u (+ (* 163 (mod a 512)) (floor s 128))))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
;; Overflow is a terrible thing!
|
2004-07-14 23:22:14 +00:00
|
|
|
(list
|
1993-11-13 23:59:53 +00:00
|
|
|
;; floor((60*60*24*a + s) / 2^16)
|
1993-08-10 17:57:31 +00:00
|
|
|
(+ a (* 163 (floor a 512)) (floor u 512))
|
1993-11-13 23:59:53 +00:00
|
|
|
;; (60*60*24*a + s) mod 2^16
|
1993-08-10 17:57:31 +00:00
|
|
|
(+ (* 128 (mod u 512)) (mod s 128)))))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
(defun calendar-next-time-zone-transition (time)
|
|
|
|
"Return the time of the next time zone transition after TIME.
|
2008-03-08 20:41:30 +00:00
|
|
|
Both TIME and the result are acceptable arguments to `current-time-zone'.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
Return nil if no such transition can be found."
|
2008-03-15 02:58:24 +00:00
|
|
|
(let* ((base 65536) ; 2^16 = base of current-time output
|
|
|
|
(quarter-multiple 120) ; approx = (seconds per quarter year) / base
|
2008-03-13 06:29:28 +00:00
|
|
|
(time-zone (current-time-zone time))
|
|
|
|
(time-utc-diff (car time-zone))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
hi
|
2008-03-13 06:29:28 +00:00
|
|
|
hi-zone
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(hi-utc-diff time-utc-diff)
|
|
|
|
(quarters '(2 1 3)))
|
|
|
|
;; Heuristic: probe the time zone offset in the next three calendar
|
|
|
|
;; quarters, looking for a time zone offset different from TIME.
|
|
|
|
(while (and quarters (eq time-utc-diff hi-utc-diff))
|
2008-03-14 03:38:38 +00:00
|
|
|
(setq hi (cons (+ (car time) (* (car quarters) quarter-multiple)) 0)
|
|
|
|
hi-zone (current-time-zone hi)
|
|
|
|
hi-utc-diff (car hi-zone)
|
|
|
|
quarters (cdr quarters)))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(and
|
|
|
|
time-utc-diff
|
|
|
|
hi-utc-diff
|
|
|
|
(not (eq time-utc-diff hi-utc-diff))
|
|
|
|
;; Now HI is after the next time zone transition.
|
|
|
|
;; Set LO to TIME, and then binary search to increase LO and decrease HI
|
|
|
|
;; until LO is just before and HI is just after the time zone transition.
|
|
|
|
(let* ((tail (cdr time))
|
2008-03-13 06:29:28 +00:00
|
|
|
(lo (cons (car time) (if (numberp tail) tail (car tail))))
|
|
|
|
probe)
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(while
|
2008-03-13 06:29:28 +00:00
|
|
|
;; Set PROBE to halfway between LO and HI, rounding down.
|
|
|
|
;; If PROBE equals LO, we are done.
|
|
|
|
(let* ((lsum (+ (cdr lo) (cdr hi)))
|
|
|
|
(hsum (+ (car lo) (car hi) (/ lsum base)))
|
|
|
|
(hsumodd (logand 1 hsum)))
|
|
|
|
(setq probe (cons (/ (- hsum hsumodd) 2)
|
|
|
|
(/ (+ (* hsumodd base) (% lsum base)) 2)))
|
|
|
|
(not (equal lo probe)))
|
|
|
|
;; Set either LO or HI to PROBE, depending on probe results.
|
|
|
|
(if (eq (car (current-time-zone probe)) hi-utc-diff)
|
|
|
|
(setq hi probe)
|
|
|
|
(setq lo probe)))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
hi))))
|
|
|
|
|
2008-03-26 03:10:23 +00:00
|
|
|
(autoload 'calendar-absolute-from-persian "cal-persia")
|
|
|
|
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(defun calendar-time-zone-daylight-rules (abs-date utc-diff)
|
|
|
|
"Return daylight transition rule for ABS-DATE, UTC-DIFF sec offset from UTC.
|
2007-03-17 17:49:59 +00:00
|
|
|
ABS-DATE must specify a day that contains a daylight saving transition.
|
|
|
|
The result has the proper form for `calendar-daylight-savings-starts'."
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(let* ((date (calendar-gregorian-from-absolute abs-date))
|
2008-03-13 06:29:28 +00:00
|
|
|
(weekday (% abs-date 7))
|
|
|
|
(m (extract-calendar-month date))
|
|
|
|
(d (extract-calendar-day date))
|
|
|
|
(y (extract-calendar-year date))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(last (calendar-last-day-of-month m y))
|
2008-03-13 06:29:28 +00:00
|
|
|
(candidate-rules
|
|
|
|
(append
|
|
|
|
;; Day D of month M.
|
|
|
|
(list (list 'list m d 'year))
|
|
|
|
;; The first WEEKDAY of month M.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(if (< d 8)
|
|
|
|
(list (list 'calendar-nth-named-day 1 weekday m 'year)))
|
2008-03-13 06:29:28 +00:00
|
|
|
;; The last WEEKDAY of month M.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(if (> d (- last 7))
|
|
|
|
(list (list 'calendar-nth-named-day -1 weekday m 'year)))
|
2008-03-13 06:29:28 +00:00
|
|
|
;; The first WEEKDAY after day J of month M, for D-6 < J <= D.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(let (l)
|
|
|
|
(calendar-for-loop j from (max 2 (- d 6)) to (min d (- last 8)) do
|
2008-03-13 06:29:28 +00:00
|
|
|
(setq l
|
|
|
|
(cons
|
|
|
|
(list 'calendar-nth-named-day
|
|
|
|
1 weekday m 'year j)
|
|
|
|
l)))
|
|
|
|
l)
|
|
|
|
;; 01-01 and 07-01 for this year's Persian calendar.
|
|
|
|
(if (and (= m 3) (<= 20 d) (<= d 21))
|
|
|
|
'((calendar-gregorian-from-absolute
|
|
|
|
(calendar-absolute-from-persian
|
|
|
|
(list 1 1 (- year 621))))))
|
|
|
|
(if (and (= m 9) (<= 22 d) (<= d 23))
|
|
|
|
'((calendar-gregorian-from-absolute
|
|
|
|
(calendar-absolute-from-persian
|
|
|
|
(list 7 1 (- year 621))))))))
|
2008-03-15 02:58:24 +00:00
|
|
|
(prevday-sec (- -1 utc-diff)) ; last sec of previous local day
|
2008-03-13 06:29:28 +00:00
|
|
|
(year (1+ y)))
|
(calendar-time-zone-daylight-rules): Scan through the
next few years until at most one rule remains; if none remain, then
just use the first candidate rule; it's wrong in general, but it's
right for at least one year. This is a better heuristic in case the
underlying time zone implementation has bugs (which is all too
common). If possible, don't convert back and forth between gregorian
and absolute; this speeds things up noticeably. This uses the new
calendar-nth-named-absday function.
(calendar-current-time-zone): Some locales start DST at a different
time of day than they end; allow for this by yielding both times. The
performance speedups in calendar.el are great enough that we now no
longer need the "Checking time zone data..." message. If
current-time-zone yields nil, don't bother with
calendar-next-time-zone-transition. Use clearer names for local vars.
(calendar-time-zone, calendar-daylight-time-offset,
calendar-{standard,daylight}-time-zone-name,
calendar-daylight-savings-{starts,ends}): Default to US Eastern rules
for information that is not available.
(calendar-daylight-savings-{starts,ends}-time): New vars, replacing
calendar-daylight-savings-switchover-time, to support locales that
start DST at a different time of day than they end.
(calendar-absolute-from-time):
Fix typo by interchanging floor and mod.
1993-08-28 04:14:25 +00:00
|
|
|
;; Scan through the next few years until only one rule remains.
|
2008-03-14 03:38:38 +00:00
|
|
|
(while (let ((rules candidate-rules)
|
|
|
|
new-rules)
|
|
|
|
(dolist (rule rules)
|
|
|
|
(let ((date
|
|
|
|
;; The following is much faster than
|
|
|
|
;; (calendar-absolute-from-gregorian (eval rule)).
|
|
|
|
(cond ((eq (car rule) 'calendar-nth-named-day)
|
|
|
|
(eval (cons 'calendar-nth-named-absday
|
|
|
|
(cdr rule))))
|
|
|
|
((eq (car rule) 'calendar-gregorian-from-absolute)
|
|
|
|
(eval (cadr rule)))
|
|
|
|
(t (calendar-absolute-from-gregorian
|
|
|
|
(eval rule))))))
|
|
|
|
(or (equal
|
|
|
|
(current-time-zone
|
|
|
|
(calendar-time-from-absolute date prevday-sec))
|
|
|
|
(current-time-zone
|
|
|
|
(calendar-time-from-absolute (1+ date) prevday-sec)))
|
|
|
|
(setq new-rules (cons rule new-rules)))))
|
|
|
|
;; If no rules remain, just use the first candidate rule;
|
|
|
|
;; it's wrong in general, but it's right for at least one year.
|
|
|
|
(setq candidate-rules (if new-rules (nreverse new-rules)
|
|
|
|
(list (car candidate-rules)))
|
|
|
|
year (1+ year))
|
|
|
|
(cdr candidate-rules)))
|
(calendar-time-zone-daylight-rules): Scan through the
next few years until at most one rule remains; if none remain, then
just use the first candidate rule; it's wrong in general, but it's
right for at least one year. This is a better heuristic in case the
underlying time zone implementation has bugs (which is all too
common). If possible, don't convert back and forth between gregorian
and absolute; this speeds things up noticeably. This uses the new
calendar-nth-named-absday function.
(calendar-current-time-zone): Some locales start DST at a different
time of day than they end; allow for this by yielding both times. The
performance speedups in calendar.el are great enough that we now no
longer need the "Checking time zone data..." message. If
current-time-zone yields nil, don't bother with
calendar-next-time-zone-transition. Use clearer names for local vars.
(calendar-time-zone, calendar-daylight-time-offset,
calendar-{standard,daylight}-time-zone-name,
calendar-daylight-savings-{starts,ends}): Default to US Eastern rules
for information that is not available.
(calendar-daylight-savings-{starts,ends}-time): New vars, replacing
calendar-daylight-savings-switchover-time, to support locales that
start DST at a different time of day than they end.
(calendar-absolute-from-time):
Fix typo by interchanging floor and mod.
1993-08-28 04:14:25 +00:00
|
|
|
(car candidate-rules)))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
2006-11-10 08:54:38 +00:00
|
|
|
;; TODO it might be better to extract this information directly from
|
|
|
|
;; the system timezone database. But cross-platform...?
|
|
|
|
;; See thread
|
|
|
|
;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2006-11/msg00060.html
|
|
|
|
(defun calendar-dst-find-data (&optional time)
|
2007-03-17 17:49:59 +00:00
|
|
|
"Find data on the first daylight saving time transitions after TIME.
|
2006-11-10 08:54:38 +00:00
|
|
|
TIME defaults to `current-time'. Return value is as described
|
|
|
|
for `calendar-current-time-zone'."
|
|
|
|
(let* ((t0 (or time (current-time)))
|
|
|
|
(t0-zone (current-time-zone t0))
|
|
|
|
(t0-utc-diff (car t0-zone))
|
2008-03-14 03:38:38 +00:00
|
|
|
(t0-name (cadr t0-zone)))
|
2006-11-10 08:54:38 +00:00
|
|
|
(if (not t0-utc-diff)
|
|
|
|
;; Little or no time zone information is available.
|
|
|
|
(list nil nil t0-name t0-name nil nil nil nil)
|
|
|
|
(let* ((t1 (calendar-next-time-zone-transition t0))
|
|
|
|
(t2 (and t1 (calendar-next-time-zone-transition t1))))
|
|
|
|
(if (not t2)
|
2007-03-17 17:49:59 +00:00
|
|
|
;; This locale does not have daylight saving time.
|
2006-11-10 08:54:38 +00:00
|
|
|
(list (/ t0-utc-diff 60) 0 t0-name t0-name nil nil 0 0)
|
2007-03-17 17:49:59 +00:00
|
|
|
;; Use heuristics to find daylight saving parameters.
|
2006-11-10 08:54:38 +00:00
|
|
|
(let* ((t1-zone (current-time-zone t1))
|
|
|
|
(t1-utc-diff (car t1-zone))
|
2008-03-14 03:38:38 +00:00
|
|
|
(t1-name (cadr t1-zone))
|
2006-11-10 08:54:38 +00:00
|
|
|
(t1-date-sec (calendar-absolute-from-time t1 t0-utc-diff))
|
|
|
|
(t2-date-sec (calendar-absolute-from-time t2 t1-utc-diff))
|
|
|
|
;; TODO When calendar-dst-check-each-year-flag is non-nil,
|
|
|
|
;; the rules can be simpler than they currently are.
|
|
|
|
(t1-rules (calendar-time-zone-daylight-rules
|
|
|
|
(car t1-date-sec) t0-utc-diff))
|
|
|
|
(t2-rules (calendar-time-zone-daylight-rules
|
|
|
|
(car t2-date-sec) t1-utc-diff))
|
|
|
|
(t1-time (/ (cdr t1-date-sec) 60))
|
|
|
|
(t2-time (/ (cdr t2-date-sec) 60)))
|
|
|
|
(cons
|
|
|
|
(/ (min t0-utc-diff t1-utc-diff) 60)
|
|
|
|
(cons
|
|
|
|
(/ (abs (- t0-utc-diff t1-utc-diff)) 60)
|
|
|
|
(if (< t0-utc-diff t1-utc-diff)
|
|
|
|
(list t0-name t1-name t1-rules t2-rules t1-time t2-time)
|
|
|
|
(list t1-name t0-name t2-rules t1-rules t2-time t1-time)
|
|
|
|
)))))))))
|
|
|
|
|
|
|
|
(defvar calendar-dst-transition-cache nil
|
2007-03-17 17:49:59 +00:00
|
|
|
"Internal cal-dst variable storing date of daylight saving time transitions.
|
2006-11-10 08:54:38 +00:00
|
|
|
Value is a list with elements of the form (YEAR START END), where
|
|
|
|
START and END are expressions that when evaluated return the
|
2008-03-08 20:41:30 +00:00
|
|
|
start and end dates (respectively) for DST in YEAR. Used by the
|
2006-11-10 08:54:38 +00:00
|
|
|
function `calendar-dst-find-startend'.")
|
|
|
|
|
|
|
|
(defun calendar-dst-find-startend (year)
|
2007-03-17 17:49:59 +00:00
|
|
|
"Find the dates in YEAR on which daylight saving time starts and ends.
|
2006-11-10 08:54:38 +00:00
|
|
|
Returns a list (YEAR START END), where START and END are
|
|
|
|
expressions that when evaluated return the start and end dates,
|
|
|
|
respectively. This function first attempts to use pre-calculated
|
|
|
|
data from `calendar-dst-transition-cache', otherwise it calls
|
2007-04-17 02:29:50 +00:00
|
|
|
`calendar-dst-find-data' (and adds the results to the cache).
|
|
|
|
If dates in YEAR cannot be handled by `encode-time' (e.g. if they
|
|
|
|
are too large to be represented as a lisp integer), then rather
|
|
|
|
than an error this function returns the result appropriate for
|
|
|
|
the current year."
|
2006-11-10 08:54:38 +00:00
|
|
|
(let ((e (assoc year calendar-dst-transition-cache))
|
|
|
|
f)
|
|
|
|
(or e
|
|
|
|
(progn
|
2007-04-17 02:29:50 +00:00
|
|
|
(setq e (calendar-dst-find-data
|
|
|
|
(condition-case nil
|
|
|
|
(encode-time 1 0 0 1 1 year)
|
|
|
|
(error
|
|
|
|
(encode-time 1 0 0 1 1 (nth 5 (decode-time))))))
|
2006-11-10 08:54:38 +00:00
|
|
|
f (nth 4 e)
|
|
|
|
e (list year f (nth 5 e))
|
|
|
|
calendar-dst-transition-cache
|
|
|
|
(append calendar-dst-transition-cache (list e)))
|
|
|
|
e))))
|
|
|
|
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(defun calendar-current-time-zone ()
|
|
|
|
"Return UTC difference, dst offset, names and rules for current time zone.
|
|
|
|
|
(calendar-time-zone-daylight-rules): Scan through the
next few years until at most one rule remains; if none remain, then
just use the first candidate rule; it's wrong in general, but it's
right for at least one year. This is a better heuristic in case the
underlying time zone implementation has bugs (which is all too
common). If possible, don't convert back and forth between gregorian
and absolute; this speeds things up noticeably. This uses the new
calendar-nth-named-absday function.
(calendar-current-time-zone): Some locales start DST at a different
time of day than they end; allow for this by yielding both times. The
performance speedups in calendar.el are great enough that we now no
longer need the "Checking time zone data..." message. If
current-time-zone yields nil, don't bother with
calendar-next-time-zone-transition. Use clearer names for local vars.
(calendar-time-zone, calendar-daylight-time-offset,
calendar-{standard,daylight}-time-zone-name,
calendar-daylight-savings-{starts,ends}): Default to US Eastern rules
for information that is not available.
(calendar-daylight-savings-{starts,ends}-time): New vars, replacing
calendar-daylight-savings-switchover-time, to support locales that
start DST at a different time of day than they end.
(calendar-absolute-from-time):
Fix typo by interchanging floor and mod.
1993-08-28 04:14:25 +00:00
|
|
|
Returns (UTC-DIFF DST-OFFSET STD-ZONE DST-ZONE DST-STARTS DST-ENDS
|
|
|
|
DST-STARTS-TIME DST-ENDS-TIME), based on a heuristic probing of what the
|
|
|
|
system knows:
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
UTC-DIFF is an integer specifying the number of minutes difference between
|
|
|
|
standard time in the current time zone and Coordinated Universal Time
|
|
|
|
(Greenwich Mean Time). A negative value means west of Greenwich.
|
2007-03-17 17:49:59 +00:00
|
|
|
DST-OFFSET is an integer giving the daylight saving time offset in minutes.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
STD-ZONE is a string giving the name of the time zone when no seasonal time
|
|
|
|
adjustment is in effect.
|
|
|
|
DST-ZONE is a string giving the name of the time zone when there is a seasonal
|
|
|
|
time adjustment in effect.
|
|
|
|
DST-STARTS and DST-ENDS are sexps in the variable `year' giving the daylight
|
2007-03-17 17:49:59 +00:00
|
|
|
saving time start and end rules, in the form expected by
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
`calendar-daylight-savings-starts'.
|
(calendar-time-zone-daylight-rules): Scan through the
next few years until at most one rule remains; if none remain, then
just use the first candidate rule; it's wrong in general, but it's
right for at least one year. This is a better heuristic in case the
underlying time zone implementation has bugs (which is all too
common). If possible, don't convert back and forth between gregorian
and absolute; this speeds things up noticeably. This uses the new
calendar-nth-named-absday function.
(calendar-current-time-zone): Some locales start DST at a different
time of day than they end; allow for this by yielding both times. The
performance speedups in calendar.el are great enough that we now no
longer need the "Checking time zone data..." message. If
current-time-zone yields nil, don't bother with
calendar-next-time-zone-transition. Use clearer names for local vars.
(calendar-time-zone, calendar-daylight-time-offset,
calendar-{standard,daylight}-time-zone-name,
calendar-daylight-savings-{starts,ends}): Default to US Eastern rules
for information that is not available.
(calendar-daylight-savings-{starts,ends}-time): New vars, replacing
calendar-daylight-savings-switchover-time, to support locales that
start DST at a different time of day than they end.
(calendar-absolute-from-time):
Fix typo by interchanging floor and mod.
1993-08-28 04:14:25 +00:00
|
|
|
DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes
|
2007-03-17 17:49:59 +00:00
|
|
|
after midnight that daylight saving time starts and ends.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
(calendar-time-zone-daylight-rules): Scan through the
next few years until at most one rule remains; if none remain, then
just use the first candidate rule; it's wrong in general, but it's
right for at least one year. This is a better heuristic in case the
underlying time zone implementation has bugs (which is all too
common). If possible, don't convert back and forth between gregorian
and absolute; this speeds things up noticeably. This uses the new
calendar-nth-named-absday function.
(calendar-current-time-zone): Some locales start DST at a different
time of day than they end; allow for this by yielding both times. The
performance speedups in calendar.el are great enough that we now no
longer need the "Checking time zone data..." message. If
current-time-zone yields nil, don't bother with
calendar-next-time-zone-transition. Use clearer names for local vars.
(calendar-time-zone, calendar-daylight-time-offset,
calendar-{standard,daylight}-time-zone-name,
calendar-daylight-savings-{starts,ends}): Default to US Eastern rules
for information that is not available.
(calendar-daylight-savings-{starts,ends}-time): New vars, replacing
calendar-daylight-savings-switchover-time, to support locales that
start DST at a different time of day than they end.
(calendar-absolute-from-time):
Fix typo by interchanging floor and mod.
1993-08-28 04:14:25 +00:00
|
|
|
If the local area does not use a seasonal time adjustment, STD-ZONE and
|
|
|
|
DST-ZONE are equal, and all the DST-* integer variables are 0.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
Some operating systems cannot provide all this information to Emacs; in this
|
|
|
|
case, `calendar-current-time-zone' returns a list containing nil for the data
|
|
|
|
it can't find."
|
2006-11-10 08:54:38 +00:00
|
|
|
(unless calendar-current-time-zone-cache
|
|
|
|
(setq calendar-current-time-zone-cache (calendar-dst-find-data))))
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
|
|
|
|
;; Following options should be set based on conditions when the code
|
|
|
|
;; is invoked, so are not suitable for dumping into loaddefs.el. They
|
|
|
|
;; default to US Eastern time if time zone info is not available.
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
|
|
|
(calendar-current-time-zone)
|
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
(defcustom calendar-time-zone (or (car calendar-current-time-zone-cache) -300)
|
2008-03-08 20:41:30 +00:00
|
|
|
"Number of minutes difference between local standard time and UTC.
|
2008-03-07 05:13:00 +00:00
|
|
|
For example, -300 for New York City, -480 for Los Angeles."
|
|
|
|
:type 'integer
|
|
|
|
:group 'calendar-dst)
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
(defcustom calendar-daylight-time-offset
|
2008-03-14 03:38:38 +00:00
|
|
|
(or (cadr calendar-current-time-zone-cache) 60)
|
2008-03-07 05:13:00 +00:00
|
|
|
"Number of minutes difference between daylight saving and standard time.
|
|
|
|
If the locale never uses daylight saving time, set this to 0."
|
|
|
|
:type 'integer
|
|
|
|
:group 'calendar-dst)
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
(defcustom calendar-standard-time-zone-name
|
2008-03-14 03:38:38 +00:00
|
|
|
(or (nth 2 calendar-current-time-zone-cache) "EST")
|
2008-03-07 05:13:00 +00:00
|
|
|
"Abbreviated name of standard time zone at `calendar-location-name'.
|
|
|
|
For example, \"EST\" in New York City, \"PST\" for Los Angeles."
|
|
|
|
:type 'string
|
|
|
|
:group 'calendar-dst)
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
|
2008-03-07 05:13:00 +00:00
|
|
|
(defcustom calendar-daylight-time-zone-name
|
2008-03-14 03:38:38 +00:00
|
|
|
(or (nth 3 calendar-current-time-zone-cache) "EDT")
|
2008-03-07 05:13:00 +00:00
|
|
|
"Abbreviated name of daylight saving time zone at `calendar-location-name'.
|
|
|
|
For example, \"EDT\" in New York City, \"PDT\" for Los Angeles."
|
|
|
|
:type 'string
|
|
|
|
:group 'calendar-dst)
|
|
|
|
|
|
|
|
(defcustom calendar-daylight-savings-starts-time
|
2008-03-14 03:38:38 +00:00
|
|
|
(or (nth 6 calendar-current-time-zone-cache) 120)
|
2008-03-07 05:13:00 +00:00
|
|
|
"Number of minutes after midnight that daylight saving time starts."
|
|
|
|
:type 'integer
|
|
|
|
:group 'calendar-dst)
|
|
|
|
|
|
|
|
(defcustom calendar-daylight-savings-ends-time
|
2008-03-14 03:38:38 +00:00
|
|
|
(or (nth 7 calendar-current-time-zone-cache)
|
2008-03-07 05:13:00 +00:00
|
|
|
calendar-daylight-savings-starts-time)
|
|
|
|
"Number of minutes after midnight that daylight saving time ends."
|
|
|
|
:type 'integer
|
|
|
|
:group 'calendar-dst)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
2006-11-10 08:54:38 +00:00
|
|
|
|
|
|
|
(defun calendar-dst-starts (year)
|
2007-03-17 17:49:59 +00:00
|
|
|
"Return the date of YEAR on which daylight saving time starts.
|
2006-11-10 08:54:38 +00:00
|
|
|
This function respects the value of `calendar-dst-check-each-year-flag'."
|
|
|
|
(or (let ((expr (if calendar-dst-check-each-year-flag
|
|
|
|
(cadr (calendar-dst-find-startend year))
|
|
|
|
(nth 4 calendar-current-time-zone-cache))))
|
|
|
|
(if expr (eval expr)))
|
2008-03-13 06:29:28 +00:00
|
|
|
;; New US rules commencing 2007. ftp://elsie.nci.nih.gov/pub/.
|
2006-11-10 08:54:38 +00:00
|
|
|
(and (not (zerop calendar-daylight-time-offset))
|
2006-12-24 02:58:41 +00:00
|
|
|
(calendar-nth-named-day 2 0 3 year))))
|
2006-11-10 08:54:38 +00:00
|
|
|
|
|
|
|
(defun calendar-dst-ends (year)
|
2007-03-17 17:49:59 +00:00
|
|
|
"Return the date of YEAR on which daylight saving time ends.
|
2006-11-10 08:54:38 +00:00
|
|
|
This function respects the value of `calendar-dst-check-each-year-flag'."
|
|
|
|
(or (let ((expr (if calendar-dst-check-each-year-flag
|
|
|
|
(nth 2 (calendar-dst-find-startend year))
|
|
|
|
(nth 5 calendar-current-time-zone-cache))))
|
|
|
|
(if expr (eval expr)))
|
2008-03-13 06:29:28 +00:00
|
|
|
;; New US rules commencing 2007. ftp://elsie.nci.nih.gov/pub/.
|
2006-11-10 08:54:38 +00:00
|
|
|
(and (not (zerop calendar-daylight-time-offset))
|
2006-12-24 02:58:41 +00:00
|
|
|
(calendar-nth-named-day 1 0 11 year))))
|
2006-11-10 08:54:38 +00:00
|
|
|
|
1995-09-21 02:54:58 +00:00
|
|
|
(defun dst-in-effect (date)
|
2007-03-17 17:49:59 +00:00
|
|
|
"True if on absolute DATE daylight saving time is in effect.
|
1995-12-05 22:55:22 +00:00
|
|
|
Fractional part of DATE is local standard time of day."
|
1995-09-21 02:54:58 +00:00
|
|
|
(let* ((year (extract-calendar-year
|
|
|
|
(calendar-gregorian-from-absolute (floor date))))
|
1995-12-05 22:55:22 +00:00
|
|
|
(dst-starts-gregorian (eval calendar-daylight-savings-starts))
|
|
|
|
(dst-ends-gregorian (eval calendar-daylight-savings-ends))
|
|
|
|
(dst-starts (and dst-starts-gregorian
|
1995-09-21 02:54:58 +00:00
|
|
|
(+ (calendar-absolute-from-gregorian
|
1995-12-05 22:55:22 +00:00
|
|
|
dst-starts-gregorian)
|
1995-09-21 02:54:58 +00:00
|
|
|
(/ calendar-daylight-savings-starts-time
|
|
|
|
60.0 24.0))))
|
1995-12-05 22:55:22 +00:00
|
|
|
(dst-ends (and dst-ends-gregorian
|
1995-09-21 02:54:58 +00:00
|
|
|
(+ (calendar-absolute-from-gregorian
|
1995-12-05 22:55:22 +00:00
|
|
|
dst-ends-gregorian)
|
1995-09-21 02:54:58 +00:00
|
|
|
(/ (- calendar-daylight-savings-ends-time
|
|
|
|
calendar-daylight-time-offset)
|
|
|
|
60.0 24.0)))))
|
1995-12-05 22:55:22 +00:00
|
|
|
(and dst-starts dst-ends
|
|
|
|
(if (< dst-starts dst-ends)
|
|
|
|
(and (<= dst-starts date) (< date dst-ends))
|
|
|
|
(or (<= dst-starts date) (< date dst-ends))))))
|
1995-09-21 02:54:58 +00:00
|
|
|
|
|
|
|
(defun dst-adjust-time (date time &optional style)
|
|
|
|
"Adjust, to account for dst on DATE, decimal fraction standard TIME.
|
|
|
|
Returns a list (date adj-time zone) where `date' and `adj-time' are the values
|
|
|
|
adjusted for `zone'; here `date' is a list (month day year), `adj-time' is a
|
|
|
|
decimal fraction time, and `zone' is a string.
|
|
|
|
|
|
|
|
Optional parameter STYLE forces the result time to be standard time when its
|
2007-03-17 17:49:59 +00:00
|
|
|
value is 'standard and daylight saving time (if available) when its value is
|
1995-09-21 02:54:58 +00:00
|
|
|
'daylight.
|
|
|
|
|
2007-03-17 17:49:59 +00:00
|
|
|
Conversion to daylight saving time is done according to
|
1995-09-21 02:54:58 +00:00
|
|
|
`calendar-daylight-savings-starts', `calendar-daylight-savings-ends',
|
|
|
|
`calendar-daylight-savings-starts-time',
|
2008-03-26 03:10:23 +00:00
|
|
|
`calendar-daylight-savings-ends-time', and `calendar-daylight-time-offset'."
|
1995-09-21 02:54:58 +00:00
|
|
|
|
|
|
|
(let* ((rounded-abs-date (+ (calendar-absolute-from-gregorian date)
|
2008-03-13 06:29:28 +00:00
|
|
|
(/ (round (* 60 time)) 60.0 24.0)))
|
1995-09-21 02:54:58 +00:00
|
|
|
(dst (dst-in-effect rounded-abs-date))
|
2008-03-13 06:29:28 +00:00
|
|
|
(time-zone (if dst
|
|
|
|
calendar-daylight-time-zone-name
|
|
|
|
calendar-standard-time-zone-name))
|
|
|
|
(time (+ rounded-abs-date
|
1995-09-21 02:54:58 +00:00
|
|
|
(if dst (/ calendar-daylight-time-offset 24.0 60.0) 0))))
|
|
|
|
(list (calendar-gregorian-from-absolute (truncate time))
|
|
|
|
(* 24.0 (- time (truncate time)))
|
|
|
|
time-zone)))
|
|
|
|
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
(provide 'cal-dst)
|
|
|
|
|
2008-03-08 03:40:33 +00:00
|
|
|
;; arch-tag: a141d204-213c-4ca5-bdc6-f9df3aa92aad
|
* cal-dst.el: New file.
(calendar-/, calendar-%, calendar-absolute-from-time,
calendar-time-from-absolute, calendar-next-time-zone-transition,
calendar-time-zone-daylight-rules): New functions.
(calendar-current-time-zone): Moved from calendar.el and rewritten.
(calendar-current-time-zone-cache): New variable.
(calendar-current-time-zone, calendar-time-zone,
calendar-daylight-time-offset, calendar-standard-time-zone-name,
calendar-daylight-time-zone-name,
calendar-daylight-savings-starts, calendar-daylight-savings-ends,
calendar-daylight-savings-switchover-time): Moved from calendar.el.
1993-06-22 03:25:13 +00:00
|
|
|
;;; cal-dst.el ends here
|