emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] using holiday dates from an ICAL calendar


From: Matt Lundin
Subject: Re: [O] using holiday dates from an ICAL calendar
Date: Wed, 12 Aug 2015 16:37:49 -0500
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Julien Cubizolles <address@hidden> 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%40import.calendar.google.com/public/basic.ics).

> Did somebody ever try it ?

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, 
Orléans-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 12 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) => (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]