diff options
| author | Edward M. Reingold | 1995-09-21 02:54:58 +0000 |
|---|---|---|
| committer | Edward M. Reingold | 1995-09-21 02:54:58 +0000 |
| commit | ec23095166a703272c2f8fe21efaaef368399e98 (patch) | |
| tree | 5834636b14fff0508c031529f719c68eb0320afd | |
| parent | 9fadf1a53e244575dc7e7013b2efdb680a9f2dec (diff) | |
| download | emacs-ec23095166a703272c2f8fe21efaaef368399e98.tar.gz emacs-ec23095166a703272c2f8fe21efaaef368399e98.zip | |
Minor fixes; moved some code here from other calendar files.
| -rw-r--r-- | lisp/calendar/cal-dst.el | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/lisp/calendar/cal-dst.el b/lisp/calendar/cal-dst.el index f48a9feb1d9..598af905d99 100644 --- a/lisp/calendar/cal-dst.el +++ b/lisp/calendar/cal-dst.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; cal-dst.el --- calendar functions for daylight savings rules. | 1 | ;;; cal-dst.el --- calendar functions for daylight savings rules. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Paul Eggert <eggert@twinsun.com> | 5 | ;; Author: Paul Eggert <eggert@twinsun.com> |
| 6 | ;; Edward M. Reingold <reingold@cs.uiuc.edu> | 6 | ;; Edward M. Reingold <reingold@cs.uiuc.edu> |
| @@ -250,7 +250,7 @@ it can't find." | |||
| 250 | (list t1-name t0-name t2-rules t1-rules t2-time t1-time) | 250 | (list t1-name t0-name t2-rules t1-rules t2-time t1-time) |
| 251 | ))))))))))) | 251 | ))))))))))) |
| 252 | 252 | ||
| 253 | ;;; The following six defvars relating to daylight savings time should NOT be | 253 | ;;; The following eight defvars relating to daylight savings time should NOT be |
| 254 | ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is | 254 | ;;; marked to go into loaddefs.el where they would be evaluated when Emacs is |
| 255 | ;;; dumped. These variables' appropriate values depend on the conditions under | 255 | ;;; dumped. These variables' appropriate values depend on the conditions under |
| 256 | ;;; which the code is INVOKED; so it's inappropriate to initialize them when | 256 | ;;; which the code is INVOKED; so it's inappropriate to initialize them when |
| @@ -330,6 +330,58 @@ If the locale never uses daylight savings time, set this to nil.") | |||
| 330 | calendar-daylight-savings-starts-time) | 330 | calendar-daylight-savings-starts-time) |
| 331 | "*Number of minutes after midnight that daylight savings time ends.") | 331 | "*Number of minutes after midnight that daylight savings time ends.") |
| 332 | 332 | ||
| 333 | (defun dst-in-effect (date) | ||
| 334 | "True if on absolute DATE daylight savings time is in effect. | ||
| 335 | Fractional part of DATE is time of day." | ||
| 336 | (let* ((year (extract-calendar-year | ||
| 337 | (calendar-gregorian-from-absolute (floor date)))) | ||
| 338 | (dst-starts (and (eval calendar-daylight-savings-starts) | ||
| 339 | (+ (calendar-absolute-from-gregorian | ||
| 340 | (eval calendar-daylight-savings-starts)) | ||
| 341 | (/ calendar-daylight-savings-starts-time | ||
| 342 | 60.0 24.0)))) | ||
| 343 | (dst-ends (and (eval calendar-daylight-savings-ends) | ||
| 344 | (+ (calendar-absolute-from-gregorian | ||
| 345 | (eval calendar-daylight-savings-ends)) | ||
| 346 | (/ (- calendar-daylight-savings-ends-time | ||
| 347 | calendar-daylight-time-offset) | ||
| 348 | 60.0 24.0))))) | ||
| 349 | (and (and dst-starts dst-ends | ||
| 350 | (or (and (< dst-starts dst-ends);; northern hemi. | ||
| 351 | (<= dst-starts date) (< date dst-ends)) | ||
| 352 | (and (< dst-ends dst-starts);; southern hemi. | ||
| 353 | (<= dst-starts date) (< date dst-ends)) | ||
| 354 | (and dst-starts (not dst-ends) (<= dst-starts date)) | ||
| 355 | (and dst-ends (not dst-starts) (< date dst-ends))))))) | ||
| 356 | |||
| 357 | (defun dst-adjust-time (date time &optional style) | ||
| 358 | "Adjust, to account for dst on DATE, decimal fraction standard TIME. | ||
| 359 | Returns a list (date adj-time zone) where `date' and `adj-time' are the values | ||
| 360 | adjusted for `zone'; here `date' is a list (month day year), `adj-time' is a | ||
| 361 | decimal fraction time, and `zone' is a string. | ||
| 362 | |||
| 363 | Optional parameter STYLE forces the result time to be standard time when its | ||
| 364 | value is 'standard and daylight savings time (if available) when its value is | ||
| 365 | 'daylight. | ||
| 366 | |||
| 367 | Conversion to daylight savings time is done according to | ||
| 368 | `calendar-daylight-savings-starts', `calendar-daylight-savings-ends', | ||
| 369 | `calendar-daylight-savings-starts-time', | ||
| 370 | `calendar-daylight-savings-ends-time', and | ||
| 371 | `calendar-daylight-savings-offset'." | ||
| 372 | |||
| 373 | (let* ((rounded-abs-date (+ (calendar-absolute-from-gregorian date) | ||
| 374 | (/ (round (* 60 time)) 60.0 24.0))) | ||
| 375 | (dst (dst-in-effect rounded-abs-date)) | ||
| 376 | (time-zone (if dst | ||
| 377 | calendar-daylight-time-zone-name | ||
| 378 | calendar-standard-time-zone-name)) | ||
| 379 | (time (+ rounded-abs-date | ||
| 380 | (if dst (/ calendar-daylight-time-offset 24.0 60.0) 0)))) | ||
| 381 | (list (calendar-gregorian-from-absolute (truncate time)) | ||
| 382 | (* 24.0 (- time (truncate time))) | ||
| 383 | time-zone))) | ||
| 384 | |||
| 333 | (provide 'cal-dst) | 385 | (provide 'cal-dst) |
| 334 | 386 | ||
| 335 | ;;; cal-dst.el ends here | 387 | ;;; cal-dst.el ends here |