]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-iso.el
(cal-tex-insert-blank-days-at-end, cal-tex-last-blank-p)
[gnu-emacs] / lisp / calendar / cal-iso.el
index 2a12dd66c04b8a5d97fad2f0d292e964d940619b..e7aa4667081cb027b29cdd4d5b29e7c7b7414192 100644 (file)
 
 ;;; Commentary:
 
-;; This collection of functions implements the features of calendar.el and
-;; diary.el that deal with the ISO calendar.
-
-;; Technical details of all the calendrical calculations can be found in
-;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
-;; and Nachum Dershowitz, Cambridge University Press (2001).
+;; See calendar.el.
 
 ;;; Code:
 
@@ -46,12 +41,12 @@ the first such week in which at least 4 days are in a year.  The ISO
 commercial DATE has the form (week day year) in which week is in the range
 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 =
 Sunday).  The Gregorian date Sunday, December 31, 1 BC is imaginary."
-  (let* ((week (extract-calendar-month date))
-         (day (extract-calendar-day date))
-         (year (extract-calendar-year date)))
+  (let ((day (extract-calendar-day date)))
     (+ (calendar-dayname-on-or-before
-        1 (+ 3 (calendar-absolute-from-gregorian (list 1 1 year))))
-       (* 7 (1- week))
+        1 (+ 3 (calendar-absolute-from-gregorian
+                (list 1 1 (extract-calendar-year date)))))
+       ;; ISO date is (week day year); normally (month day year).
+       (* 7 (1- (extract-calendar-month date)))
        (if (zerop day) 6 (1- day)))))
 
 (defun calendar-iso-from-absolute (date)
@@ -67,17 +62,17 @@ date Sunday, December 31, 1 BC."
                   (calendar-gregorian-from-absolute (- date 3))))
          (year (+ approx
                   (calendar-sum y approx
-                      (>= date (calendar-absolute-from-iso (list 1 1 (1+ y))))
-                      1))))
+                                (>= date (calendar-absolute-from-iso
+                                          (list 1 1 (1+ y))))
+                                1))))
     (list
      (1+ (/ (- date (calendar-absolute-from-iso (list 1 1 year))) 7))
      (% date 7)
      year)))
 
-;;;###autoload
+;;;###cal-autoload
 (defun calendar-iso-date-string (&optional date)
-  "String of ISO date of Gregorian DATE.
-Defaults to today's date if DATE is not given."
+  "String of ISO date of Gregorian DATE, default today."
   (let* ((d (calendar-absolute-from-gregorian
              (or date (calendar-current-date))))
          (day (% d 7))
@@ -87,22 +82,22 @@ Defaults to today's date if DATE is not given."
             (extract-calendar-month iso-date)
             (extract-calendar-year iso-date))))
 
-;;;###autoload
+;;;###cal-autoload
 (defun calendar-print-iso-date ()
   "Show equivalent ISO date for the date under the cursor."
   (interactive)
   (message "ISO date: %s"
            (calendar-iso-date-string (calendar-cursor-to-date t))))
 
-(defun calendar-iso-read-args (&optional dayflag)
-  "Interactively read the arguments for an iso date command.
+(defun calendar-iso-read-date (&optional dayflag)
+  "Interactively read the arguments for an ISO date command.
 Reads a year and week, and if DAYFLAG is non-nil a day (otherwise
 taken to be 1)."
-  (let* ((today (calendar-current-date))
-         (year (calendar-read
+  (let* ((year (calendar-read
                 "ISO calendar year (>0): "
                 (lambda (x) (> x 0))
-                (int-to-string (extract-calendar-year today))))
+                (int-to-string (extract-calendar-year
+                                (calendar-current-date)))))
          (no-weeks (extract-calendar-month
                     (calendar-iso-from-absolute
                      (1-
@@ -118,19 +113,22 @@ taken to be 1)."
                 1)))
     (list (list week day year))))
 
-;;;###autoload
+(define-obsolete-function-alias
+  'calendar-iso-read-args 'calendar-iso-read-date "23.1")
+
+;;;###cal-autoload
 (defun calendar-goto-iso-date (date &optional noecho)
-  "Move cursor to ISO DATE; echo ISO date unless NOECHO is t."
-  (interactive (calendar-iso-read-args t))
+  "Move cursor to ISO DATE; echo ISO date unless NOECHO is non-nil."
+  (interactive (calendar-iso-read-date t))
   (calendar-goto-date (calendar-gregorian-from-absolute
                        (calendar-absolute-from-iso date)))
   (or noecho (calendar-print-iso-date)))
 
-;;;###autoload
+;;;###cal-autoload
 (defun calendar-goto-iso-week (date &optional noecho)
-  "Move cursor to ISO DATE; echo ISO date unless NOECHO is t.
+  "Move cursor to ISO DATE; echo ISO date unless NOECHO is non-nil.
 Interactively, goes to the first day of the specified week."
-  (interactive (calendar-iso-read-args))
+  (interactive (calendar-iso-read-date))
   (calendar-goto-date (calendar-gregorian-from-absolute
                        (calendar-absolute-from-iso date)))
   (or noecho (calendar-print-iso-date)))
@@ -138,15 +136,12 @@ Interactively, goes to the first day of the specified week."
 (defvar date)
 
 ;; To be called from list-sexp-diary-entries, where DATE is bound.
+;;;###diary-autoload
 (defun diary-iso-date ()
   "ISO calendar equivalent of date diary entry."
   (format "ISO date: %s" (calendar-iso-date-string date)))
 
 (provide 'cal-iso)
 
-;; Local Variables:
-;; generated-autoload-file: "cal-loaddefs.el"
-;; End:
-
 ;; arch-tag: 3c0154cc-d30f-4981-9f60-42bdf7a468f6
 ;;; cal-iso.el ends here