;;; cal-china.el --- calendar functions for the Chinese calendar
-;; Copyright (C) 1995, 1997, 2001-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1997, 2001-2015 Free Software Foundation, Inc.
;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
;; Maintainer: Glenn Morris <rgm@gnu.org>
;;; These two functions convert to and back from this representation.
(defun calendar-chinese-from-absolute-for-diary (date)
(pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute date)))
- (list m d (+ (* c 100) y))))
-
-(defun calendar-chinese-to-absolute-for-diary (date)
- (pcase-let ((`(,m ,d ,y) date))
+ ;; Note: For leap months M is a float.
+ (list (floor m) d (+ (* c 100) y))))
+
+(defun calendar-chinese-to-absolute-for-diary (date &optional prefer-leap)
+ (pcase-let* ((`(,m ,d ,y) date)
+ (cycle (floor y 100))
+ (year (mod y 100))
+ (months (calendar-chinese-months cycle year))
+ (lm (+ (floor m) 0.5)))
(calendar-chinese-to-absolute
- (list (floor y 100) (mod y 100) m d))))
+ (if (and prefer-leap (memql lm months))
+ (list cycle year lm d)
+ (list cycle year m d)))))
(defun calendar-chinese-mark-date-pattern (month day year &optional color)
(calendar-mark-1 month day year
#'calendar-chinese-from-absolute-for-diary
#'calendar-chinese-to-absolute-for-diary
- color))
+ color)
+ (unless (zerop month)
+ (calendar-mark-1 month day year
+ #'calendar-chinese-from-absolute-for-diary
+ (lambda (date) (calendar-chinese-to-absolute-for-diary date t))
+ color)))
;;;###cal-autoload
(defun diary-chinese-mark-entries ()
(diff (if (and dc dy)
(+ (* 60 (- cc dc)) (- cy dy))
100)))
- (and (> diff 0) (= dm cm) (= dd cd)
+ (and (> diff 0)
+ ;; The Chinese month can differ by 0.5 in a leap month.
+ (or (= dm cm) (= (+ 0.5 dm) cm))
+ (= dd cd)
(cons mark (format entry diff (diary-ordinal-suffix diff))))))
;;;###cal-autoload