aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-07-24 07:42:23 +0000
committerRichard M. Stallman1997-07-24 07:42:23 +0000
commitae58b7adfb6a5063b1b674f0c655f5772296c48d (patch)
treeb2bda21aacb3c64d82bc275fbbea1678a0e81a05
parent471faf6cf3f983b18aa296df8bbb1d1e175933d4 (diff)
downloademacs-ae58b7adfb6a5063b1b674f0c655f5772296c48d.tar.gz
emacs-ae58b7adfb6a5063b1b674f0c655f5772296c48d.zip
(calendar-day-name): New optional args WIDTH, ABSOLUTE.
(calendar-month-name): New optional arg WIDTH. (generate-calendar-month, calendar-date-string): Pass new args instead of using substring here.
-rw-r--r--lisp/calendar/calendar.el49
1 files changed, 35 insertions, 14 deletions
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 838987378f3..5ea0d145ea9 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1783,9 +1783,8 @@ characters on the line."
1783 indent t) 1783 indent t)
1784 (calendar-insert-indented "" indent);; Go to proper spot 1784 (calendar-insert-indented "" indent);; Go to proper spot
1785 (calendar-for-loop i from 0 to 6 do 1785 (calendar-for-loop i from 0 to 6 do
1786 (insert (substring (aref calendar-day-name-array 1786 (insert (calendar-day-name (mod (+ calendar-week-start-day i) 7)
1787 (mod (+ calendar-week-start-day i) 7)) 1787 2 t))
1788 0 2))
1789 (insert " ")) 1788 (insert " "))
1790 (calendar-insert-indented "" 0 t);; Force onto following line 1789 (calendar-insert-indented "" 0 t);; Force onto following line
1791 (calendar-insert-indented "" indent);; Go to proper spot 1790 (calendar-insert-indented "" indent);; Go to proper spot
@@ -2263,8 +2262,8 @@ is a string to insert in the minibuffer before reading."
2263(defun calendar-read-date (&optional noday) 2262(defun calendar-read-date (&optional noday)
2264 "Prompt for Gregorian date. Returns a list (month day year). 2263 "Prompt for Gregorian date. Returns a list (month day year).
2265If optional NODAY is t, does not ask for day, but just returns 2264If optional NODAY is t, does not ask for day, but just returns
2266(month nil year); if NODAY is any other non-nil value the value returned is 2265\(month nil year); if NODAY is any other non-nil value the value returned is
2267(month year) " 2266\(month year) "
2268 (let* ((year (calendar-read 2267 (let* ((year (calendar-read
2269 "Year (>0): " 2268 "Year (>0): "
2270 '(lambda (x) (> x 0)) 2269 '(lambda (x) (> x 0))
@@ -2294,9 +2293,22 @@ If optional NODAY is t, does not ask for day, but just returns
2294 (+ (* 12 (- yr2 yr1)) 2293 (+ (* 12 (- yr2 yr1))
2295 (- mon2 mon1))) 2294 (- mon2 mon1)))
2296 2295
2297(defun calendar-day-name (date) 2296(defun calendar-day-name (date &optional width absolute)
2298 "Returns a string with the name of the day of the week of DATE." 2297 "Returns a string with the name of the day of the week of DATE.
2299 (aref calendar-day-name-array (calendar-day-of-week date))) 2298If WIDTH is non-nil, return just the first WIDTH characters of the name.
2299If ABSOLUTE is non-nil, then DATE is actual the day-of-the-week
2300rather than a date."
2301 (let ((string (aref calendar-day-name-array
2302 (if absolute date (calendar-day-of-week date)))))
2303 (if width
2304 (let ((i 0) (result "") (pos 0))
2305 (while (< i width)
2306 (let ((chartext (char-to-string (sref string pos))))
2307 (setq pos (+ pos (length chartext)))
2308 (setq result (concat result chartext)))
2309 (setq i (1+ i)))
2310 result)
2311 string)))
2300 2312
2301(defvar calendar-day-name-array 2313(defvar calendar-day-name-array
2302 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]) 2314 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
@@ -2317,9 +2329,19 @@ If FILTER is provided, apply it to each item in the list."
2317 index)) 2329 index))
2318 (append sequence nil)))) 2330 (append sequence nil))))
2319 2331
2320(defun calendar-month-name (month) 2332(defun calendar-month-name (month &optional width)
2321 "The name of MONTH." 2333 "The name of MONTH.
2322 (aref calendar-month-name-array (1- month))) 2334If WIDTH is non-nil, return just the first WIDTH characters of the name."
2335 (let ((string (aref calendar-month-name-array (1- month))))
2336 (if width
2337 (let ((i 0) (result "") (pos 0))
2338 (while (< i width)
2339 (let ((chartext (char-to-string (sref string pos))))
2340 (setq pos (+ pos (length chartext)))
2341 (setq result (concat result chartext)))
2342 (setq i (1+ i)))
2343 result)
2344 string)))
2323 2345
2324(defun calendar-day-of-week (date) 2346(defun calendar-day-of-week (date)
2325 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc." 2347 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
@@ -2412,13 +2434,12 @@ omits the name of the day of the week."
2412 (if nodayname 2434 (if nodayname
2413 nil 2435 nil
2414 (if abbreviate 2436 (if abbreviate
2415 (substring (calendar-day-name date) 0 3) 2437 (calendar-day-name date 3)
2416 (calendar-day-name date)))) 2438 (calendar-day-name date))))
2417 (month (extract-calendar-month date)) 2439 (month (extract-calendar-month date))
2418 (monthname 2440 (monthname
2419 (if abbreviate 2441 (if abbreviate
2420 (substring 2442 (calendar-month-name month 3)
2421 (calendar-month-name month) 0 3)
2422 (calendar-month-name month))) 2443 (calendar-month-name month)))
2423 (day (int-to-string (extract-calendar-day date))) 2444 (day (int-to-string (extract-calendar-day date)))
2424 (month (int-to-string month)) 2445 (month (int-to-string month))