0

How to define Hebrew anniversaries (like birthdays) to show up in Org agenda? The best would be to do it through BBDB. So far I managed to add anniversaries/birthdays to BBDB and display them in org-agenda. Now I need to move to the next step and provide those dates as Hebrew dates. In diary mode the dates seem to look like HSivan 17, 5776 . However if I insert it to BBDB like anniversary: HSivan 17, 5776 birthday - I get error while trying to generate agenda view: bad-sexp at line 5 /path/to/agenda.org (org-bbdb-anniversaries). Maybe there are other ways (without BBDB), maybe I can list them in an .org file directly?

user1876484
  • 610
  • 6
  • 16

2 Answers2

1

In general, org-mode does not deal well (or at all) with calendars other than ISO-based, western calendars.

If you want to store differently formatted dates in bbdb, you can customize org-bbdb-extract-date-fun. You'll have to write your own function to parse Hebrew dates and return (month day year).

That will allow you to use a bbdb database using Hebrew dates, but it will not present e.g., agenda output using Hebrew dates. That is a much harder problem, particularly because the ISO calendar assumption permeates the org-mode code base.

EDIT: Here's a function that takes a string like "Heshvan 17, 5776" as argument and produces a (month, day, year) tuple that org can use:

;;; This function uses functions and variables defined in calendar.el
;;; and cal-hebrew.el

(require 'calendar)
(require 'cal-hebrew)

(defun org-bbdb-anniv-extract-hebrew-date (date-string)
    "Parse the string, assumed to be in the form \"MONTHNAME day,
     year\", using Hebrew month names. Day is an integer, roughly
     between 1 and 30 (the range depends on the month and the
     year), and year is an integer representing a Hebrew calendar
     year (roughly 5776 ~= 2015)."
    (let* ((date-list (split-string date-string))
           (month-name (nth 0 date-list))
           (day (string-to-number (nth 1 date-list)))
           (year (string-to-number (nth 2 date-list)))
           (month-array (if (calendar-hebrew-leap-year-p year)
                            calendar-hebrew-month-name-array-leap-year
                          calendar-hebrew-month-name-array-common-year))
           (month (cdr (assoc-string
                         month-name
                         (calendar-make-alist month-array 1)))))
      (calendar-gregorian-from-absolute
       (calendar-hebrew-to-absolute (list month day year)))))

;; test: (org-bbdb-anniv-extract-hebrew-date "Heshvan 17, 5776") ==> (10 30 2015)
;; test: (org-bbdb-anniv-extract-hebrew-date "Heshvan 17, 3762") ==> (10 22 1)
;; I hope these are right.

;; To get org-bbdb to use this function to read dates from the BBDB
;; database, instead of the standard org-bbdb-anniv-extract-date, do
;; this:

;; (setq org-bbdb-extract-date-fun #'org-bbdb-anniv-extract-hebrew-date)

;; N.B. *ALL* dates in the BBDB database will be read using this
;; function, so *ALL* of them must be Hebrew calendar dates. There is
;; no provision for dates in different formats. To do that, one would
;; need to write a function that can recognize dates in different
;; formats (probably using heuristics) and then call the right
;; conversion function. That's beyond the scope of this answer.

;; Also, calendrical calculations are notoriously difficult to get
;; right: this is no exception. In particular, the month calculation
;; is probably valid only for dates in the Common Era, i.e. for years
;; >= 3762. cal-hebrew.el has more details. But in any case, no
;; guarantees: if it breaks, you get to keep the pieces.
NickD
  • 5,937
  • 1
  • 21
  • 38
  • I'm fine with the fact that the anniversary will be displayed on an ISO calendar, the only thing I need is that it will be displayed on the ISO date that corresponds to the Hebrew date. – user1876484 Jul 01 '16 at 05:18
  • Then writing a function as suggested above should be enough. You can model it on `org-bbdb-anniv-extract-date`, but instead of taking a string of the form 'YYYY-MM-DD', it will take a Hebrew date string. You might be able to use calendar functions for the conversion, but that's beyond my knowledge. – NickD Jul 01 '16 at 05:36
  • 1
    cal-hebrew.el contains the following array of month names: `(defconst calendar-hebrew-month-name-array-common-year ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri" "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"] "Array of strings giving the names of the Hebrew months in a common year.")`. Months are represented by integers; assuming 0-based, "Heshvan" is 7, so Heshvan 17, 5776 would be represented by (7 17 5776). The conversion is done with `(calendar-gregorian-from-absolute (calendar-hebrew-to-absolute '(7 17 5776)))` which gives (9 30 2015). – NickD Jul 02 '16 at 02:41
  • thank you! I think Hebrew dates can be identified by the "H" char preceding the date itselft like: HHeshvan 17, 5776 or H5775-03-20. At least that is the way it is inserted into diary (using "i h d" command). By the way: is there a way to show Hebrew dates from diary in Org or maybe even use Hebrew dates to mark events in Org itself (like * Birthday )> – user1876484 Jul 06 '16 at 10:51
  • If that's how they are entered, then the above function will fail. It only understands "Monthname Date, Year": it would have to strip the initial H. It also does not understand the H5775-03-20 format. And AFAIK, org cannot deal with Hebrew dates at all. – NickD Jul 06 '16 at 13:33
  • @user1876484 Did this fix your issue? [My issue seems to be still unresolved even after putting in bounty](http://stackoverflow.com/questions/36557402/viewing-chinese-korean-lunar-birthday-on-org-agenda) – THIS USER NEEDS HELP Jul 20 '16 at 17:54
0

I believe you can fix your bbdb problem by putting this in your .emacs:

(require 'org-bbdb)
Brian Malehorn
  • 2,627
  • 14
  • 15
  • Adding this line didn't solve the issue. Actually it is/was working for Gregorian dates. I just need a way to convert Hebrew date to the Gregorian during Agenda view generation. Interesting thing: if I write `anniversary: HSivan 23, 5776 birthday` I get the error above, but if I write it in ISO style, like `anniversary: H5776-03-23 birthday` I get no errors, but the birthday is not displayed either. I just found [similiar question re Chineese](http://stackoverflow.com/questions/36557402/viewing-chinese-korean-lunar-birthday-on-org-agenda). – user1876484 Jun 29 '16 at 08:59
  • Sorry but I don't know much more than you do about this issue. You can try poking around the Emacs documentation: https://www.gnu.org/software/emacs/manual/html_node/emacs/Other-Calendars.html#Other-Calendars, or try reading the source code for the Hebrew calendar, for me located at `/usr/local/share/emacs/24.4/lisp/calendar/cal-hebrew.el.gz`. – Brian Malehorn Jun 29 '16 at 22:08