changeset 18940:953dfe84b101

(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.
author Richard M. Stallman <rms@gnu.org>
date Thu, 24 Jul 1997 07:42:23 +0000
parents 7415a69ea66e
children 3fcfe59102ac
files lisp/calendar/calendar.el
diffstat 1 files changed, 35 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calendar/calendar.el	Thu Jul 24 07:42:07 1997 +0000
+++ b/lisp/calendar/calendar.el	Thu Jul 24 07:42:23 1997 +0000
@@ -1783,9 +1783,8 @@
     indent t)
    (calendar-insert-indented "" indent);; Go to proper spot
    (calendar-for-loop i from 0 to 6 do
-      (insert (substring (aref calendar-day-name-array 
-                               (mod (+ calendar-week-start-day i) 7))
-                         0 2))
+      (insert (calendar-day-name (mod (+ calendar-week-start-day i) 7)
+				 2 t))
       (insert " "))
    (calendar-insert-indented "" 0 t);; Force onto following line
    (calendar-insert-indented "" indent);; Go to proper spot
@@ -2263,8 +2262,8 @@
 (defun calendar-read-date (&optional noday)
   "Prompt for Gregorian date.  Returns a list (month day year).
 If optional NODAY is t, does not ask for day, but just returns
-(month nil year); if NODAY is any other non-nil value the value returned is
-(month year) "
+\(month nil year); if NODAY is any other non-nil value the value returned is
+\(month year) "
   (let* ((year (calendar-read
                 "Year (>0): "
                 '(lambda (x) (> x 0))
@@ -2294,9 +2293,22 @@
   (+ (* 12 (- yr2 yr1))
      (- mon2 mon1)))
 
-(defun calendar-day-name (date)
-  "Returns a string with the name of the day of the week of DATE."
-  (aref calendar-day-name-array (calendar-day-of-week date)))
+(defun calendar-day-name (date &optional width absolute)
+  "Returns a string with the name of the day of the week of DATE.
+If WIDTH is non-nil, return just the first WIDTH characters of the name.
+If ABSOLUTE is non-nil, then DATE is actual the day-of-the-week
+rather than a date."
+  (let ((string (aref calendar-day-name-array
+		      (if absolute date (calendar-day-of-week date)))))
+    (if width
+	(let ((i 0) (result "") (pos 0))
+	  (while (< i width)
+	    (let ((chartext (char-to-string (sref string pos))))
+	      (setq pos (+ pos (length chartext)))
+	      (setq result (concat result chartext)))
+	    (setq i (1+ i)))
+	  result)
+      string)))
 
 (defvar calendar-day-name-array
   ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
@@ -2317,9 +2329,19 @@
               index))
      (append sequence nil))))
 
-(defun calendar-month-name (month)
-  "The name of MONTH."
-  (aref calendar-month-name-array (1- month)))
+(defun calendar-month-name (month &optional width)
+  "The name of MONTH.
+If WIDTH is non-nil, return just the first WIDTH characters of the name."
+  (let ((string (aref calendar-month-name-array (1- month))))
+    (if width
+	(let ((i 0) (result "") (pos 0))
+	  (while (< i width)
+	    (let ((chartext (char-to-string (sref string pos))))
+	      (setq pos (+ pos (length chartext)))
+	      (setq result (concat result chartext)))
+	    (setq i (1+ i)))
+	  result)
+      string)))
 
 (defun calendar-day-of-week (date)
   "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
@@ -2412,13 +2434,12 @@
           (if nodayname
               nil
             (if abbreviate
-                (substring (calendar-day-name date) 0 3)
+                (calendar-day-name date 3)
               (calendar-day-name date))))
          (month (extract-calendar-month date))
          (monthname
           (if abbreviate
-              (substring
-               (calendar-month-name month) 0 3)
+              (calendar-month-name month 3)
             (calendar-month-name month)))
          (day (int-to-string (extract-calendar-day date)))
          (month (int-to-string month))