emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calendar gets wrong end for Daylight Savings Time


From: Glenn Morris
Subject: Re: calendar gets wrong end for Daylight Savings Time
Date: Thu, 09 Nov 2006 04:41:23 -0500
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

Here's a patch that works in the manner I have tried to describe. It
works with no noticeable slow-down on my (admittedly, fairly new)
machine. I can install if desired.


*** cal-dst.el  07 Feb 2006 23:46:47 -0800      1.24
--- cal-dst.el  09 Nov 2006 01:37:31 -0800      
***************
*** 42,47 ****
--- 42,57 ----
  (require 'calendar)
  (require 'cal-persia)
  
+ (defcustom calendar-dst-check-each-year-flag t
+   "Non-nil means to check each year for DST transitions as needed.
+ Nil means to assume the next two transitions found after the
+ current date apply to all years.  This is faster, but not always
+ correct, since the dates of Daylight Saving transitions sometimes
+ change."
+   :type 'boolean
+   :version "22.1"
+   :group 'calendar)
+ 
  (defvar calendar-current-time-zone-cache nil
    "Cache for result of calendar-current-time-zone.")
  
***************
*** 199,236 ****
          (cdr candidate-rules)))
      (car candidate-rules)))
  
! (defun calendar-current-time-zone ()
!   "Return UTC difference, dst offset, names and rules for current time zone.
! 
! 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:
! 
! 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.
! DST-OFFSET is an integer giving the daylight savings time offset in minutes.
! 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
!     savings time start and end rules, in the form expected by
!     `calendar-daylight-savings-starts'.
! DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes
!     after midnight that daylight savings time starts and ends.
! 
! 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.
! 
! 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."
!   (or
!    calendar-current-time-zone-cache
!    (setq
!     calendar-current-time-zone-cache
!     (let* ((t0 (current-time))
           (t0-zone (current-time-zone t0))
           (t0-utc-diff (car t0-zone))
           (t0-name (car (cdr t0-zone))))
--- 209,219 ----
          (cdr candidate-rules)))
      (car candidate-rules)))
  
! (defun calendar-dst-find-data (&optional time)
!   "Find data on the first Daylight Saving Time transitions after TIME.
! 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))
           (t0-name (car (cdr t0-zone))))
***************
*** 261,267 ****
                (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)
!                   )))))))))))
  
  ;;; The following eight defvars relating to daylight savings time should NOT 
be
  ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is
--- 244,325 ----
                (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
!   "Internal cal-dst variable storing date of Daylight Saving Time transitions.
! Value is a list with elements of the form (YEAR START END), where
! START and END are expressions that when evaluated return the
! start and end dates (respectively) for DST in YEAR. Used by the
! function `calendar-dst-find-startend'.")
! 
! (defun calendar-dst-find-startend (year)
!   "Find the dates in YEAR on which Daylight Saving Time starts and ends.
! 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
! `calendar-dst-find-data' (and adds the results to the cache)."
!   (let ((e (assoc year calendar-dst-transition-cache))
!         f)
!     (or e
!         (progn
!           (setq e (calendar-dst-find-data (encode-time 1 0 0 1 1 year))
!                 f (nth 4 e)
!                 e (list year f (nth 5 e))
!                 calendar-dst-transition-cache
!                 (append calendar-dst-transition-cache (list e)))
!           e))))
! 
! (defun calendar-dst-starts (year)
!   "Return the date of YEAR on which Daylight Saving Time starts.
! 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)))
!       (and (not (zerop calendar-daylight-time-offset))
!            (calendar-nth-named-day 1 0 4 year))))
! 
! (defun calendar-dst-ends (year)
!   "Return the date of YEAR on which Daylight Saving Time ends.
! 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)))
!       (and (not (zerop calendar-daylight-time-offset))
!            (calendar-nth-named-day -1 0 10 year))))
! 
! (defun calendar-current-time-zone ()
!   "Return UTC difference, dst offset, names and rules for current time zone.
! 
! 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:
! 
! 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.
! DST-OFFSET is an integer giving the daylight savings time offset in minutes.
! 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
!     savings time start and end rules, in the form expected by
!     `calendar-daylight-savings-starts'.
! DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes
!     after midnight that daylight savings time starts and ends.
! 
! 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.
! 
! 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."
!   (unless calendar-current-time-zone-cache
!     (setq calendar-current-time-zone-cache (calendar-dst-find-data))))
  
  ;;; The following eight defvars relating to daylight savings time should NOT 
be
  ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is
***************
*** 296,304 ****
  ;;;###autoload
  (put 'calendar-daylight-savings-starts 'risky-local-variable t)
  (defvar calendar-daylight-savings-starts
!   (or (car (nthcdr 4 calendar-current-time-zone-cache))
!       (and (not (zerop calendar-daylight-time-offset))
!          '(calendar-nth-named-day 1 0 4 year)))
    "*Sexp giving the date on which daylight savings 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 savings time starts.  It 
is
--- 354,360 ----
  ;;;###autoload
  (put 'calendar-daylight-savings-starts 'risky-local-variable t)
  (defvar calendar-daylight-savings-starts
!   '(calendar-dst-starts year)
    "*Sexp giving the date on which daylight savings 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 savings time starts.  It 
is
***************
*** 319,327 ****
  ;;;###autoload
  (put 'calendar-daylight-savings-ends 'risky-local-variable t)
  (defvar calendar-daylight-savings-ends
!   (or (car (nthcdr 5 calendar-current-time-zone-cache))
!       (and (not (zerop calendar-daylight-time-offset))
!          '(calendar-nth-named-day -1 0 10 year)))
    "*Sexp giving the date on which daylight savings 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 savings time ends.  It is
--- 375,381 ----
  ;;;###autoload
  (put 'calendar-daylight-savings-ends 'risky-local-variable t)
  (defvar calendar-daylight-savings-ends
!   '(calendar-dst-ends year)
    "*Sexp giving the date on which daylight savings 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 savings time ends.  It is





reply via email to

[Prev in Thread] Current Thread [Next in Thread]