The Ada Program: calendar_date.adb
1 -- calendar_date.adb: package with function for day of week
2
3 package body Calendar_Date is
4
5 -- Zeller's congruence
6 -- Sunday is 0, Monday is 1, ..., Saturday is 6.
7
8 function Which_Day (Date: Date_Type) return Day_Of_Week is
9 M: Integer := Month_Name'Pos (Date.Month);
10 Y: Integer := Date.Year;
11 Century: Integer;
12 Day: Integer;
13 begin
14 if M<3 then
15 Y := Y+1;
16 M := M+10;
17 else
18 M := M-2;
19 end if;
20 Century := Y/100; -- first two digits of the year
21 Y := Y mod 100; -- last two digits of the year
22 Day := ((26*M - 2)/10 + Date.Day + Y/4 + Century/4 - 2*Century) mod 7;
23 return (Day_Of_Week'Val(Day));
24 end Which_Day;
25
26 end Calendar_Date;