aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Blandy1993-06-16 23:10:55 +0000
committerJim Blandy1993-06-16 23:10:55 +0000
commit23195d9408256b6a9cef2158d042e0859d24b004 (patch)
treef07b1e99520706c929beaf4f10bd9702ab8f6451
parent327ab40d47792886b103b6462d01a97aba3cb886 (diff)
downloademacs-23195d9408256b6a9cef2158d042e0859d24b004.tar.gz
emacs-23195d9408256b6a9cef2158d042e0859d24b004.zip
* calendar.el (calendar-current-time-zone): Change variable names
to make them more readable. (calendar-time-zone, calendar-standard-time-zone-name, calendar-daylight-time-zone-name, calendar-daylight-savings-ends, calendar-daylight-savings-starts): Don't autload them. * calendar.el (calendar-holidays): Quote it to delay evaluation until it's needed.
-rw-r--r--lisp/calendar/calendar.el197
1 files changed, 89 insertions, 108 deletions
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 5efe24fe296..1b2c4fe8bb0 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -480,100 +480,83 @@ For example, -74.0 for New York City.")
480longitude pair.") 480longitude pair.")
481 481
482(defun calendar-current-time-zone () 482(defun calendar-current-time-zone ()
483 "Return the offset, savings state, and names for the current time zone. 483 "Return the UTC difference, dst offset, and names for the current time zone.
484This returns a list of the form (OFFSET SAVINGS-FLAG STANDARD SAVINGS). 484
485This list is calculated from a heuristic that is usually correct; 485Returns a list of the form (UTC-DIFF DST-OFFSET STD-ZONE DST-ZONE), based on
486to get more reliable results, use current-time-zone. 486a heuristic probing of what the system knows:
487OFFSET is an integer specifying how many minutes east of Greenwich the 487
488 current time zone is located. A negative value means west of 488UTC-DIFF is an integer specifying the number of minutes difference between
489 Greenwich. This describes the standard time; if daylight 489 standard time in the current time zone and Coordinated Universal Time
490 savings time is in effect, it does not affect this value. 490 (Greenwich Mean Time). A negative value means west of Greenwich.
491SAVINGS-FLAG is non-nil iff daylight savings time or some other sort 491DST-OFFSET is an integer giving the daylight savings time offset in minutes.
492 of seasonal time adjustment is ever in effect. 492STD-ZONE is a string giving the name of the time zone when no seasonal time
493STANDARD is a string giving the name of the time zone when no seasonal 493 adjustment is in effect.
494 time adjustment is in effect. 494DST-ZONE is a string giving the name of the time zone when there is a seasonal
495SAVINGS is a string giving the name of the time zone when there is a 495 time adjustment in effect.
496 seasonal time adjustment in effect. 496
497If the local area does not use a seasonal time adjustment, 497If the local area does not use a seasonal time adjustment, OFFSET is 0, and
498SAVINGS-FLAG is always nil, and STANDARD and SAVINGS are equal. 498STD-ZONE and DST-ZONE are equal.
499 499
500Some operating systems cannot provide all this information to Emacs; 500Some operating systems cannot provide all this information to Emacs; in this
501in this case, `calendar-current-time-zone' returns a list containing nil for 501case, `calendar-current-time-zone' returns a list containing nil for the data
502the data it can't find." 502it can't find."
503 (let* ((quarter-year-seconds 7889238.0) ; # number of seconds in 1/4 year 503 (let* ((now (current-time))
504 (current-time-arithmetic-base 65536.0) 504 (now-zone (current-time-zone now))
505 (now (current-time)) 505 (now-utc-diff (car now-zone))
506 (now-zone (current-time-zone now)) 506 (now-name (car (cdr now-zone)))
507 (now-offset (car now-zone)) 507 probe-zone
508 (now-name (car (cdr now-zone))) 508 (probe-utc-diff now-utc-diff)
509 probe-zone 509 (i 1))
510 (probe-offset now-offset)
511 (i 0))
512 ;; Heuristic: probe the time zone offset in the next three calendar 510 ;; Heuristic: probe the time zone offset in the next three calendar
513 ;; quarters, looking for a time zone offset different from now. 511 ;; quarters, looking for a time zone offset different from now.
514 (while (and (< i 4) (eq now-offset probe-offset)) 512 ;; There about 120 * 2^16 seconds in a quarter year
515 (let ((probe 513 (while (and (< i 4) (eq now-utc-diff probe-utc-diff))
516 (list (+ (car now) (round (/ (* i quarter-year-seconds) 514 (setq probe-zone (current-time-zone (list (+ (car now) (* i 120)) 0)))
517 current-time-arithmetic-base))) 515 (setq probe-utc-diff (car probe-zone))
518 0 0))) 516 (setq i (1+ i)))
519 (setq probe-zone (current-time-zone probe)) 517 (if (or (eq now-utc-diff probe-utc-diff)
520 (setq probe-offset (car probe-zone)) 518 (not now-utc-diff)
521 (setq i (1+ i)))) 519 (not probe-utc-diff))
522 (if (or (eq now-offset probe-offset) (not now-offset) (not probe-offset)) 520 ;; No change found
523 (list (and now-offset (/ now-offset 60)) nil now-name now-name) 521 (list (and now-utc-diff (/ now-utc-diff 60)) 0 now-name now-name)
524 (let ((std-offset (min now-offset probe-offset)) 522 ;; Found a different utc-diff
525 (probe-name (car (cdr probe-zone)))) 523 (let ((utc-diff (min now-utc-diff probe-utc-diff))
526 (list (/ std-offset 60) 524 (probe-name (car (cdr probe-zone))))
527 t 525 (list (/ utc-diff 60)
528 (if (eq std-offset now-offset) now-name probe-name) 526 (/ (abs (- now-utc-diff probe-utc-diff)) 60)
529 (if (eq std-offset now-offset) probe-name now-name)))))) 527 (if (eq utc-diff now-utc-diff) now-name probe-name)
530 528 (if (eq utc-diff now-utc-diff) probe-name now-name))))))
531;;; Since the following three defvars are marked to go into 529
532;;; loaddefs.el, they will be evaluated when Emacs is dumped. 530;;; The following six defvars relating to daylight savings time should NOT be
533;;; However, these variables' appropriate values really depend on the 531;;; marked to go into loaddefs.el where they would be evaluated when Emacs is
534;;; conditions under which the code is invoked; so it's inappropriate 532;;; dumped. These variables' appropriate values really on the conditions under
535;;; to initialize them when Emacs is dumped. Thus we initialize them 533;;; which the code is INVOKED; so it's inappropriate to initialize them when
536;;; to nil now, and if they are still nil when this file is actually 534;;; Emacs is dumped---they should be initialized when calendar.el is loaded.
537;;; loaded, we give them their real values then. 535
538 536(defvar calendar-time-zone (car (calendar-current-time-zone))
539;;;###autoload
540(defvar calendar-time-zone nil
541 "*Number of minutes difference between local standard time at 537 "*Number of minutes difference between local standard time at
542`calendar-location-name' and Universal (Greenwich) Time. For example, -300 538`calendar-location-name' and Coordinated Universal (Greenwich) Time. For
543for New York City, -480 for Los Angeles. 539example, -300 for New York City, -480 for Los Angeles.")
544 540
545If this is nil, it will be set to the local time zone when the calendar 541(defvar calendar-daylight-time-offset (car (cdr (calendar-current-time-zone)))
546package loads.") 542 "*A sexp in the variable `year' that gives the number of minutes difference
547;;; If the user has given this a real value, don't wipe it out. 543between daylight savings time and standard time.
548(or calendar-time-zone
549 (setq calendar-time-zone (car (calendar-current-time-zone))))
550 544
551;;;###autoload 545Should be set to 0 if locale has no daylight savings time.")
552(defvar calendar-standard-time-zone-name nil
553 "*Abbreviated name of standard time zone at `calendar-location-name'.
554For example, \"EST\" in New York City, \"PST\" for Los Angeles.
555 546
556If this is nil, it will be set for the local time zone when the calendar 547(defvar calendar-standard-time-zone-name
557package loads.") 548 (car (nthcdr 2 (calendar-current-time-zone)))
558;;; If the user has given this a value, don't wipe it out. 549 "*Abbreviated name of standard time zone at `calendar-location-name'.
559(or calendar-standard-time-zone-name 550For example, \"EST\" in New York City, \"PST\" for Los Angeles.")
560 (setq calendar-standard-time-zone-name
561 (car (nthcdr 2 (calendar-current-time-zone)))))
562 551
563;;;###autoload 552(defvar calendar-daylight-time-zone-name
564(defvar calendar-daylight-time-zone-name nil 553 (car (nthcdr 3 (calendar-current-time-zone)))
565 "*Abbreviated name of daylight-savings time zone at `calendar-location-name'. 554 "*Abbreviated name of daylight-savings time zone at `calendar-location-name'.
566For example, \"EDT\" in New York City, \"PDT\" for Los Angeles. 555For example, \"EDT\" in New York City, \"PDT\" for Los Angeles.")
567
568If this is nil, it will be set for the local time zone when the calendar
569package loads.")
570;;; If the user has given this a value, don't wipe it out.
571(or calendar-daylight-time-zone-name
572 (setq calendar-daylight-time-zone-name
573 (car (nthcdr 3 (calendar-current-time-zone)))))
574 556
575;;;###autoload 557(defvar calendar-daylight-savings-starts
576(defvar calendar-daylight-savings-starts nil 558 (if (not (eq calendar-daylight-time-offset 0))
559 '(calendar-nth-named-day 1 0 4 year))
577 "*A sexp in the variable `year' that gives the Gregorian date, in the form 560 "*A sexp in the variable `year' that gives the Gregorian date, in the form
578of a list (month day year), on which daylight savings time starts. This is 561of a list (month day year), on which daylight savings time starts. This is
579used to determine the starting date of daylight savings time for the holiday 562used to determine the starting date of daylight savings time for the holiday
@@ -594,30 +577,26 @@ to
594 577
595because Nisan is the first month in the Hebrew calendar. 578because Nisan is the first month in the Hebrew calendar.
596 579
597If this is nil and the locale ever uses daylight savings time, 580If the locale never uses daylight savings time, set this to nil.")
598it will be set to the American rule of the first Sunday in April
599when the calendar package loads.")
600;;; If the user has given this a value, don't wipe it out.
601(or calendar-daylight-savings-starts
602 (setq calendar-daylight-savings-starts
603 (and (car (cdr (calendar-current-time-zone)))
604 '(calendar-nth-named-day 1 0 4 year))))
605 581
606;;;###autoload 582(defvar calendar-daylight-savings-ends
607(defvar calendar-daylight-savings-ends nil 583 (if (not (eq calendar-daylight-time-offset 0))
584 '(calendar-nth-named-day -1 0 10 year))
608 "*An expression in the variable `year' that gives the Gregorian date, in the 585 "*An expression in the variable `year' that gives the Gregorian date, in the
609form of a list (month day year), on which daylight savings time ends. This 586form of a list (month day year), on which daylight savings time ends. This
610is used to determine the ending date of daylight savings time for the holiday 587is used to determine the ending date of daylight savings time for the holiday
611list and for correcting times of day in the solar and lunar calculations. 588list and for correcting times of day in the solar and lunar calculations.
612The default value is the American rule of the last Sunday in October 589
613if the locale ever uses daylight savings time, otherwise nil. 590The default value is the American rule of the last Sunday in October,
591
592If the locale never uses daylight savings time, set this to nil.
593
614See the documentation for `calendar-daylight-savings-starts' for other 594See the documentation for `calendar-daylight-savings-starts' for other
615examples.") 595examples.")
616;;; If the user has given this a value, don't wipe it out. 596
617(or calendar-daylight-savings-ends 597(defvar calendar-daylight-savings-switchover-time 120
618 (setq calendar-daylight-savings-ends 598 "*A sexp in the variable `year' that gives the number of minutes after
619 (and (car (cdr (calendar-current-time-zone))) 599midnight that daylight savings time begins and ends.")
620 '(calendar-nth-named-day -1 0 10 year))))
621 600
622(defun european-calendar () 601(defun european-calendar ()
623 "Set the interpretation and display of dates to the European style." 602 "Set the interpretation and display of dates to the European style."
@@ -904,9 +883,9 @@ See the documentation for `calendar-holidays' for details.")
904 883
905;;;###autoload 884;;;###autoload
906(defvar calendar-holidays 885(defvar calendar-holidays
907 (append general-holidays local-holidays other-holidays 886 '(append general-holidays local-holidays other-holidays
908 christian-holidays hebrew-holidays islamic-holidays 887 christian-holidays hebrew-holidays islamic-holidays
909 solar-holidays) 888 solar-holidays)
910 "*List of notable days for the command M-x holidays. 889 "*List of notable days for the command M-x holidays.
911 890
912Additional holidays are easy to add to the list, just put them in the list 891Additional holidays are easy to add to the list, just put them in the list
@@ -1759,8 +1738,10 @@ To find the times of sunrise and sunset and lunar phases use
1759The times given will be at latitude `solar-latitude', longitude 1738The times given will be at latitude `solar-latitude', longitude
1760`solar-longitude' in time zone `solar-time-zone'. These variables, and the 1739`solar-longitude' in time zone `solar-time-zone'. These variables, and the
1761variables `solar-location-name', `solar-standard-time-zone-name', 1740variables `solar-location-name', `solar-standard-time-zone-name',
1762`solar-daylight-time-zone-name', `solar-daylight-savings-starts', and 1741`solar-daylight-time-zone-name', `solar-daylight-savings-starts',
1763`solar-daylight-savings-ends', should be set for your location. 1742`solar-daylight-savings-ends', `calendar-daylight-time-offset',
1743and `calendar-daylight-savings-switchover-time' should be set for
1744your location.
1764 1745
1765To exit from the calendar use 1746To exit from the calendar use
1766 1747
@@ -3102,7 +3083,7 @@ the date of death is taken from the cursor position."
3102shown by cursor." 3083shown by cursor."
3103 (interactive) 3084 (interactive)
3104 (message 3085 (message
3105 "Astronomical (Julian) day number after noon Universal Time: %d" 3086 "Astronomical (Julian) day number after noon UTC: %d"
3106 (+ 1721425 3087 (+ 1721425
3107 (calendar-absolute-from-gregorian 3088 (calendar-absolute-from-gregorian
3108 (or (calendar-cursor-to-date) 3089 (or (calendar-cursor-to-date)