From: "Rémi Vanicat" <vanicat@debian.org>
To: emacs-orgmode@gnu.org
Subject: Exporting org-diary-class to icalendar
Date: Mon, 06 Dec 2010 20:20:15 +0100 [thread overview]
Message-ID: <87tyiqu2s0.dlv@debian.org> (raw)
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
next reply other threads:[~2010-12-06 19:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-06 19:20 Rémi Vanicat [this message]
2011-02-11 9:50 ` Exporting org-diary-class to icalendar Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tyiqu2s0.dlv@debian.org \
--to=vanicat@debian.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.