From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: using holiday dates from an ICAL calendar Date: Wed, 12 Aug 2015 16:37:49 -0500 Message-ID: <87si7o8a3a.fsf@fastmail.fm> References: <876153dpjr.fsf@free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZPdia-0006vP-92 for emacs-orgmode@gnu.org; Wed, 12 Aug 2015 17:37:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZPdiX-00017B-1z for emacs-orgmode@gnu.org; Wed, 12 Aug 2015 17:37:52 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:38555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZPdiW-00016y-S2 for emacs-orgmode@gnu.org; Wed, 12 Aug 2015 17:37:48 -0400 In-Reply-To: <876153dpjr.fsf@free.fr> (Julien Cubizolles's message of "Wed, 29 Jul 2015 16:08:40 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Julien Cubizolles Cc: emacs-orgmode@gnu.org Julien Cubizolles writes: > I need to define weekly appointments, except during the school > holidays. I know org-class provides a way to exclude some weeks from > recurring events but I was wondering if some clever use of sexp would > make it possible to use the weeks/days of holiday from a public ical > calendar (like > https://www.google.com/calendar/ical/bubn5utkn054pluh4v44nu6ok62e1dbo%40i= mport.calendar.google.com/public/basic.ics). > Did somebody ever try it=C2=A0? One possible solution that comes to mind would be to parse the calendar with icalendar-import-file. wget https://www.google.com/calendar/ical/bubn5utkn054pluh4v44nu6ok62e1dbo%= 40import.calendar.google.com/public/basic.ics /tmp/basic.ics Then within emacs: (icalendar-import-file "/tmp/basic.ics" "/tmp/diary") This produces entries that look like this: --8<---------------cut here---------------start------------->8--- %%(and (diary-block 10 17 2015 11 1 2015)) Vacances de la Toussaint - Zone B Desc: Vacances de la Toussaint Location: Aix-Marseille, Amiens, Caen, Lille, Nancy-Metz, Nantes, Nice, Or= l=C3=A9ans-Tours, Reims, Rennes, Rouen, Strasbourg --8<---------------cut here---------------end--------------->8--- You could write a script to parse this data and combine it with an org-class sexp, resulting in something like this: %%(and (not (diary-block 10 17 2015 11 1 2015)) (org-class 2015 9 15 2015 1= 2 20 3)) My class Alternatively you could use the data in the diary block to calculate which iso weeks to add to the SKIP-WEEKS arguments of org-class, which has the following form: (org-class Y1 M1 D1 Y2 M2 D2 DAYNAME &rest SKIP-WEEKS) Here's a proof of concept that shows how you could quickly calculate which days to add to org-class. It takes two dates and a day of week (dow), returning the iso weeks in which the day of the week falls within the diary block. --8<---------------cut here---------------start------------->8--- (defun my-calculate-skip-weeks (date1 date2 dow) (let ((d1 (calendar-absolute-from-gregorian date1)) (d2 (calendar-absolute-from-gregorian date2)) (iso-weeks)) (while (< d1 d2) (let ((iso-date (calendar-iso-from-absolute d1))) (when (eq (nth 1 iso-date) dow) (add-to-list 'iso-weeks (car (calendar-iso-from-absolute d1)) t))) (setq d1 (1+ d1))) iso-weeks)) --8<---------------cut here---------------end--------------->8--- Using the diary block information above and taking Wednesday as the day of the week, the function yields the days of the week to add as SKIP-WEEKS in org-class: (my-calculate-skip-weeks '(10 17 2015) '(11 1 2015) 3) =3D> (43 44) Based on this information, the org-class sexp could be written like this: %%(org-class 2015 9 15 2015 12 20 3 43 44) My class Obviously this would need to be scripted. But I hope these ideas help. Matt