aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLeo Liu2014-11-23 15:58:16 +0800
committerLeo Liu2014-11-23 16:00:06 +0800
commit9c3381106fa40ef7a6d41e09e8fab0e1553b088e (patch)
tree857c58fa69dce44fed3e3dee38a959832dbcab73 /lisp
parent116be2828b1c36a02471019d6a6ed68b67a32497 (diff)
downloademacs-9c3381106fa40ef7a6d41e09e8fab0e1553b088e.tar.gz
emacs-9c3381106fa40ef7a6d41e09e8fab0e1553b088e.zip
Handle leap months in Chinese calendar
Fixes: debbugs:18953 * calendar/cal-china.el (calendar-chinese-from-absolute-for-diary) (calendar-chinese-to-absolute-for-diary) (calendar-chinese-mark-date-pattern, diary-chinese-anniversary): Handle leap months in Chinese calendar. (Bug#18953)
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/calendar/cal-china.el29
2 files changed, 29 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 422336332bf..43b3f9abc8c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12014-11-23 Leo Liu <sdl.web@gmail.com>
2
3 * calendar/cal-china.el (calendar-chinese-from-absolute-for-diary)
4 (calendar-chinese-to-absolute-for-diary)
5 (calendar-chinese-mark-date-pattern, diary-chinese-anniversary):
6 Handle leap months in Chinese calendar. (Bug#18953)
7
12014-11-22 Alan Mackenzie <acm@muc.de> 82014-11-22 Alan Mackenzie <acm@muc.de>
2 9
3 Fix error with `mark-defun' and "protected:" in C++ Mode. 10 Fix error with `mark-defun' and "protected:" in C++ Mode.
diff --git a/lisp/calendar/cal-china.el b/lisp/calendar/cal-china.el
index c5860653a3e..8b61ef1f3ef 100644
--- a/lisp/calendar/cal-china.el
+++ b/lisp/calendar/cal-china.el
@@ -662,18 +662,30 @@ Echo Chinese date unless NOECHO is non-nil."
662;;; These two functions convert to and back from this representation. 662;;; These two functions convert to and back from this representation.
663(defun calendar-chinese-from-absolute-for-diary (date) 663(defun calendar-chinese-from-absolute-for-diary (date)
664 (pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute date))) 664 (pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute date)))
665 (list m d (+ (* c 100) y)))) 665 ;; Note: For leap months M is a float.
666 666 (list (floor m) d (+ (* c 100) y))))
667(defun calendar-chinese-to-absolute-for-diary (date) 667
668 (pcase-let ((`(,m ,d ,y) date)) 668(defun calendar-chinese-to-absolute-for-diary (date &optional prefer-leap)
669 (pcase-let* ((`(,m ,d ,y) date)
670 (cycle (floor y 100))
671 (year (mod y 100))
672 (months (calendar-chinese-months cycle year))
673 (lm (+ (floor m) 0.5)))
669 (calendar-chinese-to-absolute 674 (calendar-chinese-to-absolute
670 (list (floor y 100) (mod y 100) m d)))) 675 (if (and prefer-leap (memql lm months))
676 (list cycle year lm d)
677 (list cycle year m d)))))
671 678
672(defun calendar-chinese-mark-date-pattern (month day year &optional color) 679(defun calendar-chinese-mark-date-pattern (month day year &optional color)
673 (calendar-mark-1 month day year 680 (calendar-mark-1 month day year
674 #'calendar-chinese-from-absolute-for-diary 681 #'calendar-chinese-from-absolute-for-diary
675 #'calendar-chinese-to-absolute-for-diary 682 #'calendar-chinese-to-absolute-for-diary
676 color)) 683 color)
684 (unless (zerop month)
685 (calendar-mark-1 month day year
686 #'calendar-chinese-from-absolute-for-diary
687 (lambda (date) (calendar-chinese-to-absolute-for-diary date t))
688 color)))
677 689
678;;;###cal-autoload 690;;;###cal-autoload
679(defun diary-chinese-mark-entries () 691(defun diary-chinese-mark-entries ()
@@ -717,7 +729,10 @@ This function is provided for use with `diary-nongregorian-listing-hook'."
717 (diff (if (and dc dy) 729 (diff (if (and dc dy)
718 (+ (* 60 (- cc dc)) (- cy dy)) 730 (+ (* 60 (- cc dc)) (- cy dy))
719 100))) 731 100)))
720 (and (> diff 0) (= dm cm) (= dd cd) 732 (and (> diff 0)
733 ;; The Chinese month can differ by 0.5 in a leap month.
734 (or (= dm cm) (= (+ 0.5 dm) cm))
735 (= dd cd)
721 (cons mark (format entry diff (diary-ordinal-suffix diff)))))) 736 (cons mark (format entry diff (diary-ordinal-suffix diff))))))
722 737
723;;;###cal-autoload 738;;;###cal-autoload