A posting from Coen in the NF Integration forum (subject Active X) brought me to the idea to post this routine for calculating Holidays. Now you will say, “what’s the problem? Christmas is always December 25th”. Right! But what about days like Eastern (and depending holidays) which depend on the moon-phase? Right, it is possible to calculate moon phases in Navision. Quite compliated but nevertheless possible as I’m going to proove here. First note: If you are Swiss, German or Austrian, don’t use the routines posted here as plain text. You might instead download the zipped object in the German forum which calculates all holidays for the German speaking countries. Second and last note: The procedure EasterSunday is only valid to the year 8000. —

```
Procedure EasterSunday(CalendarYear : Integer) : Date;
Begin
JH := CalendarYear DIV 100;
J := CalendarYear MOD 100;
a := CalendarYear MOD 19;
b := CalendarYear MOD 4;
c := CalendarYear MOD 7;
P := (15 + JH - JH DIV 3 - JH DIV 4) MOD 30;
Q := (JH - JH DIV 4 + 4) MOD 7;
d := (19 * a + P) MOD 30;
e := (2 * b + 4 * c + 6 * d + Q) MOD 7;
IF (d = 29) AND (e = 6) THEN
k := 50 { Exception 1: --> 19th April }
ELSE
IF (d = 28) AND (e = 6) AND (a > 10) THEN
k := 49 { Exception 2: --> 18th April }
ELSE
k := 22 + d + e;
IF k <= 31 THEN
exit(DMY2DATE (k,3,100*JH+J))
ELSE
exit(DMY2DATE (k-31,4,100*JH+J));
End;
---
... or what about calculating mother-day, the second sunday in May 2001?
--> GetFactor(2,7,5,2001) ; speak: (second, sunday, may, 2001)
Procedure GetFactor(Which : Integer; DayOfWeek : Integer; Month : Integer; Year : Integer);
Begin
// Which --> 0 = Last, 1 = first day .... , 2 = second DayOfWeek in month
// DayOfWeek --> 1 = monday, 7 = sunday
locDate := DMY2DATE(1,Month ,Year );
locW := DATE2DWY (locDate,1);
IF (locW = 0) THEN
locW := 7;
IF (Which = 0) THEN BEGIN
locDate := CALCDATE(STRSUBSTNO('+%1D',35+DayOfWeek -locW));
IF DATE2DMY(locDate,2) = Month THEN
Which := 5
ELSE
Which := 4
END;
IF (locW <= DayOfWeek ) THEN
Which := Which - 1;
EXIT (CALCDATE (STRSUBSTNO('+%1D',7*Which +DayOfWeek -locW),DMY2DATE(1,Month ,Year )));
```

— Hope you enjoy it! Marcus Fabian m.fabian@thenet.ch