Function: math-date-to-gregorian-dt
math-date-to-gregorian-dt is a byte-compiled function defined in
calc-forms.el.gz.
Signature
(math-date-to-gregorian-dt DATE)
Documentation
Return the day (YEAR MONTH DAY) in the Gregorian calendar.
DATE is the number of days since December 31, -1 in the Gregorian calendar.
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-forms.el.gz
;;;; Date forms.
;;; Some of these functions are adapted from Edward Reingold's "calendar.el".
;;; These versions are rewritten to use arbitrary-size integers.
;;; A numerical date is the number of days since midnight on
;;; the morning of December 31, 1 BC (Gregorian) or January 2, 1 AD (Julian).
;;; Emacs's calendar refers to such a date as an absolute date, some Calc function
;;; names also use that terminology. If the date is a non-integer, it represents
;;; a specific date and time.
;;; A "dt" is a list of the form, (year month day), corresponding to
;;; an integer code, or (year month day hour minute second), corresponding
;;; to a non-integer code.
(defun math-date-to-gregorian-dt (date)
"Return the day (YEAR MONTH DAY) in the Gregorian calendar.
DATE is the number of days since December 31, -1 in the Gregorian calendar."
(let* ((month 1)
day
(year (math-quotient (math-add date (if (Math-lessp date 711859)
365 ; for speed, we take
-108)) ; >1950 as a special case
(if (math-negp date) 366 365)))
; this result may be an overestimate
temp)
(while (Math-lessp date (setq temp (math-absolute-from-gregorian-dt year 1 1)))
(setq year (math-add year -1)))
(if (eq year 0) (setq year -1))
(setq date (1+ (math-sub date temp)))
(setq temp
(if (math-leap-year-p year)
[1 32 61 92 122 153 183 214 245 275 306 336 999]
[1 32 60 91 121 152 182 213 244 274 305 335 999]))
(while (>= date (aref temp month))
(setq month (1+ month)))
(setq day (1+ (- date (aref temp (1- month)))))
(list year month day)))