

Task

Convert a given date from the   Gregorian calendar   to the   Discordian calendar.




$ include "seed7_05.s7i";
  include "time.s7i";
 
const array string: seasons is [0] ("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath");
const array string: weekday is [0] ("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
const array string: apostle is [0] ("Mungday", "Mojoday", "Syaday", "Zaraday",  "Maladay");
const array string: holiday is [0] ("Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux");
 
const func string: discordianDate (in time: date) is func
  result
    var string: discordianDate is "";
  local
    var integer: dyear is 0;
    var integer: doy is 0;
    var integer: dsday is 0;
  begin
    dyear := date.year + 1166;
    if isLeapYear(date.year) and date.month = 2 and date.day = 29 then
      discordianDate := "St. Tib's Day, in the YOLD " <& dyear;
    else
      doy := dayOfYear(date);
      if isLeapYear(date.year) and doy >= 60 then
        decr(doy);
      end if;
      dsday := doy rem 73; # season day
      if dsday = 5 then
        discordianDate := apostle[doy div 73] <& ", in the YOLD " <& dyear;
      elsif dsday = 50 then
        discordianDate := holiday[doy div 73] <& ", in the YOLD " <& dyear;
      else
        discordianDate := weekday[pred(doy) rem 5] <&
                          ", day " <& dsday <&
                          " of " <& seasons[doy div 73] <&
                          " in the YOLD " <& dyear;
      end if;
    end if;
  end func;
 
const proc: main is func
  local
    var time: today is time.value;
  begin
    today := time(NOW);
    writeln(strDate(today) <& " as Discordian date: " <& discordianDate(today));
    if  discordianDate(date(2010, 7, 22)) = "Pungenday, day 57 of Confusion in the YOLD 3176" and
        discordianDate(date(2012, 2, 28)) = "Prickle-Prickle, day 59 of Chaos in the YOLD 3178" and
        discordianDate(date(2012, 2, 29)) = "St. Tib's Day, in the YOLD 3178" and
        discordianDate(date(2012, 3,  1)) = "Setting Orange, day 60 of Chaos in the YOLD 3178" and
        discordianDate(date(2010, 1,  5)) = "Mungday, in the YOLD 3176" and
        discordianDate(date(2011, 5,  3)) = "Discoflux, in the YOLD 3177" then
      writeln("Discordian date computation works.");
    end if;
  end func;