user1876484
user1876484

Reputation: 630

How to define Hebrew anniversaries to show up in Org agenda?

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?

Upvotes: 0

Views: 331

Answers (2)

NickD
NickD

Reputation: 6422

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.

Upvotes: 1

Brian Malehorn
Brian Malehorn

Reputation: 2685

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

(require 'org-bbdb)

Upvotes: 0

Related Questions