From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?R=C3=A9mi_Vanicat?= Subject: Exporting org-diary-class to icalendar Date: Mon, 06 Dec 2010 20:20:15 +0100 Message-ID: <87tyiqu2s0.dlv@debian.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from [140.186.70.92] (port=38654 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPgbw-0001zh-6b for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 14:20:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPgbv-00036R-4R for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 14:20:32 -0500 Received: from lo.gmane.org ([80.91.229.12]:40532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPgbu-00035u-Oo for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 14:20:31 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PPgbr-0003Ta-DO for emacs-orgmode@gnu.org; Mon, 06 Dec 2010 20:20:27 +0100 Received: from 88-139-240-219.adslgp.cegetel.net ([88.139.240.219]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 06 Dec 2010 20:20:27 +0100 Received: from vanicat by 88-139-240-219.adslgp.cegetel.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 06 Dec 2010 20:20:27 +0100 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 Hello, For those who want to use the org-diary-class diary sexp, and who want to export it to ical (for google calendar consumption for example) Here is a code that will do it. Beware that my timezone is hardwired in it (search for Europe/Paris). For now it doesn't take into account the skipped weeks, my first implementation seemed to failed for an unknown reason. --8<---------------cut here---------------start------------->8--- (defun icalendar--convert-org-diary-class-to-ical (nonmarker entry-main) "Convert `org-diary-class' diary entry to icalendar format. NONMARKER is a regular expression matching the start of non-marking entries. ENTRY-MAIN is the first line of the diary entry." (if (string-match (concat nonmarker "%%(org-diary-class " "\\([0-9]+ [0-9]+ [0-9]+\\) " ;date start "\\([0-9]+ [0-9]+ [0-9]+\\) " ;date start "\\([0-9]+\\)" ;DAYNAME "\\([ 0-9]*\\)) " "\\(" "\\([0-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?" "\\(-\\([0-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?" "\\)?" "\\s-*\\(.*\\) ?$") entry-main) (let* ((start (match-string 1 entry-main)) (end (match-string 2 entry-main)) (dayname (read (match-string 3 entry-main))) (skip-week (match-string 4 entry-main)) (remain-week ()) (startisostring (icalendar--datestring-to-isodate start)) (endisostring (icalendar--datestring-to-isodate end)) (starttimestring (icalendar--diarytime-to-isotime (when (match-beginning 6) (match-string 6 entry-main)) (when (match-beginning 7) (match-string 7 entry-main)))) (endtimestring (icalendar--diarytime-to-isotime (when (match-beginning 9) (match-string 9 entry-main)) (when (match-beginning 10) (match-string 10 entry-main)))) (summary (icalendar--convert-string-for-export (match-string 11 entry-main)))) (icalendar--dmsg "org-diary-class %s" entry-main) (setq skip-week (read (concat "(" skip-week ")"))) (when skip-week (setq remain-week (number-sequence 1 52)) (mapc (lambda (el) (setq remain-week (delete el remain-week))) skip-week)) (when starttimestring (unless endtimestring (let ((time (read (icalendar--rris "^T0?" "" starttimestring)))) (setq endtimestring (format "T%06d" (+ 10000 time)))))) (list (concat "\nDTSTART;TZID=Europe/Paris;" (if starttimestring "VALUE=DATE-TIME:" "VALUE=DATE:") startisostring (or starttimestring "") "\nDTEND;TZID=Europe/Paris;" (if endtimestring "VALUE=DATE-TIME:" "VALUE=DATE:") startisostring (or endtimestring "") "\nRRULE:FREQ=DAILY;INTERVAL=1" ";BYDAY=" (nth dayname '("SU" "MO" "TU" "WE" "TH" "FR" "SA")) ";UNTIL=" endisostring) summary)) ;; no match nil)) (defadvice icalendar--convert-to-ical (around ical-for-org (nonmarker entry-main)) (let ((res (icalendar--convert-org-diary-class-to-ical nonmarker entry-main))) (if res (setq ad-return-value res) ad-do-it))) (ad-activate 'icalendar--convert-to-ical) --8<---------------cut here---------------end--------------->8--- -- RĂ©mi Vanicat