aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/calendar/calendar.el99
1 files changed, 55 insertions, 44 deletions
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 1b10ff55db6..906def77f90 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -752,7 +752,7 @@ See the documentation for `calendar-holidays' for details.")
752 '(format "Daylight Savings Time Begins %s" 752 '(format "Daylight Savings Time Begins %s"
753 (if (fboundp 'atan) 753 (if (fboundp 'atan)
754 (solar-time-string 754 (solar-time-string
755 (/ calendar-daylight-savings-switchover-time 755 (/ calendar-daylight-savings-starts-time
756 (float 60)) 756 (float 60))
757 date 757 date
758 'standard) 758 'standard)
@@ -763,7 +763,7 @@ See the documentation for `calendar-holidays' for details.")
763 '(format "Daylight Savings Time Ends %s" 763 '(format "Daylight Savings Time Ends %s"
764 (if (fboundp 'atan) 764 (if (fboundp 'atan)
765 (solar-time-string 765 (solar-time-string
766 (/ (- calendar-daylight-savings-switchover-time 766 (/ (- calendar-daylight-savings-ends-time
767 calendar-daylight-time-offset) 767 calendar-daylight-time-offset)
768 (float 60)) 768 (float 60))
769 date 769 date
@@ -978,13 +978,13 @@ Forward if N is positive or backward if N is negative."
978(defmacro calendar-last-day-of-month (month year) 978(defmacro calendar-last-day-of-month (month year)
979 "The last day in MONTH during YEAR." 979 "The last day in MONTH during YEAR."
980 (` (if (and 980 (` (if (and
981 (, (macroexpand (` (calendar-leap-year-p (, year))))) 981 (= (, month) 2)
982 (= (, month) 2)) 982 (, (macroexpand (` (calendar-leap-year-p (, year))))))
983 29 983 29
984 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- (, month)))))) 984 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- (, month))))))
985;;(defun calendar-last-day-of-month (month year) 985;;(defun calendar-last-day-of-month (month year)
986;; "The last day in MONTH during YEAR." 986;; "The last day in MONTH during YEAR."
987;; (if (and (calendar-leap-year-p year) (= month 2)) 987;; (if (and (= month 2) (calendar-leap-year-p year))
988;; 29 988;; 29
989;; (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month)))) 989;; (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
990 990
@@ -1024,21 +1024,22 @@ while (calendar-day-number '(12 31 1980)) returns 366."
1024(defmacro calendar-absolute-from-gregorian (date) 1024(defmacro calendar-absolute-from-gregorian (date)
1025 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. 1025 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
1026The Gregorian date Sunday, December 31, 1 BC is imaginary." 1026The Gregorian date Sunday, December 31, 1 BC is imaginary."
1027 (` (let ((year (, (macroexpand (` (extract-calendar-year (, date))))))) 1027 (` (let ((prior-years
1028 (1- (, (macroexpand (` (extract-calendar-year (, date))))))))
1028 (+ (, (macroexpand (` (calendar-day-number (, date)))));; Days this year 1029 (+ (, (macroexpand (` (calendar-day-number (, date)))));; Days this year
1029 (* 365 (1- year));; + Days in prior years 1030 (* 365 prior-years);; + Days in prior years
1030 (/ (1- year) 4);; + Julian leap years 1031 (/ prior-years 4);; + Julian leap years
1031 (- (/ (1- year) 100));; - century years 1032 (- (/ prior-years 100));; - century years
1032 (/ (1- year) 400)))));; + Gregorian leap years 1033 (/ prior-years 400)))));; + Gregorian leap years
1033;;(defun calendar-absolute-from-gregorian (date) 1034;;(defun calendar-absolute-from-gregorian (date)
1034;; "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. 1035;; "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
1035;;The Gregorian date Sunday, December 31, 1 BC is imaginary." 1036;;The Gregorian date Sunday, December 31, 1 BC is imaginary."
1036;; (let ((year (extract-calendar-year date))) 1037;; (let ((prior-years (1- (extract-calendar-year date))))
1037;; (+ (calendar-day-number date);; Days this year 1038;; (+ (calendar-day-number date);; Days this year
1038;; (* 365 (1- year));; + Days in prior years 1039;; (* 365 prior-years);; + Days in prior years
1039;; (/ (1- year) 4);; + Julian leap years 1040;; (/ prior-years 4);; + Julian leap years
1040;; (- (/ (1- year) 100));; - century years 1041;; (- (/ prior-years 100));; - century years
1041;; (/ (1- year) 400))));; + Gregorian leap years 1042;; (/ prior-years 400))));; + Gregorian leap years
1042 1043
1043;;;###autoload 1044;;;###autoload
1044(defun calendar (&optional arg) 1045(defun calendar (&optional arg)
@@ -1493,19 +1494,19 @@ the inserted text. Value is always t."
1493 1494
1494The commands for cursor movement are:\\<calendar-mode-map> 1495The commands for cursor movement are:\\<calendar-mode-map>
1495 1496
1496 \\[calendar-forward-day] one day forward \\[calendar-backward-day] one day backward 1497 \\[calendar-forward-day] one day forward \\[calendar-backward-day] one day backward
1497 \\[calendar-forward-week] one week forward \\[calendar-backward-week] one week backward 1498 \\[calendar-forward-week] one week forward \\[calendar-backward-week] one week backward
1498 \\[calendar-forward-month] one month forward \\[calendar-backward-month] one month backward 1499 \\[calendar-forward-month] one month forward \\[calendar-backward-month] one month backward
1499 \\[calendar-forward-year] one year forward \\[calendar-backward-year] one year backward 1500 \\[calendar-forward-year] one year forward \\[calendar-backward-year] one year backward
1500 \\[calendar-beginning-of-week] beginning of week \\[calendar-end-of-week] end of week 1501 \\[calendar-beginning-of-week] beginning of week \\[calendar-end-of-week] end of week
1501 \\[calendar-beginning-of-month] beginning of month \\[calendar-end-of-month] end of month 1502 \\[calendar-beginning-of-month] beginning of month \\[calendar-end-of-month] end of month
1502 \\[calendar-beginning-of-year] beginning of year \\[calendar-end-of-year] end of year 1503 \\[calendar-beginning-of-year] beginning of year \\[calendar-end-of-year] end of year
1503 1504
1504 \\[calendar-goto-date] go to date 1505 \\[calendar-goto-date] go to date
1505 1506
1506 \\[calendar-goto-julian-date] go to Julian date \\[calendar-goto-astro-day-number] go to astronomical (Julian) day number 1507 \\[calendar-goto-julian-date] go to Julian date \\[calendar-goto-astro-day-number] go to astronomical (Julian) day number
1507 \\[calendar-goto-hebrew-date] go to Hebrew date \\[calendar-goto-islamic-date] go to Islamic date 1508 \\[calendar-goto-hebrew-date] go to Hebrew date \\[calendar-goto-islamic-date] go to Islamic date
1508 \\[calendar-goto-iso-date] go to ISO date \\[calendar-goto-french-date] go to French Revolutionary date 1509 \\[calendar-goto-iso-date] go to ISO date \\[calendar-goto-french-date] go to French Revolutionary date
1509 1510
1510 \\[calendar-goto-mayan-long-count-date] go to Mayan Long Count date 1511 \\[calendar-goto-mayan-long-count-date] go to Mayan Long Count date
1511 \\[calendar-next-haab-date] go to next occurrence of Mayan Haab date 1512 \\[calendar-next-haab-date] go to next occurrence of Mayan Haab date
@@ -1525,9 +1526,9 @@ You can determine the number of days (inclusive) between the point and mark by
1525 1526
1526The commands for calendar movement are: 1527The commands for calendar movement are:
1527 1528
1528 \\[scroll-calendar-right] scroll one month right \\[scroll-calendar-left] scroll one month left 1529 \\[scroll-calendar-right] scroll one month right \\[scroll-calendar-left] scroll one month left
1529 \\[scroll-calendar-right-three-months] scroll 3 months right \\[scroll-calendar-left-three-months] scroll 3 months left 1530 \\[scroll-calendar-right-three-months] scroll 3 months right \\[scroll-calendar-left-three-months] scroll 3 months left
1530 \\[calendar-current-month] display current month \\[calendar-other-month] display another month 1531 \\[calendar-current-month] display current month \\[calendar-other-month] display another month
1531 1532
1532Whenever it makes sense, the above commands take prefix arguments that 1533Whenever it makes sense, the above commands take prefix arguments that
1533multiply their affect. For convenience, the digit keys and the minus sign 1534multiply their affect. For convenience, the digit keys and the minus sign
@@ -1636,13 +1637,14 @@ To find the times of sunrise and sunset and lunar phases use
1636 \\[calendar-sunrise-sunset] show times of sunrise and sunset 1637 \\[calendar-sunrise-sunset] show times of sunrise and sunset
1637 \\[calendar-phases-of-moon] show times of quarters of the moon 1638 \\[calendar-phases-of-moon] show times of quarters of the moon
1638 1639
1639The times given will be at latitude `solar-latitude', longitude 1640The times given will be for location `calendar-location-name' at latitude
1640`solar-longitude' in time zone `solar-time-zone'. These variables, and the 1641`calendar-latitude', longitude `calendar-longitude'; set these variables for
1641variables `solar-location-name', `solar-standard-time-zone-name', 1642your location. The following variables are also consulted, and you must set
1642`solar-daylight-time-zone-name', `solar-daylight-savings-starts', 1643them if your system does not initialize them properly: `calendar-time-zone',
1643`solar-daylight-savings-ends', `calendar-daylight-time-offset', 1644`calendar-daylight-time-offset', `calendar-standard-time-zone-name',
1644and `calendar-daylight-savings-switchover-time' should be set for 1645`calendar-daylight-time-zone-name', `calendar-daylight-savings-starts',
1645your location. 1646`calendar-daylight-savings-ends', `calendar-daylight-savings-starts-time',
1647`calendar-daylight-savings-ends-time'.
1646 1648
1647To exit from the calendar use 1649To exit from the calendar use
1648 1650
@@ -2549,6 +2551,27 @@ absolute date d, applying it to d-1 gives the DAYNAME previous to absolute
2549date d, and applying it to d+7 gives the DAYNAME following absolute date d." 2551date d, and applying it to d+7 gives the DAYNAME following absolute date d."
2550 (- date (% (- date dayname) 7))) 2552 (- date (% (- date dayname) 7)))
2551 2553
2554(defun calendar-nth-named-absday (n dayname month year &optional day)
2555 "The absolute date of Nth DAYNAME in MONTH, YEAR before/after optional DAY.
2556A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0,
2557return the Nth DAYNAME before MONTH DAY, YEAR (inclusive).
2558If N>0, return the Nth DAYNAME after MONTH DAY, YEAR (inclusive).
2559
2560If DAY is omitted, it defaults to 1 if N>0, and MONTH's last day otherwise."
2561 (if (> n 0)
2562 (+ (* 7 (1- n))
2563 (calendar-dayname-on-or-before
2564 dayname
2565 (+ 6 (calendar-absolute-from-gregorian
2566 (list month (or day 1) year)))))
2567 (+ (* 7 (1+ n))
2568 (calendar-dayname-on-or-before
2569 dayname
2570 (calendar-absolute-from-gregorian
2571 (list month
2572 (or day (calendar-last-day-of-month month year))
2573 year))))))
2574
2552(defun calendar-nth-named-day (n dayname month year &optional day) 2575(defun calendar-nth-named-day (n dayname month year &optional day)
2553 "The date of Nth DAYNAME in MONTH, YEAR before/after optional DAY. 2576 "The date of Nth DAYNAME in MONTH, YEAR before/after optional DAY.
2554A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0, 2577A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0,
@@ -2557,19 +2580,7 @@ If N>0, return the Nth DAYNAME after MONTH DAY, YEAR (inclusive).
2557 2580
2558If DAY is omitted, it defaults to 1 if N>0, and MONTH's last day otherwise." 2581If DAY is omitted, it defaults to 1 if N>0, and MONTH's last day otherwise."
2559 (calendar-gregorian-from-absolute 2582 (calendar-gregorian-from-absolute
2560 (if (> n 0) 2583 (calendar-nth-named-absday n dayname month year day)))
2561 (+ (* 7 (1- n))
2562 (calendar-dayname-on-or-before
2563 dayname
2564 (+ 6 (calendar-absolute-from-gregorian
2565 (list month (or day 1) year)))))
2566 (+ (* 7 (1+ n))
2567 (calendar-dayname-on-or-before
2568 dayname
2569 (calendar-absolute-from-gregorian
2570 (list month
2571 (or day (calendar-last-day-of-month month year))
2572 year)))))))
2573 2584
2574(defun calendar-print-day-of-year () 2585(defun calendar-print-day-of-year ()
2575 "Show the day number in the year and the number of days remaining in the 2586 "Show the day number in the year and the number of days remaining in the