comparison lisp/calendar/cal-dst.el @ 76476:3878691bdbb7

Change "daylight savings time" -> "daylight saving time" throughout.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 17 Mar 2007 17:49:59 +0000
parents 7a3f13e2dd57
children c56fcbc72ab0 c0409ee15cee
comparison
equal deleted inserted replaced
76475:321e7fa1c51d 76476:3878691bdbb7
1 ;;; cal-dst.el --- calendar functions for daylight savings rules 1 ;;; cal-dst.el --- calendar functions for daylight saving rules
2 2
3 ;; Copyright (C) 1993, 1994, 1995, 1996, 2001, 2002, 2003, 2004, 2005, 3 ;; Copyright (C) 1993, 1994, 1995, 1996, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc. 4 ;; 2006, 2007 Free Software Foundation, Inc.
5 5
6 ;; Author: Paul Eggert <eggert@twinsun.com> 6 ;; Author: Paul Eggert <eggert@twinsun.com>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu> 7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org> 8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
9 ;; Keywords: calendar 9 ;; Keywords: calendar
10 ;; Human-Keywords: daylight savings time, calendar, diary, holidays 10 ;; Human-Keywords: daylight saving time, calendar, diary, holidays
11 11
12 ;; This file is part of GNU Emacs. 12 ;; This file is part of GNU Emacs.
13 13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify 14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by 15 ;; it under the terms of the GNU General Public License as published by
27 ;; Boston, MA 02110-1301, USA. 27 ;; Boston, MA 02110-1301, USA.
28 28
29 ;;; Commentary: 29 ;;; Commentary:
30 30
31 ;; This collection of functions implements the features of calendar.el and 31 ;; This collection of functions implements the features of calendar.el and
32 ;; holiday.el that deal with daylight savings time. 32 ;; holiday.el that deal with daylight saving time.
33 33
34 ;; Comments, corrections, and improvements should be sent to 34 ;; Comments, corrections, and improvements should be sent to
35 ;; Edward M. Reingold Department of Computer Science 35 ;; Edward M. Reingold Department of Computer Science
36 ;; (217) 333-6733 University of Illinois at Urbana-Champaign 36 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
37 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue 37 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
44 44
45 (defcustom calendar-dst-check-each-year-flag t 45 (defcustom calendar-dst-check-each-year-flag t
46 "Non-nil means to check each year for DST transitions as needed. 46 "Non-nil means to check each year for DST transitions as needed.
47 Otherwise assume the next two transitions found after the 47 Otherwise assume the next two transitions found after the
48 current date apply to all years. This is faster, but not always 48 current date apply to all years. This is faster, but not always
49 correct, since the dates of Daylight Saving transitions sometimes 49 correct, since the dates of daylight saving transitions sometimes
50 change." 50 change."
51 :type 'boolean 51 :type 'boolean
52 :version "22.1" 52 :version "22.1"
53 :group 'calendar) 53 :group 'calendar)
54 54
140 (setq lo probe))) 140 (setq lo probe)))
141 hi)))) 141 hi))))
142 142
143 (defun calendar-time-zone-daylight-rules (abs-date utc-diff) 143 (defun calendar-time-zone-daylight-rules (abs-date utc-diff)
144 "Return daylight transition rule for ABS-DATE, UTC-DIFF sec offset from UTC. 144 "Return daylight transition rule for ABS-DATE, UTC-DIFF sec offset from UTC.
145 ABS-DATE must specify a day that contains a daylight savings transition. 145 ABS-DATE must specify a day that contains a daylight saving transition.
146 The result has the proper form for calendar-daylight-savings-starts'." 146 The result has the proper form for `calendar-daylight-savings-starts'."
147 (let* ((date (calendar-gregorian-from-absolute abs-date)) 147 (let* ((date (calendar-gregorian-from-absolute abs-date))
148 (weekday (% abs-date 7)) 148 (weekday (% abs-date 7))
149 (m (extract-calendar-month date)) 149 (m (extract-calendar-month date))
150 (d (extract-calendar-day date)) 150 (d (extract-calendar-day date))
151 (y (extract-calendar-year date)) 151 (y (extract-calendar-year date))
213 ;; TODO it might be better to extract this information directly from 213 ;; TODO it might be better to extract this information directly from
214 ;; the system timezone database. But cross-platform...? 214 ;; the system timezone database. But cross-platform...?
215 ;; See thread 215 ;; See thread
216 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2006-11/msg00060.html 216 ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2006-11/msg00060.html
217 (defun calendar-dst-find-data (&optional time) 217 (defun calendar-dst-find-data (&optional time)
218 "Find data on the first Daylight Saving Time transitions after TIME. 218 "Find data on the first daylight saving time transitions after TIME.
219 TIME defaults to `current-time'. Return value is as described 219 TIME defaults to `current-time'. Return value is as described
220 for `calendar-current-time-zone'." 220 for `calendar-current-time-zone'."
221 (let* ((t0 (or time (current-time))) 221 (let* ((t0 (or time (current-time)))
222 (t0-zone (current-time-zone t0)) 222 (t0-zone (current-time-zone t0))
223 (t0-utc-diff (car t0-zone)) 223 (t0-utc-diff (car t0-zone))
226 ;; Little or no time zone information is available. 226 ;; Little or no time zone information is available.
227 (list nil nil t0-name t0-name nil nil nil nil) 227 (list nil nil t0-name t0-name nil nil nil nil)
228 (let* ((t1 (calendar-next-time-zone-transition t0)) 228 (let* ((t1 (calendar-next-time-zone-transition t0))
229 (t2 (and t1 (calendar-next-time-zone-transition t1)))) 229 (t2 (and t1 (calendar-next-time-zone-transition t1))))
230 (if (not t2) 230 (if (not t2)
231 ;; This locale does not have daylight savings time. 231 ;; This locale does not have daylight saving time.
232 (list (/ t0-utc-diff 60) 0 t0-name t0-name nil nil 0 0) 232 (list (/ t0-utc-diff 60) 0 t0-name t0-name nil nil 0 0)
233 ;; Use heuristics to find daylight savings parameters. 233 ;; Use heuristics to find daylight saving parameters.
234 (let* ((t1-zone (current-time-zone t1)) 234 (let* ((t1-zone (current-time-zone t1))
235 (t1-utc-diff (car t1-zone)) 235 (t1-utc-diff (car t1-zone))
236 (t1-name (car (cdr t1-zone))) 236 (t1-name (car (cdr t1-zone)))
237 (t1-date-sec (calendar-absolute-from-time t1 t0-utc-diff)) 237 (t1-date-sec (calendar-absolute-from-time t1 t0-utc-diff))
238 (t2-date-sec (calendar-absolute-from-time t2 t1-utc-diff)) 238 (t2-date-sec (calendar-absolute-from-time t2 t1-utc-diff))
252 (list t0-name t1-name t1-rules t2-rules t1-time t2-time) 252 (list t0-name t1-name t1-rules t2-rules t1-time t2-time)
253 (list t1-name t0-name t2-rules t1-rules t2-time t1-time) 253 (list t1-name t0-name t2-rules t1-rules t2-time t1-time)
254 ))))))))) 254 )))))))))
255 255
256 (defvar calendar-dst-transition-cache nil 256 (defvar calendar-dst-transition-cache nil
257 "Internal cal-dst variable storing date of Daylight Saving Time transitions. 257 "Internal cal-dst variable storing date of daylight saving time transitions.
258 Value is a list with elements of the form (YEAR START END), where 258 Value is a list with elements of the form (YEAR START END), where
259 START and END are expressions that when evaluated return the 259 START and END are expressions that when evaluated return the
260 start and end dates (respectively) for DST in YEAR. Used by the 260 start and end dates (respectively) for DST in YEAR. Used by the
261 function `calendar-dst-find-startend'.") 261 function `calendar-dst-find-startend'.")
262 262
263 (defun calendar-dst-find-startend (year) 263 (defun calendar-dst-find-startend (year)
264 "Find the dates in YEAR on which Daylight Saving Time starts and ends. 264 "Find the dates in YEAR on which daylight saving time starts and ends.
265 Returns a list (YEAR START END), where START and END are 265 Returns a list (YEAR START END), where START and END are
266 expressions that when evaluated return the start and end dates, 266 expressions that when evaluated return the start and end dates,
267 respectively. This function first attempts to use pre-calculated 267 respectively. This function first attempts to use pre-calculated
268 data from `calendar-dst-transition-cache', otherwise it calls 268 data from `calendar-dst-transition-cache', otherwise it calls
269 `calendar-dst-find-data' (and adds the results to the cache)." 269 `calendar-dst-find-data' (and adds the results to the cache)."
286 system knows: 286 system knows:
287 287
288 UTC-DIFF is an integer specifying the number of minutes difference between 288 UTC-DIFF is an integer specifying the number of minutes difference between
289 standard time in the current time zone and Coordinated Universal Time 289 standard time in the current time zone and Coordinated Universal Time
290 (Greenwich Mean Time). A negative value means west of Greenwich. 290 (Greenwich Mean Time). A negative value means west of Greenwich.
291 DST-OFFSET is an integer giving the daylight savings time offset in minutes. 291 DST-OFFSET is an integer giving the daylight saving time offset in minutes.
292 STD-ZONE is a string giving the name of the time zone when no seasonal time 292 STD-ZONE is a string giving the name of the time zone when no seasonal time
293 adjustment is in effect. 293 adjustment is in effect.
294 DST-ZONE is a string giving the name of the time zone when there is a seasonal 294 DST-ZONE is a string giving the name of the time zone when there is a seasonal
295 time adjustment in effect. 295 time adjustment in effect.
296 DST-STARTS and DST-ENDS are sexps in the variable `year' giving the daylight 296 DST-STARTS and DST-ENDS are sexps in the variable `year' giving the daylight
297 savings time start and end rules, in the form expected by 297 saving time start and end rules, in the form expected by
298 `calendar-daylight-savings-starts'. 298 `calendar-daylight-savings-starts'.
299 DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes 299 DST-STARTS-TIME and DST-ENDS-TIME are integers giving the number of minutes
300 after midnight that daylight savings time starts and ends. 300 after midnight that daylight saving time starts and ends.
301 301
302 If the local area does not use a seasonal time adjustment, STD-ZONE and 302 If the local area does not use a seasonal time adjustment, STD-ZONE and
303 DST-ZONE are equal, and all the DST-* integer variables are 0. 303 DST-ZONE are equal, and all the DST-* integer variables are 0.
304 304
305 Some operating systems cannot provide all this information to Emacs; in this 305 Some operating systems cannot provide all this information to Emacs; in this
306 case, `calendar-current-time-zone' returns a list containing nil for the data 306 case, `calendar-current-time-zone' returns a list containing nil for the data
307 it can't find." 307 it can't find."
308 (unless calendar-current-time-zone-cache 308 (unless calendar-current-time-zone-cache
309 (setq calendar-current-time-zone-cache (calendar-dst-find-data)))) 309 (setq calendar-current-time-zone-cache (calendar-dst-find-data))))
310 310
311 ;;; The following eight defvars relating to daylight savings time should NOT be 311 ;;; The following eight defvars relating to daylight saving time should NOT be
312 ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is 312 ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is
313 ;;; dumped. These variables' appropriate values depend on the conditions under 313 ;;; dumped. These variables' appropriate values depend on the conditions under
314 ;;; which the code is INVOKED; so it's inappropriate to initialize them when 314 ;;; which the code is INVOKED; so it's inappropriate to initialize them when
315 ;;; Emacs is dumped---they should be initialized when calendar.el is loaded. 315 ;;; Emacs is dumped---they should be initialized when calendar.el is loaded.
316 ;;; They default to US Eastern time if time zone info is not available. 316 ;;; They default to US Eastern time if time zone info is not available.
322 `calendar-location-name' and Coordinated Universal (Greenwich) Time. For 322 `calendar-location-name' and Coordinated Universal (Greenwich) Time. For
323 example, -300 for New York City, -480 for Los Angeles.") 323 example, -300 for New York City, -480 for Los Angeles.")
324 324
325 (defvar calendar-daylight-time-offset 325 (defvar calendar-daylight-time-offset
326 (or (car (cdr calendar-current-time-zone-cache)) 60) 326 (or (car (cdr calendar-current-time-zone-cache)) 60)
327 "*Number of minutes difference between daylight savings and standard time. 327 "*Number of minutes difference between daylight saving and standard time.
328 328
329 If the locale never uses daylight savings time, set this to 0.") 329 If the locale never uses daylight saving time, set this to 0.")
330 330
331 (defvar calendar-standard-time-zone-name 331 (defvar calendar-standard-time-zone-name
332 (or (car (nthcdr 2 calendar-current-time-zone-cache)) "EST") 332 (or (car (nthcdr 2 calendar-current-time-zone-cache)) "EST")
333 "*Abbreviated name of standard time zone at `calendar-location-name'. 333 "*Abbreviated name of standard time zone at `calendar-location-name'.
334 For example, \"EST\" in New York City, \"PST\" for Los Angeles.") 334 For example, \"EST\" in New York City, \"PST\" for Los Angeles.")
335 335
336 (defvar calendar-daylight-time-zone-name 336 (defvar calendar-daylight-time-zone-name
337 (or (car (nthcdr 3 calendar-current-time-zone-cache)) "EDT") 337 (or (car (nthcdr 3 calendar-current-time-zone-cache)) "EDT")
338 "*Abbreviated name of daylight-savings time zone at `calendar-location-name'. 338 "*Abbreviated name of daylight saving time zone at `calendar-location-name'.
339 For example, \"EDT\" in New York City, \"PDT\" for Los Angeles.") 339 For example, \"EDT\" in New York City, \"PDT\" for Los Angeles.")
340 340
341 341
342 (defun calendar-dst-starts (year) 342 (defun calendar-dst-starts (year)
343 "Return the date of YEAR on which Daylight Saving Time starts. 343 "Return the date of YEAR on which daylight saving time starts.
344 This function respects the value of `calendar-dst-check-each-year-flag'." 344 This function respects the value of `calendar-dst-check-each-year-flag'."
345 (or (let ((expr (if calendar-dst-check-each-year-flag 345 (or (let ((expr (if calendar-dst-check-each-year-flag
346 (cadr (calendar-dst-find-startend year)) 346 (cadr (calendar-dst-find-startend year))
347 (nth 4 calendar-current-time-zone-cache)))) 347 (nth 4 calendar-current-time-zone-cache))))
348 (if expr (eval expr))) 348 (if expr (eval expr)))
349 ;; New US rules commencing 2007. ftp://elsie.nci.nih.gov/pub/. 349 ;; New US rules commencing 2007. ftp://elsie.nci.nih.gov/pub/.
350 (and (not (zerop calendar-daylight-time-offset)) 350 (and (not (zerop calendar-daylight-time-offset))
351 (calendar-nth-named-day 2 0 3 year)))) 351 (calendar-nth-named-day 2 0 3 year))))
352 352
353 (defun calendar-dst-ends (year) 353 (defun calendar-dst-ends (year)
354 "Return the date of YEAR on which Daylight Saving Time ends. 354 "Return the date of YEAR on which daylight saving time ends.
355 This function respects the value of `calendar-dst-check-each-year-flag'." 355 This function respects the value of `calendar-dst-check-each-year-flag'."
356 (or (let ((expr (if calendar-dst-check-each-year-flag 356 (or (let ((expr (if calendar-dst-check-each-year-flag
357 (nth 2 (calendar-dst-find-startend year)) 357 (nth 2 (calendar-dst-find-startend year))
358 (nth 5 calendar-current-time-zone-cache)))) 358 (nth 5 calendar-current-time-zone-cache))))
359 (if expr (eval expr))) 359 (if expr (eval expr)))
364 364
365 ;;;###autoload 365 ;;;###autoload
366 (put 'calendar-daylight-savings-starts 'risky-local-variable t) 366 (put 'calendar-daylight-savings-starts 'risky-local-variable t)
367 (defvar calendar-daylight-savings-starts 367 (defvar calendar-daylight-savings-starts
368 '(calendar-dst-starts year) 368 '(calendar-dst-starts year)
369 "*Sexp giving the date on which daylight savings time starts. 369 "*Sexp giving the date on which daylight saving time starts.
370 This is an expression in the variable `year' whose value gives the Gregorian 370 This is an expression in the variable `year' whose value gives the Gregorian
371 date in the form (month day year) on which daylight savings time starts. It is 371 date in the form (month day year) on which daylight saving time starts. It is
372 used to determine the starting date of daylight savings time for the holiday 372 used to determine the starting date of daylight saving time for the holiday
373 list and for correcting times of day in the solar and lunar calculations. 373 list and for correcting times of day in the solar and lunar calculations.
374 374
375 For example, if daylight savings time is mandated to start on October 1, 375 For example, if daylight saving time is mandated to start on October 1,
376 you would set `calendar-daylight-savings-starts' to 376 you would set `calendar-daylight-savings-starts' to
377 377
378 '(10 1 year) 378 '(10 1 year)
379 379
380 If it starts on the first Sunday in April, you would set it to 380 If it starts on the first Sunday in April, you would set it to
381 381
382 '(calendar-nth-named-day 1 0 4 year) 382 '(calendar-nth-named-day 1 0 4 year)
383 383
384 If the locale never uses daylight savings time, set this to nil.") 384 If the locale never uses daylight saving time, set this to nil.")
385 385
386 ;;;###autoload 386 ;;;###autoload
387 (put 'calendar-daylight-savings-ends 'risky-local-variable t) 387 (put 'calendar-daylight-savings-ends 'risky-local-variable t)
388 (defvar calendar-daylight-savings-ends 388 (defvar calendar-daylight-savings-ends
389 '(calendar-dst-ends year) 389 '(calendar-dst-ends year)
390 "*Sexp giving the date on which daylight savings time ends. 390 "*Sexp giving the date on which daylight saving time ends.
391 This is an expression in the variable `year' whose value gives the Gregorian 391 This is an expression in the variable `year' whose value gives the Gregorian
392 date in the form (month day year) on which daylight savings time ends. It is 392 date in the form (month day year) on which daylight saving time ends. It is
393 used to determine the starting date of daylight savings time for the holiday 393 used to determine the starting date of daylight saving time for the holiday
394 list and for correcting times of day in the solar and lunar calculations. 394 list and for correcting times of day in the solar and lunar calculations.
395 395
396 For example, if daylight savings time ends on the last Sunday in October: 396 For example, if daylight saving time ends on the last Sunday in October:
397 397
398 '(calendar-nth-named-day -1 0 10 year) 398 '(calendar-nth-named-day -1 0 10 year)
399 399
400 If the locale never uses daylight savings time, set this to nil.") 400 If the locale never uses daylight saving time, set this to nil.")
401 401
402 (defvar calendar-daylight-savings-starts-time 402 (defvar calendar-daylight-savings-starts-time
403 (or (car (nthcdr 6 calendar-current-time-zone-cache)) 120) 403 (or (car (nthcdr 6 calendar-current-time-zone-cache)) 120)
404 "*Number of minutes after midnight that daylight savings time starts.") 404 "*Number of minutes after midnight that daylight saving time starts.")
405 405
406 (defvar calendar-daylight-savings-ends-time 406 (defvar calendar-daylight-savings-ends-time
407 (or (car (nthcdr 7 calendar-current-time-zone-cache)) 407 (or (car (nthcdr 7 calendar-current-time-zone-cache))
408 calendar-daylight-savings-starts-time) 408 calendar-daylight-savings-starts-time)
409 "*Number of minutes after midnight that daylight savings time ends.") 409 "*Number of minutes after midnight that daylight saving time ends.")
410 410
411 (defun dst-in-effect (date) 411 (defun dst-in-effect (date)
412 "True if on absolute DATE daylight savings time is in effect. 412 "True if on absolute DATE daylight saving time is in effect.
413 Fractional part of DATE is local standard time of day." 413 Fractional part of DATE is local standard time of day."
414 (let* ((year (extract-calendar-year 414 (let* ((year (extract-calendar-year
415 (calendar-gregorian-from-absolute (floor date)))) 415 (calendar-gregorian-from-absolute (floor date))))
416 (dst-starts-gregorian (eval calendar-daylight-savings-starts)) 416 (dst-starts-gregorian (eval calendar-daylight-savings-starts))
417 (dst-ends-gregorian (eval calendar-daylight-savings-ends)) 417 (dst-ends-gregorian (eval calendar-daylight-savings-ends))
436 Returns a list (date adj-time zone) where `date' and `adj-time' are the values 436 Returns a list (date adj-time zone) where `date' and `adj-time' are the values
437 adjusted for `zone'; here `date' is a list (month day year), `adj-time' is a 437 adjusted for `zone'; here `date' is a list (month day year), `adj-time' is a
438 decimal fraction time, and `zone' is a string. 438 decimal fraction time, and `zone' is a string.
439 439
440 Optional parameter STYLE forces the result time to be standard time when its 440 Optional parameter STYLE forces the result time to be standard time when its
441 value is 'standard and daylight savings time (if available) when its value is 441 value is 'standard and daylight saving time (if available) when its value is
442 'daylight. 442 'daylight.
443 443
444 Conversion to daylight savings time is done according to 444 Conversion to daylight saving time is done according to
445 `calendar-daylight-savings-starts', `calendar-daylight-savings-ends', 445 `calendar-daylight-savings-starts', `calendar-daylight-savings-ends',
446 `calendar-daylight-savings-starts-time', 446 `calendar-daylight-savings-starts-time',
447 `calendar-daylight-savings-ends-time', and 447 `calendar-daylight-savings-ends-time', and
448 `calendar-daylight-savings-offset'." 448 `calendar-daylight-savings-offset'."
449 449