The Ada Program: dow.adb

  1 -- today.adb:  print today's date using "Ada.Calendar" package
  2 
  3 with Ada.Text_IO, Ada.Calendar;
  4 use Ada;
  5 
  6 procedure DoW is
  7 
  8    Now        : Calendar.Time := Calendar.Clock;
  9    Year       : Calendar.Year_Number;
 10    Month      : Calendar.Month_Number;
 11    Day        : Calendar.Day_Number;
 12    Seconds    : Calendar.Day_Duration;
 13    Century    : Integer;
 14    Day_Of_Week: Integer;
 15 
 16 begin
 17 
 18    Calendar.Split (Now, Year, Month, Day, Seconds);
 19 
 20    if Month<3 then
 21       Year  := Year-1;
 22       Month := Month+10;
 23    else
 24       Month := Month-2;
 25    end if;
 26 
 27    Century := Year/100;
 28    Day_Of_Week := ((26*Month - 2)/10 + Day + (Year mod 100)/4 + Century/4 - 2*Century) mod 7;
 29 
 30    if Day_Of_Week = 5 then
 31       for I in 1..25 loop
 32          Text_IO.Put_Line ("TGIF!");
 33       end loop;
 34    end if;
 35 
 36 end DoW;