emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Adding support for limits and exclusions to iCal recurring events
@ 2013-07-07 15:55 Toke Høiland-Jørgensen
  2013-07-22 11:45 ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: Toke Høiland-Jørgensen @ 2013-07-07 15:55 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2668 bytes --]

Hi

I've been wanting to have support for exporting recurring events to iCal
while limiting the number of repetitions, as well as excluding dates.
The patch below is my attempt to add this functionality. However, I'm in
doubt as to whether or not this is the right way to go about it (parsing
dates stored in the property drawer), or if there's a better way?

A sample headline supporting this might look like this:

* Test
:PROPERTIES:
:END_DATE: [2013-07-21 Sun]
:EXCLUDE:  [2013-07-14 Sun]
:ID:       b376f8e3-f1a7-4ed6-ab9b-a255938af8c0
:END:
<2013-07-07 Sun +1w>


If this is a reasonable way to go about it, I'll be happy to resubmit it
as a proper patch (i.e. from `git format-patch`) for inclusion. :)

-Toke

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index c6ab295..361cef2 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -632,6 +632,12 @@ inlinetask within the section."
        ;; Don't forget components from inner entries.
        contents))))
 
+(defun org-icalendar-zero-convert-timestamp (timestamp &optional format)
+  "Parse and format an org-formatted timestamp, zeroing the time component."
+  (let ((time (org-parse-time-string timestamp))
+	(fmt (or format "%Y%m%dT%H%M%SZ")))
+    (format-time-string fmt (encode-time 0 0 0 (nth 3 time) (nth 4 time) (nth 5 time)))))
+
 (defun org-icalendar--vevent
   (entry timestamp uid summary location description categories)
   "Create a VEVENT component.
@@ -656,11 +662,18 @@ Return VEVENT component as a string."
 	     (org-icalendar-convert-timestamp timestamp "DTEND" t) "\n"
 	     ;; RRULE.
 	     (when (org-element-property :repeater-type timestamp)
-	       (format "RRULE:FREQ=%s;INTERVAL=%d\n"
+	       (format "RRULE:FREQ=%s;INTERVAL=%d%s\n"
 		       (case (org-element-property :repeater-unit timestamp)
 			 (hour "HOURLY") (day "DAILY") (week "WEEKLY")
 			 (month "MONTHLY") (year "YEARLY"))
-		       (org-element-property :repeater-value timestamp)))
+		       (org-element-property :repeater-value timestamp)
+		       (if (not (org-element-property :END_DATE entry)) ""
+			   (format ";UNTIL=%s" (org-icalendar-zero-convert-timestamp
+						  (org-element-property :END_DATE entry))))))
+	     (when (org-element-property :EXCLUDE entry)
+	       (format "EXDATE;VALUE=DATE:%s\n" (mapconcat (lambda (ts) (org-icalendar-zero-convert-timestamp ts "%Y%m%d"))
+							   (split-string (org-element-property :EXCLUDE entry) ",")
+							   ",")))
 	     "SUMMARY:" summary "\n"
 	     (and (org-string-nw-p location) (format "LOCATION:%s\n" location))
 	     (and (org-string-nw-p description)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 489 bytes --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-07-27 22:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-07 15:55 Adding support for limits and exclusions to iCal recurring events Toke Høiland-Jørgensen
2013-07-22 11:45 ` Nicolas Goaziou
2013-07-22 14:56   ` Toke Høiland-Jørgensen
2013-07-24  8:38     ` Nicolas Goaziou
2013-07-24 16:01       ` Michael Brand
2013-07-24 17:25         ` Toke Høiland-Jørgensen
2013-07-27 21:11           ` Nicolas Goaziou
2013-07-27 22:16             ` Toke Høiland-Jørgensen
2013-07-24 18:23       ` David Rogers

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).