Compute moving holidays for iCal

©1998-2003 by Gerald Teschl  <Gerald.Teschl@univie.ac.at>, <http://www.mat.univie.ac.at/~gerald/>

For an official list of public holidays see: <http://www.bmf.gv.at/finanzministerium/gesetzlichefeiertag_4523/>

Evaluate the notebook and save the output of the function at the end into ~/Library/Calendars/AustrianHolydays.ical

Config (You might want to make some changes here)

fixdays: every year on a fixed date. format: {"Name", day, month}
movdays: relative to easter sunday. format: {"Name", shift, duration}

ybegin=2000;
yend=2020;
timezone="Europe/Vienna";
calname="Austrian Holidays";
fixdays={{"Neujahr", 1,1},{"Hl. 3 Könige",6,1},{"Staatsfeiertag",1,5},{"Maria Himmelfahrt",15,8},{"Nationalfeiertag",26,10},{"Allerheiligen",1,11},{"Maria Empfängnis",8,12},{"Christtag",25,12},{"Stefanitag",26,12}};movdays={{"Ostern",0,2},{"Christi Himmelfahrt",39,1},{"Pfingsten",49,2},{"Fronleichnam",60,1}};

Code (No user serviceable parts here;-)

<<"Calendar`"

StringDate[{y_,m_,d_}]:=Block[{dd,mm,yy},
dd=ToString[d];
If[d<10,dd=StringJoin["0",dd]];
mm=ToString[m];
If[m<10,mm=StringJoin["0",mm]];
yy=ToString[y];
StringJoin[yy,mm,dd]
]

PreCal="\<BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:XX-CN
X-WR-TIMEZONE:XX-TZ
CALSCALE:GREGORIAN
\>";
Event="\<BEGIN:VEVENT
DTSTART;VALUE=DATE:YYYYMMDDS
DTEND;VALUE=DATE:YYYYMMDDE
SUMMARY:XXXX
SEQUENCE:1
END:VEVENT
\>";
YearlyEvent="\<BEGIN:VEVENT
DTSTART;VALUE=DATE:YYYYMMDDS
DTEND;VALUE=DATE:YYYYMMDDE
SUMMARY:XXXX
RRULE:FREQ=YEARLY;INTERVAL=1;COUNT=-1
SEQUENCE:1
END:VEVENT
\>";
PostCal="\<END:VCALENDAR
\>";

PrintCalender[]:=Block[{out},
out=StringReplace[PreCal,{"XX-TZ" -> timezone,"XX-CN"->calname}];
Do[
dd=fixdays[[i]][[1]];
ts= {ybegin,fixdays[[i]][[3]],fixdays[[i]][[2]]};
te=DaysPlus[ts,1];
ev=StringReplace[YearlyEvent,{"XXXX"->dd,"YYYYMMDDS"->StringDate[ts],"YYYYMMDDE"->StringDate[te]}];
out=StringJoin[out,ev];
,{i,Length[fixdays]}];
Do[
t=EasterSunday[y];
Do[
dd=movdays[[i]][[1]];
ts=DaysPlus[t,movdays[[i]][[2]] ];
te=DaysPlus[t,movdays[[i]][[2]]+movdays[[i]][[3]]];
ev=StringReplace[Event,{"XXXX"->dd,"YYYYMMDDS"->StringDate[ts],"YYYYMMDDE"->StringDate[te]}];
out=StringJoin[out,ev];
,{i,Length[movdays]}];
,{y,ybegin,yend}];
out=StringJoin[out,PostCal]
]

Do it...

Export[NotebookDirectory[]<>ToString[calname]<>".ics",PrintCalender[],"Text"]