Function: math-format-date-part
math-format-date-part is a byte-compiled function defined in
calc-forms.el.gz.
Signature
(math-format-date-part X)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-forms.el.gz
(defun math-format-date-part (x)
(cond ((stringp x)
x)
((listp x)
(if (math-integerp math-fd-date)
""
(apply 'concat (mapcar 'math-format-date-part x))))
((eq x 'X)
"")
((eq x 'N)
(math-format-number math-fd-date))
((eq x 'n)
(math-format-number (math-floor math-fd-date)))
((eq x 'J)
(math-format-number
(math-add math-fd-date math-julian-date-beginning)))
((eq x 'j)
(math-format-number (math-add
(math-floor math-fd-date)
math-julian-date-beginning-int)))
((eq x 'U)
(math-format-number (nth 1 (math-date-parts math-fd-date
math-unix-epoch))))
((memq x '(IYYY Iww w))
(progn
(or math-fd-iso-dt
(setq math-fd-iso-dt (math-date-to-iso-dt math-fd-date)
math-fd-isoyear (car math-fd-iso-dt)
math-fd-isoweek (nth 1 math-fd-iso-dt)
math-fd-isoweekday (nth 2 math-fd-iso-dt)))
(cond ((eq x 'IYYY)
(let* ((neg (Math-negp math-fd-isoyear))
(pyear (calcFunc-abs math-fd-isoyear)))
(if (and (natnump pyear) (< pyear 10000))
(concat (if neg "-" "") (format "%04d" pyear))
(concat (if neg "-" "+") (math-format-number pyear)))))
((eq x 'Iww)
(concat "W" (format "%02d" math-fd-isoweek)))
((eq x 'w)
(format "%d" math-fd-isoweekday)))))
((progn
(or math-fd-dt
(progn
(setq math-fd-dt (math-date-to-dt math-fd-date)
math-fd-year (car math-fd-dt)
math-fd-month (nth 1 math-fd-dt)
math-fd-day (nth 2 math-fd-dt)
math-fd-weekday (math-mod (math-floor math-fd-date) 7)
math-fd-hour (nth 3 math-fd-dt)
math-fd-minute (nth 4 math-fd-dt)
math-fd-second (nth 5 math-fd-dt))
(and (memq 'b calc-date-format)
(math-negp math-fd-year)
(setq math-fd-year (math-neg math-fd-year)
math-fd-bc-flag t))))
(memq x '(Y YY BY)))
(if (and (integerp math-fd-year) (> math-fd-year 1940) (< math-fd-year 2040))
(format (cond ((eq x 'YY) "%02d")
((eq x 'BYY) "%2d")
(t "%d"))
(% math-fd-year 100))
(if (and (natnump math-fd-year) (< math-fd-year 100))
(format "+%d" math-fd-year)
(math-format-number math-fd-year))))
((eq x 'YYY)
(math-format-number math-fd-year))
((eq x 'YYYY)
(if (and (natnump math-fd-year) (< math-fd-year 100))
(format "+%d" math-fd-year)
(math-format-number math-fd-year)))
((eq x 'ZYYY)
(let* ((year (if (Math-negp math-fd-year)
(math-add math-fd-year 1)
math-fd-year))
(neg (Math-negp year))
(pyear (calcFunc-abs year)))
(if (and (natnump pyear) (< pyear 10000))
(concat (if neg "-" "") (format "%04d" pyear))
(concat (if neg "-" "+") (math-format-number pyear)))))
((eq x 'b) "")
((eq x 'aa)
(and (not math-fd-bc-flag) "ad"))
((eq x 'AA)
(and (not math-fd-bc-flag) "AD"))
((eq x 'aaa)
(and (not math-fd-bc-flag) "ad "))
((eq x 'AAA)
(and (not math-fd-bc-flag) "AD "))
((eq x 'aaaa)
(and (not math-fd-bc-flag) "a.d."))
((eq x 'AAAA)
(and (not math-fd-bc-flag) "A.D."))
((eq x 'bb)
(and math-fd-bc-flag "bc"))
((eq x 'BB)
(and math-fd-bc-flag "BC"))
((eq x 'bbb)
(and math-fd-bc-flag " bc"))
((eq x 'BBB)
(and math-fd-bc-flag " BC"))
((eq x 'bbbb)
(and math-fd-bc-flag "b.c."))
((eq x 'BBBB)
(and math-fd-bc-flag "B.C."))
((eq x 'T) "T")
((eq x 'M)
(format "%d" math-fd-month))
((eq x 'MM)
(format "%02d" math-fd-month))
((eq x 'BM)
(format "%2d" math-fd-month))
((eq x 'mmm)
(downcase (nth (1- math-fd-month) math-short-month-names)))
((eq x 'Mmm)
(nth (1- math-fd-month) math-short-month-names))
((eq x 'MMM)
(upcase (nth (1- math-fd-month) math-short-month-names)))
((eq x 'Mmmm)
(nth (1- math-fd-month) math-long-month-names))
((eq x 'MMMM)
(upcase (nth (1- math-fd-month) math-long-month-names)))
((eq x 'D)
(format "%d" math-fd-day))
((eq x 'DD)
(format "%02d" math-fd-day))
((eq x 'BD)
(format "%2d" math-fd-day))
((eq x 'W)
(format "%d" math-fd-weekday))
((eq x 'www)
(downcase (nth math-fd-weekday math-short-weekday-names)))
((eq x 'Www)
(nth math-fd-weekday math-short-weekday-names))
((eq x 'WWW)
(upcase (nth math-fd-weekday math-short-weekday-names)))
((eq x 'Wwww)
(nth math-fd-weekday math-long-weekday-names))
((eq x 'WWWW)
(upcase (nth math-fd-weekday math-long-weekday-names)))
((eq x 'd)
(format "%d" (math-day-number math-fd-year math-fd-month math-fd-day)))
((eq x 'ddd)
(format "%03d" (math-day-number math-fd-year math-fd-month math-fd-day)))
((eq x 'bdd)
(format "%3d" (math-day-number math-fd-year math-fd-month math-fd-day)))
((eq x 'h)
(and math-fd-hour (format "%d" math-fd-hour)))
((eq x 'hh)
(and math-fd-hour (format "%02d" math-fd-hour)))
((eq x 'bh)
(and math-fd-hour (format "%2d" math-fd-hour)))
((eq x 'H)
(and math-fd-hour (format "%d" (1+ (% (+ math-fd-hour 11) 12)))))
((eq x 'HH)
(and math-fd-hour (format "%02d" (1+ (% (+ math-fd-hour 11) 12)))))
((eq x 'BH)
(and math-fd-hour (format "%2d" (1+ (% (+ math-fd-hour 11) 12)))))
((eq x 'p)
(and math-fd-hour (if (< math-fd-hour 12) "a" "p")))
((eq x 'P)
(and math-fd-hour (if (< math-fd-hour 12) "A" "P")))
((eq x 'pp)
(and math-fd-hour (if (< math-fd-hour 12) "am" "pm")))
((eq x 'PP)
(and math-fd-hour (if (< math-fd-hour 12) "AM" "PM")))
((eq x 'pppp)
(and math-fd-hour (if (< math-fd-hour 12) "a.m." "p.m.")))
((eq x 'PPPP)
(and math-fd-hour (if (< math-fd-hour 12) "A.M." "P.M.")))
((eq x 'm)
(and math-fd-minute (format "%d" math-fd-minute)))
((eq x 'mm)
(and math-fd-minute (format "%02d" math-fd-minute)))
((eq x 'bm)
(and math-fd-minute (format "%2d" math-fd-minute)))
((eq x 'C)
(and math-fd-second (not (math-zerop math-fd-second))
":"))
((memq x '(s ss bs SS BS))
(and math-fd-second
(not (and (memq x '(SS BS)) (math-zerop math-fd-second)))
(if (integerp math-fd-second)
(format (cond ((memq x '(ss SS)) "%02d")
((memq x '(bs BS)) "%2d")
(t "%d"))
math-fd-second)
(concat (if (Math-lessp math-fd-second 10)
(cond ((memq x '(ss SS)) "0")
((memq x '(bs BS)) " ")
(t ""))
"")
(let ((calc-float-format
(list 'fix (min (- 12 calc-internal-prec)
0))))
(math-format-number math-fd-second))))))))