Mercurial > emacs
comparison lisp/calendar/calendar.el @ 3778:747d54c5e139
* 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.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 16 Jun 1993 23:10:55 +0000 |
parents | 507f64624555 |
children | 2c6883d0a1b2 |
comparison
equal
deleted
inserted
replaced
3777:d6f56b9586f7 | 3778:747d54c5e139 |
---|---|
478 "*An expression that evaluates to the name of the location at | 478 "*An expression that evaluates to the name of the location at |
479 `calendar-longitude', calendar-latitude'. Default value is just the latitude, | 479 `calendar-longitude', calendar-latitude'. Default value is just the latitude, |
480 longitude pair.") | 480 longitude 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. |
484 This returns a list of the form (OFFSET SAVINGS-FLAG STANDARD SAVINGS). | 484 |
485 This list is calculated from a heuristic that is usually correct; | 485 Returns a list of the form (UTC-DIFF DST-OFFSET STD-ZONE DST-ZONE), based on |
486 to get more reliable results, use current-time-zone. | 486 a heuristic probing of what the system knows: |
487 OFFSET is an integer specifying how many minutes east of Greenwich the | 487 |
488 current time zone is located. A negative value means west of | 488 UTC-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. |
491 SAVINGS-FLAG is non-nil iff daylight savings time or some other sort | 491 DST-OFFSET is an integer giving the daylight savings time offset in minutes. |
492 of seasonal time adjustment is ever in effect. | 492 STD-ZONE is a string giving the name of the time zone when no seasonal time |
493 STANDARD is a string giving the name of the time zone when no seasonal | 493 adjustment is in effect. |
494 time adjustment is in effect. | 494 DST-ZONE is a string giving the name of the time zone when there is a seasonal |
495 SAVINGS 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 |
497 If the local area does not use a seasonal time adjustment, | 497 If the local area does not use a seasonal time adjustment, OFFSET is 0, and |
498 SAVINGS-FLAG is always nil, and STANDARD and SAVINGS are equal. | 498 STD-ZONE and DST-ZONE are equal. |
499 | 499 |
500 Some operating systems cannot provide all this information to Emacs; | 500 Some operating systems cannot provide all this information to Emacs; in this |
501 in this case, `calendar-current-time-zone' returns a list containing nil for | 501 case, `calendar-current-time-zone' returns a list containing nil for the data |
502 the data it can't find." | 502 it 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 |
543 for New York City, -480 for Los Angeles. | 539 example, -300 for New York City, -480 for Los Angeles.") |
544 | 540 |
545 If 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))) |
546 package 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. | 543 between daylight savings time and standard time. |
548 (or calendar-time-zone | 544 |
549 (setq calendar-time-zone (car (calendar-current-time-zone)))) | 545 Should be set to 0 if locale has no daylight savings time.") |
550 | 546 |
551 ;;;###autoload | 547 (defvar calendar-standard-time-zone-name |
552 (defvar calendar-standard-time-zone-name nil | 548 (car (nthcdr 2 (calendar-current-time-zone))) |
553 "*Abbreviated name of standard time zone at `calendar-location-name'. | 549 "*Abbreviated name of standard time zone at `calendar-location-name'. |
554 For example, \"EST\" in New York City, \"PST\" for Los Angeles. | 550 For example, \"EST\" in New York City, \"PST\" for Los Angeles.") |
555 | 551 |
556 If this is nil, it will be set for the local time zone when the calendar | 552 (defvar calendar-daylight-time-zone-name |
557 package loads.") | 553 (car (nthcdr 3 (calendar-current-time-zone))) |
558 ;;; If the user has given this a value, don't wipe it out. | |
559 (or calendar-standard-time-zone-name | |
560 (setq calendar-standard-time-zone-name | |
561 (car (nthcdr 2 (calendar-current-time-zone))))) | |
562 | |
563 ;;;###autoload | |
564 (defvar calendar-daylight-time-zone-name nil | |
565 "*Abbreviated name of daylight-savings time zone at `calendar-location-name'. | 554 "*Abbreviated name of daylight-savings time zone at `calendar-location-name'. |
566 For example, \"EDT\" in New York City, \"PDT\" for Los Angeles. | 555 For example, \"EDT\" in New York City, \"PDT\" for Los Angeles.") |
567 | |
568 If this is nil, it will be set for the local time zone when the calendar | |
569 package 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 |
578 of a list (month day year), on which daylight savings time starts. This is | 561 of a list (month day year), on which daylight savings time starts. This is |
579 used to determine the starting date of daylight savings time for the holiday | 562 used to determine the starting date of daylight savings time for the holiday |
580 list and for correcting times of day in the solar and lunar calculations. | 563 list and for correcting times of day in the solar and lunar calculations. |
581 | 564 |
592 (calendar-absolute-from-hebrew | 575 (calendar-absolute-from-hebrew |
593 (list 1 1 (+ year 3760)))) | 576 (list 1 1 (+ year 3760)))) |
594 | 577 |
595 because Nisan is the first month in the Hebrew calendar. | 578 because Nisan is the first month in the Hebrew calendar. |
596 | 579 |
597 If this is nil and the locale ever uses daylight savings time, | 580 If the locale never uses daylight savings time, set this to nil.") |
598 it will be set to the American rule of the first Sunday in April | 581 |
599 when the calendar package loads.") | 582 (defvar calendar-daylight-savings-ends |
600 ;;; If the user has given this a value, don't wipe it out. | 583 (if (not (eq calendar-daylight-time-offset 0)) |
601 (or calendar-daylight-savings-starts | 584 '(calendar-nth-named-day -1 0 10 year)) |
602 (setq calendar-daylight-savings-starts | |
603 (and (car (cdr (calendar-current-time-zone))) | |
604 '(calendar-nth-named-day 1 0 4 year)))) | |
605 | |
606 ;;;###autoload | |
607 (defvar calendar-daylight-savings-ends nil | |
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 |
609 form of a list (month day year), on which daylight savings time ends. This | 586 form of a list (month day year), on which daylight savings time ends. This |
610 is used to determine the ending date of daylight savings time for the holiday | 587 is used to determine the ending date of daylight savings time for the holiday |
611 list and for correcting times of day in the solar and lunar calculations. | 588 list and for correcting times of day in the solar and lunar calculations. |
612 The default value is the American rule of the last Sunday in October | 589 |
613 if the locale ever uses daylight savings time, otherwise nil. | 590 The default value is the American rule of the last Sunday in October, |
591 | |
592 If the locale never uses daylight savings time, set this to nil. | |
593 | |
614 See the documentation for `calendar-daylight-savings-starts' for other | 594 See the documentation for `calendar-daylight-savings-starts' for other |
615 examples.") | 595 examples.") |
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))) | 599 midnight 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." |
624 (interactive) | 603 (interactive) |
625 (setq european-calendar-style t) | 604 (setq european-calendar-style t) |
902 "*Sun-related holidays. | 881 "*Sun-related holidays. |
903 See the documentation for `calendar-holidays' for details.") | 882 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 |
912 Additional holidays are easy to add to the list, just put them in the list | 891 Additional holidays are easy to add to the list, just put them in the list |
913 `other-holidays' in your .emacs file. Similarly, by setting any of | 892 `other-holidays' in your .emacs file. Similarly, by setting any of |
914 `general-holidays', `local-holidays' `christian-holidays', `hebrew-holidays', | 893 `general-holidays', `local-holidays' `christian-holidays', `hebrew-holidays', |
1757 \\[calendar-phases-of-moon] show times of quarters of the moon | 1736 \\[calendar-phases-of-moon] show times of quarters of the moon |
1758 | 1737 |
1759 The times given will be at latitude `solar-latitude', longitude | 1738 The 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 |
1761 variables `solar-location-name', `solar-standard-time-zone-name', | 1740 variables `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', |
1743 and `calendar-daylight-savings-switchover-time' should be set for | |
1744 your location. | |
1764 | 1745 |
1765 To exit from the calendar use | 1746 To exit from the calendar use |
1766 | 1747 |
1767 \\[exit-calendar] exit from calendar | 1748 \\[exit-calendar] exit from calendar |
1768 | 1749 |
3100 (defun calendar-print-astro-day-number () | 3081 (defun calendar-print-astro-day-number () |
3101 "Show the astronomical (Julian) day number of afternoon on date | 3082 "Show the astronomical (Julian) day number of afternoon on date |
3102 shown by cursor." | 3083 shown 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) |
3109 (error "Cursor is not on a date!")))))) | 3090 (error "Cursor is not on a date!")))))) |
3110 | 3091 |