

Task

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




link printf
 
procedure main()
   Demo(2010,1,1)
   Demo(2010,7,22)
   Demo(2012,2,28)
   Demo(2012,2,29)
   Demo(2012,3,1)
   Demo(2010,1,5)
   Demo(2011,5,3)
   Demo(2012,2,28)
   Demo(2012,2,29)
   Demo(2012,3,1)
   Demo(2010,7,22)
   Demo(2012,12,22)
end
 
procedure Demo(y,m,d)      #: demo display 
   printf("%i-%i-%i = %s\n",y,m,d,DiscordianDateString(DiscordianDate(y,m,d)))
end
 
record DiscordianDateRecord(year,yday,season,sday,holiday)
 
procedure DiscordianDate(year,month,day)  #: Convert normal date to Discordian
static  cal
initial cal := [31,28,31,30,31,30,31,31,30,31,30,31]
 
   ddate := DiscordianDateRecord(year+1166)
   every (ddate.yday := day - 1) +:= cal[1 to month-1]   # zero origin
   ddate.sday := ddate.yday
 
   if ddate.year % 4 = 2 &  month = 2 & day = 29 then 
      ddate.holiday := 1   # Note: st tibs is outside of weekdays
   else {
      ddate.season  := (ddate.yday / 73) + 1   
      ddate.sday := (ddate.yday % 73) + 1
      ddate.holiday := 1 + ddate.season * case ddate.sday of { 5 : 1; 50 : 2}    
   }
   return ddate
end
 
procedure DiscordianDateString(ddate)   #: format a Discordian Date String
static days,seasons,holidays
initial {
   days := ["Sweetmorn","Boomtime","Pungenday","Prickle-Prickle","Setting Orange"]
   seasons := ["Chaos","Discord","Confusion","Bureaucracy","The Aftermath"]
   holidays := ["St. Tib's Day","Mungday","Chaoflux","Mojoday","Discoflux",
                "Syaday","Confuflux","Zaraday","Bureflux","Maladay","Afflux"]                     
   }
 
   return (( holidays[\ddate.holiday] || "," ) |
           ( days[1+ddate.yday%5] || ", day " || 
             ddate.sday || " of " || seasons[ddate.season])) ||
          " in the YOLD " || ddate.year
end