aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2017-12-04 15:50:14 -0500
committerStefan Monnier2017-12-04 15:50:14 -0500
commit2dd14bf72504c1ba2b505f70d864b13e0661fc79 (patch)
tree23a8850b2f63674264d325038dcd0d5a98f23d26
parentad039f9bcc89a8468f9eeb35ebe41a3792926ff7 (diff)
downloademacs-2dd14bf72504c1ba2b505f70d864b13e0661fc79.tar.gz
emacs-2dd14bf72504c1ba2b505f70d864b13e0661fc79.zip
* lisp/calendar/cal-dst.el: Use lexical-binding
(calendar-time-zone-daylight-rules, calendar-dst-starts) (calendar-dst-ends, dst-in-effect): Bind `year' explicitly around `eval'.
-rw-r--r--lisp/calendar/cal-dst.el89
1 files changed, 46 insertions, 43 deletions
diff --git a/lisp/calendar/cal-dst.el b/lisp/calendar/cal-dst.el
index 301dc29c56a..6b55ea479f1 100644
--- a/lisp/calendar/cal-dst.el
+++ b/lisp/calendar/cal-dst.el
@@ -1,4 +1,4 @@
1;;; cal-dst.el --- calendar functions for daylight saving rules 1;;; cal-dst.el --- calendar functions for daylight saving rules -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 1993-1996, 2001-2017 Free Software Foundation, Inc. 3;; Copyright (C) 1993-1996, 2001-2017 Free Software Foundation, Inc.
4 4
@@ -220,29 +220,30 @@ The result has the proper form for `calendar-daylight-savings-starts'."
220 '((calendar-gregorian-from-absolute 220 '((calendar-gregorian-from-absolute
221 (calendar-persian-to-absolute `(7 1 ,(- year 621)))))))) 221 (calendar-persian-to-absolute `(7 1 ,(- year 621))))))))
222 (prevday-sec (- -1 utc-diff)) ; last sec of previous local day 222 (prevday-sec (- -1 utc-diff)) ; last sec of previous local day
223 (year (1+ y))
224 new-rules) 223 new-rules)
225 ;; Scan through the next few years until only one rule remains. 224 (calendar-dlet* ((year (1+ y)))
226 (while (cdr candidate-rules) 225 ;; Scan through the next few years until only one rule remains.
227 (dolist (rule candidate-rules) 226 (while (cdr candidate-rules)
228 ;; The rule we return should give a Gregorian date, but here 227 (dolist (rule candidate-rules)
229 ;; we require an absolute date. The following is for efficiency. 228 ;; The rule we return should give a Gregorian date, but here
230 (setq date (cond ((eq (car rule) 'calendar-nth-named-day) 229 ;; we require an absolute date. The following is for efficiency.
231 (eval (cons 'calendar-nth-named-absday (cdr rule)))) 230 (setq date (cond ((eq (car rule) #'calendar-nth-named-day)
232 ((eq (car rule) 'calendar-gregorian-from-absolute) 231 (eval (cons #'calendar-nth-named-absday
233 (eval (cadr rule))) 232 (cdr rule))))
234 (t (calendar-absolute-from-gregorian (eval rule))))) 233 ((eq (car rule) #'calendar-gregorian-from-absolute)
235 (or (equal (current-time-zone 234 (eval (cadr rule)))
236 (calendar-time-from-absolute date prevday-sec)) 235 (t (calendar-absolute-from-gregorian (eval rule)))))
237 (current-time-zone 236 (or (equal (current-time-zone
238 (calendar-time-from-absolute (1+ date) prevday-sec))) 237 (calendar-time-from-absolute date prevday-sec))
239 (setq new-rules (cons rule new-rules)))) 238 (current-time-zone
240 ;; If no rules remain, just use the first candidate rule; 239 (calendar-time-from-absolute (1+ date) prevday-sec)))
241 ;; it's wrong in general, but it's right for at least one year. 240 (setq new-rules (cons rule new-rules))))
242 (setq candidate-rules (if new-rules (nreverse new-rules) 241 ;; If no rules remain, just use the first candidate rule;
243 (list (car candidate-rules))) 242 ;; it's wrong in general, but it's right for at least one year.
244 new-rules nil 243 (setq candidate-rules (if new-rules (nreverse new-rules)
245 year (1+ year))) 244 (list (car candidate-rules)))
245 new-rules nil
246 year (1+ year))))
246 (car candidate-rules))) 247 (car candidate-rules)))
247 248
248;; TODO it might be better to extract this information directly from 249;; TODO it might be better to extract this information directly from
@@ -405,7 +406,8 @@ This function respects the value of `calendar-dst-check-each-year-flag'."
405 (or (let ((expr (if calendar-dst-check-each-year-flag 406 (or (let ((expr (if calendar-dst-check-each-year-flag
406 (cadr (calendar-dst-find-startend year)) 407 (cadr (calendar-dst-find-startend year))
407 (nth 4 calendar-current-time-zone-cache)))) 408 (nth 4 calendar-current-time-zone-cache))))
408 (if expr (eval expr))) 409 (calendar-dlet* ((year year))
410 (if expr (eval expr))))
409 ;; New US rules commencing 2007. https://www.iana.org/time-zones 411 ;; New US rules commencing 2007. https://www.iana.org/time-zones
410 (and (not (zerop calendar-daylight-time-offset)) 412 (and (not (zerop calendar-daylight-time-offset))
411 (calendar-nth-named-day 2 0 3 year)))) 413 (calendar-nth-named-day 2 0 3 year))))
@@ -416,7 +418,8 @@ This function respects the value of `calendar-dst-check-each-year-flag'."
416 (or (let ((expr (if calendar-dst-check-each-year-flag 418 (or (let ((expr (if calendar-dst-check-each-year-flag
417 (nth 2 (calendar-dst-find-startend year)) 419 (nth 2 (calendar-dst-find-startend year))
418 (nth 5 calendar-current-time-zone-cache)))) 420 (nth 5 calendar-current-time-zone-cache))))
419 (if expr (eval expr))) 421 (calendar-dlet* ((year year))
422 (if expr (eval expr))))
420 ;; New US rules commencing 2007. https://www.iana.org/time-zones 423 ;; New US rules commencing 2007. https://www.iana.org/time-zones
421 (and (not (zerop calendar-daylight-time-offset)) 424 (and (not (zerop calendar-daylight-time-offset))
422 (calendar-nth-named-day 1 0 11 year)))) 425 (calendar-nth-named-day 1 0 11 year))))
@@ -425,25 +428,25 @@ This function respects the value of `calendar-dst-check-each-year-flag'."
425(defun dst-in-effect (date) 428(defun dst-in-effect (date)
426 "True if on absolute DATE daylight saving time is in effect. 429 "True if on absolute DATE daylight saving time is in effect.
427Fractional part of DATE is local standard time of day." 430Fractional part of DATE is local standard time of day."
428 (let* ((year (calendar-extract-year 431 (calendar-dlet* ((year (calendar-extract-year
429 (calendar-gregorian-from-absolute (floor date)))) 432 (calendar-gregorian-from-absolute (floor date)))))
430 (dst-starts-gregorian (eval calendar-daylight-savings-starts)) 433 (let* ((dst-starts-gregorian (eval calendar-daylight-savings-starts))
431 (dst-ends-gregorian (eval calendar-daylight-savings-ends)) 434 (dst-ends-gregorian (eval calendar-daylight-savings-ends))
432 (dst-starts (and dst-starts-gregorian 435 (dst-starts (and dst-starts-gregorian
436 (+ (calendar-absolute-from-gregorian
437 dst-starts-gregorian)
438 (/ calendar-daylight-savings-starts-time
439 60.0 24.0))))
440 (dst-ends (and dst-ends-gregorian
433 (+ (calendar-absolute-from-gregorian 441 (+ (calendar-absolute-from-gregorian
434 dst-starts-gregorian) 442 dst-ends-gregorian)
435 (/ calendar-daylight-savings-starts-time 443 (/ (- calendar-daylight-savings-ends-time
436 60.0 24.0)))) 444 calendar-daylight-time-offset)
437 (dst-ends (and dst-ends-gregorian 445 60.0 24.0)))))
438 (+ (calendar-absolute-from-gregorian 446 (and dst-starts dst-ends
439 dst-ends-gregorian) 447 (if (< dst-starts dst-ends)
440 (/ (- calendar-daylight-savings-ends-time 448 (and (<= dst-starts date) (< date dst-ends))
441 calendar-daylight-time-offset) 449 (or (<= dst-starts date) (< date dst-ends)))))))
442 60.0 24.0)))))
443 (and dst-starts dst-ends
444 (if (< dst-starts dst-ends)
445 (and (<= dst-starts date) (< date dst-ends))
446 (or (<= dst-starts date) (< date dst-ends))))))
447 450
448;; used by calc, lunar, solar. 451;; used by calc, lunar, solar.
449(defun dst-adjust-time (date time) 452(defun dst-adjust-time (date time)