From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Subject: Re: How to set a entry with Chinese calender? Date: Wed, 06 May 2009 02:57:59 +0100 Message-ID: References: <49F9591D.2010101@gmail.com> <4A0044C8.7010107@gmail.com> <4A00CC9C.60105@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M1WOs-0000Oi-7r for emacs-orgmode@gnu.org; Tue, 05 May 2009 21:58:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M1WOn-0000Lm-FN for emacs-orgmode@gnu.org; Tue, 05 May 2009 21:58:21 -0400 Received: from [199.232.76.173] (port=38054 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1WOn-0000Lj-9b for emacs-orgmode@gnu.org; Tue, 05 May 2009 21:58:17 -0400 Received: from mx20.gnu.org ([199.232.41.8]:25118) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M1WOm-0000ec-OG for emacs-orgmode@gnu.org; Tue, 05 May 2009 21:58:16 -0400 Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M1WOl-0006JP-05 for emacs-orgmode@gnu.org; Tue, 05 May 2009 21:58:15 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1M1WOg-0001dg-FO for emacs-orgmode@gnu.org; Wed, 06 May 2009 01:58:10 +0000 Received: from sl392.st-edmunds.cam.ac.uk ([131.111.223.202]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 06 May 2009 01:58:10 +0000 Received: from sdl.web by sl392.st-edmunds.cam.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 06 May 2009 01:58:10 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= On 2009-05-06 00:32 +0100, Wei-Wei Guo wrote: >>> 1. The calculation of Chinese year is not right. >>> >>> For example, if I born in 1982.11 of *solar* calendar and my father born >>> in 1952.12 of *lunar* calendar. My age is calculated as 27 and my father's >>> age is calculated as 58, which should be 57. Because my father's birthday >>> is in the next year of *solar* calender, his age is calculated one year >>> more. >>> > > This bug cannot be reproduced without loading cal-china-plus for it uses the > diary-chinese-anniversary of your package. For example. > > %%(diary-anniversary 11 1 1982) I'm %d years old. > %%(diary-chinese-anniversary 12 1 1952) Dad is %d years old. > > Could you give me some hints on how to present the bug without your package? How do you make calendar show the age of your father? I put %%(diary-chinese-anniversary 12 1 1952) in my diary file and on 2008.12.27 (solar calendar), it says '56 years old', isn't this correct? There are different ways of counting ages. The diff var in the diary-chinese-anniversary holds the age value. Incidentally I found a bug in diary-chinese-anniversary. Could you test the attached version? --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=cal-china-plus.el Content-Transfer-Encoding: quoted-printable Content-Description: cal-china-plus.el ;;; cal-china-plus.el --- extra stuff for cal-china ;; Copyright (C) 2008 Leo Shidai Liu ;; Author: Leo Shidai Liu ;; Keywords: calendar, convenience, local ;; Version: 0.12 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; All functions are prefixed with calendar-chinese- unless it is ;; already in cal-china.el; in this case, it is prefixed with ;; calendar-chinese-plus- ;; *NB*: the Chinese calendar date is represented with '(month day ;; nl-year) instead of '(cycle year month day) in the dary file, where ;; nl-year is Nong-Li year offset by constant 2697. For example, Cycle ;; 78 Year 25 is Nong-Li year 4705 but for convenience it is ;; represented as 2008 (i.e. 4705 - 2697) in the diary file. ;; Please send me any comments that you may have. Thank you. ;;; Code: (require 'cal-china) (require 'diary-lib) ;;; modification to existing variables and functions (setq calendar-chinese-celestial-stem ["=E7=94=B2" "=E4=B9=99" "=E4=B8=99" "=E4=B8=81" "=E6=88=8A" "=E5=B7= =B1" "=E5=BA=9A" "=E8=BE=9B" "=E5=A3=AC" "=E7=99=B8"]) (setq calendar-chinese-terrestrial-branch ["=E5=AD=90" "=E4=B8=91" "=E5=AF=85" "=E5=8D=AF" "=E8=BE=B0" "=E5=B7= =B3" "=E5=8D=88" "=E6=9C=AA" "=E7=94=B3" "=E9=85=89" "=E6=88=8C" "=E4=BA=A5= "]) (defun calendar-chinese-sexagesimal-name (n) "The N-th name of the Chinese sexagesimal cycle. N congruent to 1 gives the first name, N congruent to 2 gives the second na= me, ..., N congruent to 60 gives the sixtieth name." ;; "%s-%s" -> "%s%s", since Chinese characters are tight one by one, ;; no extra `-' needed. (format "%s%s" (aref calendar-chinese-celestial-stem (% (1- n) 10)) (aref calendar-chinese-terrestrial-branch (% (1- n) 12)))) ;;; end of modification ;; Don't set this to ["1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"] (defvar calendar-chinese-month-name-array ["=E6=AD=A3=E6=9C=88" "=E4=BA=8C=E6=9C=88" "=E4=B8=89=E6=9C=88" "=E5=9B= =9B=E6=9C=88" "=E4=BA=94=E6=9C=88" "=E5=85=AD=E6=9C=88" "=E4=B8=83=E6=9C=88" "=E5=85=AB=E6=9C=88" "=E4=B9=9D=E6=9C=88" "=E5=8D= =81=E6=9C=88" "=E5=86=AC=E6=9C=88" "=E8=85=8A=E6=9C=88"]) (defcustom diary-chinese-entry-symbol "C" "Symbol indicating a diary entry according to the Chinese calendar." :type 'string :group 'diary) ;;; nl-year 2008 is NongLi 4705 or Cycle 78 Year 25 ;;; Code adapted from `calendar-chinese-to-absolute' (defun calendar-chinese-year-to-nlyear (cycle year) (+ (* (1- cycle) 60) ; years in prior cycles (1- year) ; prior years this cycle -2636)) (defun calendar-chinese-year-from-nlyear (nlyear) "Return Chinese Cycle and Year for NLYEAR." (let ((c-year (+ nlyear 2696))) (list (/ c-year 60) (1+ (mod c-year 60))))) (defun calendar-chinese-from-absolute* (date) "The returned date is in the form '(month day nlyear)." (let* ((c-date (calendar-chinese-from-absolute date)) (cycle (nth 0 c-date)) (year (nth 1 c-date)) ;; handle leap month (month (floor (nth 2 c-date))) (day (nth 3 c-date)) (nlyear (calendar-chinese-year-to-nlyear cycle year))) (list month day nlyear))) ;; date example: '(month day nlyear) (defun calendar-chinese-to-absolute* (date) (let* ((year (car (last date))) (cy (calendar-chinese-year-from-nlyear year)) (c-date (append cy (list (car date) (cadr date))))) (calendar-chinese-to-absolute c-date))) ;;;###autoload (defun diary-chinese-list-entries () "Add any Chinese date entries from the diary file to `diary-entries-list'. Chinese date diary entries must be prefaced by `diary-chinese-entry-symbol' \(normally an `I'). The same `diary-date-forms' govern the style of the Chinese calendar entries. If an Islamic date diary entry begins with `diary-nonmarking-symbol', the entry will appear in the diary listing, but will not be marked in the calendar. This function is provided for use with `diary-nongregorian-listing-hook'." (diary-list-entries-1 calendar-chinese-month-name-array diary-chinese-entry-symbol 'calendar-chinese-from-absolute*)) ;;; calendar-mark-1 seems only work with islamic and bahai (defun calendar-chinese-mark-date-pattern (month day year &optional color) "Mark dates in calendar window that conform to chinese date MONTH/DAY/YEA= R. A value of 0 in any position is a wildcard. Optional argument COLOR is passed to `calendar-mark-visible-date' as MARK." (save-excursion (set-buffer calendar-buffer) (if (and (not (zerop month)) (not (zerop day))) (if (not (zerop year)) ;; Fully specified date. (let ((date (calendar-gregorian-from-absolute (calendar-chinese-to-absolute* (list month day yea= r))))) (if (calendar-date-is-visible-p date) (calendar-mark-visible-date date color))) ;; Month and day in any year. (let ((gdate (calendar-nongregorian-visible-p month day 'calendar-chinese-to-absolute* 'calendar-chinese-from-absolute* (lambda (m) (< m 6))))) (if gdate (calendar-mark-visible-date gdate color)))) (calendar-mark-complex month day year 'calendar-chinese-from-absolute* color)))) ;;;###autoload (defun diary-chinese-mark-entries () "Mark days in the calendar window that have Chinese date diary entries. Marks each entry in `diary-file' (or included files) visible in the calendar window. See `diary-chinese-list-entries' for more information. This function is provided for use with `diary-nongregorian-marking-hook'." (diary-mark-entries-1 'calendar-chinese-mark-date-pattern calendar-chinese-month-name-array diary-chinese-entry-symbol 'calendar-chinese-from-absolute*)) ;;;###autoload (defun diary-chinese-insert-entry (arg) "Insert a diary entry. For the Chinese date corresponding to the date indicated by point. Prefix argument ARG makes the entry nonmarking." (interactive "P") (diary-insert-entry-1 nil arg calendar-chinese-month-name-array diary-chinese-entry-symbol 'calendar-chinese-from-absolute*)) ;;;###autoload (defun diary-chinese-insert-monthly-entry (arg) "Insert a monthly diary entry. For the day of the Chinese month corresponding to the date indicated by poi= nt. Prefix argument ARG makes the entry nonmarking." (interactive "P") (diary-insert-entry-1 'monthly arg calendar-chinese-month-name-array diary-chinese-entry-symbol 'calendar-chinese-from-absolute*)) ;;;###autoload (defun diary-chinese-insert-yearly-entry (arg) "Insert an annual diary entry. For the day of the Chinese year corresponding to the date indicated by poin= t. Prefix argument ARG makes the entry nonmarking." (interactive "P") (diary-insert-entry-1 'yearly arg calendar-chinese-month-name-array diary-chinese-entry-symbol 'calendar-chinese-from-absolute*)) (defvar date) (defvar entry) ;;;###autoload (defun diary-chinese-anniversary (month day &optional nlyear mark) "Anniversary diary entry in Chinese MONTH, DAY and NLYEAR." (let* ((ddate (diary-make-date month day year)) (dd (calendar-extract-day ddate)) (mm (calendar-extract-month ddate)) (yy (calendar-extract-year ddate)) (a-date (calendar-absolute-from-gregorian date)) (c-date (calendar-chinese-from-absolute* a-date)) (mm2 (calendar-extract-month c-date)) (dd2 (calendar-extract-day c-date)) (yy2 (calendar-extract-year c-date)) (diff (if yy (- yy2 yy) 100))) (and (> diff 0) (=3D mm mm2) (=3D dd dd2) (cons mark (format entry diff (diary-ordinal-suffix diff)))))) ;;;###autoload (defun diary-chinese-insert-anniversary-entry (arg) "Insert an anniversary diary entry for the Chinese date given by point. Prefix argument ARG makes the entry nonmarking." (interactive "P") (let ((calendar-date-display-form (diary-date-display-form))) (diary-make-entry (format "%s(diary-chinese-anniversary %s)" diary-sexp-entry-symbol (calendar-date-string (calendar-chinese-from-absolute* (calendar-absolute-from-gregorian (calendar-cursor-to-date t= ))))) arg))) (define-key calendar-mode-map "iCa" 'diary-chinese-insert-anniversary-entry) (define-key calendar-mode-map "iCd" 'diary-chinese-insert-entry) (define-key calendar-mode-map "iCm" 'diary-chinese-insert-monthly-entry) (define-key calendar-mode-map "iCy" 'diary-chinese-insert-yearly-entry) (provide 'cal-china-plus) ;;; cal-china-plus.el ends here --=-=-= Thanks, -- .: Leo :. [ sdl.web AT gmail.com ] .: I use Emacs :. --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--