Commit c8ca95dd authored by Glenn Morris's avatar Glenn Morris
Browse files

Re-indent.

(calendar-absolute-from-julian): Move definition before use.  Remove
un-needed local `day'.
(calendar-goto-julian-date, calendar-goto-astro-day-number): Doc fix.
parent 49f64954
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
(french-calendar-day-name-array, french-calendar-special-days-array): (french-calendar-day-name-array, french-calendar-special-days-array):
Add doc strings. Add doc strings.
   
* calendar/cal-julian.el (calendar-absolute-from-julian): Move
definition before use. Remove un-needed local `day'.
(calendar-goto-julian-date, calendar-goto-astro-day-number): Doc fix.
* calendar/cal-menu.el (displayed-year): Move declaration where needed. * calendar/cal-menu.el (displayed-year): Move declaration where needed.
(calendar-event-to-date, cal-tex-mouse-week, cal-tex-mouse-week-iso): (calendar-event-to-date, cal-tex-mouse-week, cal-tex-mouse-week-iso):
Doc fix. Doc fix.
......
...@@ -38,6 +38,20 @@ ...@@ -38,6 +38,20 @@
(require 'calendar) (require 'calendar)
(defun calendar-absolute-from-julian (date)
"The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
The Gregorian date Sunday, December 31, 1 BC is imaginary."
(let ((month (extract-calendar-month date))
(year (extract-calendar-year date)))
(+ (calendar-day-number date)
(if (and (zerop (% year 100))
(not (zerop (% year 400)))
(> month 2))
1 0) ; correct for Julian but not Gregorian leap year
(* 365 (1- year))
(/ (1- year) 4)
-2)))
;;;###cal-autoload ;;;###cal-autoload
(defun calendar-julian-from-absolute (date) (defun calendar-julian-from-absolute (date)
"Compute the Julian (month day year) corresponding to the absolute DATE. "Compute the Julian (month day year) corresponding to the absolute DATE.
...@@ -47,38 +61,25 @@ Gregorian date Sunday, December 31, 1 BC." ...@@ -47,38 +61,25 @@ Gregorian date Sunday, December 31, 1 BC."
(year ; search forward from the approximation (year ; search forward from the approximation
(+ approx (+ approx
(calendar-sum y approx (calendar-sum y approx
(>= date (calendar-absolute-from-julian (list 1 1 (1+ y)))) (>= date (calendar-absolute-from-julian
1))) (list 1 1 (1+ y))))
1)))
(month ; search forward from January (month ; search forward from January
(1+ (calendar-sum m 1 (1+ (calendar-sum m 1
(> date (> date
(calendar-absolute-from-julian (calendar-absolute-from-julian
(list m (list m
(if (and (= m 2) (zerop (% year 4))) (if (and (= m 2) (zerop (% year 4)))
29 29
(aref [31 28 31 30 31 30 31 31 30 31 30 31] (aref [31 28 31 30 31 30 31
(1- m))) 31 30 31 30 31]
year))) (1- m)))
1))) year)))
1)))
(day ; calculate the day by subtraction (day ; calculate the day by subtraction
(- date (1- (calendar-absolute-from-julian (list month 1 year)))))) (- date (1- (calendar-absolute-from-julian (list month 1 year))))))
(list month day year))) (list month day year)))
(defun calendar-absolute-from-julian (date)
"The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
The Gregorian date Sunday, December 31, 1 BC is imaginary."
(let ((month (extract-calendar-month date))
(day (extract-calendar-day date))
(year (extract-calendar-year date)))
(+ (calendar-day-number date)
(if (and (zerop (% year 100))
(/= (% year 400) 0)
(> month 2))
1 0) ; correct for Julian but not Gregorian leap year
(* 365 (1- year))
(/ (1- year) 4)
-2)))
;;;###cal-autoload ;;;###cal-autoload
(defun calendar-julian-date-string (&optional date) (defun calendar-julian-date-string (&optional date)
"String of Julian date of Gregorian DATE. "String of Julian date of Gregorian DATE.
...@@ -86,8 +87,7 @@ Defaults to today's date if DATE is not given. ...@@ -86,8 +87,7 @@ Defaults to today's date if DATE is not given.
Driven by the variable `calendar-date-display-form'." Driven by the variable `calendar-date-display-form'."
(calendar-date-string (calendar-date-string
(calendar-julian-from-absolute (calendar-julian-from-absolute
(calendar-absolute-from-gregorian (calendar-absolute-from-gregorian (or date (calendar-current-date))))
(or date (calendar-current-date))))
nil t)) nil t))
;;;###cal-autoload ;;;###cal-autoload
...@@ -99,7 +99,7 @@ Driven by the variable `calendar-date-display-form'." ...@@ -99,7 +99,7 @@ Driven by the variable `calendar-date-display-form'."
;;;###cal-autoload ;;;###cal-autoload
(defun calendar-goto-julian-date (date &optional noecho) (defun calendar-goto-julian-date (date &optional noecho)
"Move cursor to Julian DATE; echo Julian date unless NOECHO is t." "Move cursor to Julian DATE; echo Julian date unless NOECHO is non-nil."
(interactive (interactive
(let* ((today (calendar-current-date)) (let* ((today (calendar-current-date))
(year (calendar-read (year (calendar-read
...@@ -113,10 +113,10 @@ Driven by the variable `calendar-date-display-form'." ...@@ -113,10 +113,10 @@ Driven by the variable `calendar-date-display-form'."
(month-array calendar-month-name-array) (month-array calendar-month-name-array)
(completion-ignore-case t) (completion-ignore-case t)
(month (cdr (assoc-string (month (cdr (assoc-string
(completing-read (completing-read
"Julian calendar month name: " "Julian calendar month name: "
(mapcar 'list (append month-array nil)) (mapcar 'list (append month-array nil))
nil t) nil t)
(calendar-make-alist month-array 1) t))) (calendar-make-alist month-array 1) t)))
(last (last
(if (and (zerop (% year 4)) (= month 2)) (if (and (zerop (% year 4)) (= month 2))
...@@ -126,8 +126,8 @@ Driven by the variable `calendar-date-display-form'." ...@@ -126,8 +126,8 @@ Driven by the variable `calendar-date-display-form'."
(format "Julian calendar day (%d-%d): " (format "Julian calendar day (%d-%d): "
(if (and (= year 1) (= month 1)) 3 1) last) (if (and (= year 1) (= month 1)) 3 1) last)
(lambda (x) (lambda (x)
(and (< (if (and (= year 1) (= month 1)) 2 0) x) (and (< (if (and (= year 1) (= month 1)) 2 0) x)
(<= x last)))))) (<= x last))))))
(list (list month day year)))) (list (list month day year))))
(calendar-goto-date (calendar-gregorian-from-absolute (calendar-goto-date (calendar-gregorian-from-absolute
(calendar-absolute-from-julian date))) (calendar-absolute-from-julian date)))
...@@ -181,8 +181,7 @@ Defaults to today's date if DATE is not given." ...@@ -181,8 +181,7 @@ Defaults to today's date if DATE is not given."
(int-to-string (int-to-string
(ceiling (ceiling
(calendar-astro-from-absolute (calendar-astro-from-absolute
(calendar-absolute-from-gregorian (calendar-absolute-from-gregorian (or date (calendar-current-date)))))))
(or date (calendar-current-date)))))))
;;;###cal-autoload ;;;###cal-autoload
(defun calendar-print-astro-day-number () (defun calendar-print-astro-day-number ()
...@@ -195,7 +194,7 @@ Defaults to today's date if DATE is not given." ...@@ -195,7 +194,7 @@ Defaults to today's date if DATE is not given."
;;;###cal-autoload ;;;###cal-autoload
(defun calendar-goto-astro-day-number (daynumber &optional noecho) (defun calendar-goto-astro-day-number (daynumber &optional noecho)
"Move cursor to astronomical (Julian) DAYNUMBER. "Move cursor to astronomical (Julian) DAYNUMBER.
Echo astronomical (Julian) day number unless NOECHO is t." Echo astronomical (Julian) day number unless NOECHO is non-nil."
(interactive (list (calendar-read (interactive (list (calendar-read
"Astronomical (Julian) day number (>1721425): " "Astronomical (Julian) day number (>1721425): "
(lambda (x) (> x 1721425))))) (lambda (x) (> x 1721425)))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment