

Task

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




with javascript_semantics
constant seasons = {"Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"},
         weekday = {"Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"},
         apostle = {"Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"},
         holiday = {"Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"}
 
function discordianDate(sequence dt)
    integer {y,m,d} = dt, 
            leap = is_leap_year(y),
            doy = day_of_year(y,m,d)-1
    string dyear = sprintf("%d",y+1166)
    if leap and m=2 and d=29 then
        return "St. Tib's Day, in the YOLD " & dyear
    end if
    if leap and doy>=60 then
        doy -= 1
    end if
    integer dsday = remainder(doy,73)+1,
            dseason = floor(doy/73+1)
    if dsday=5 then
        return apostle[dseason] & ", in the YOLD " & dyear
    elsif dsday=50 then
        return holiday[dseason] & ", in the YOLD " & dyear
    end if
    string dseas = seasons[dseason],
           dwday = weekday[remainder(doy,5)+1]
    return sprintf("%s, day %d of %s in the YOLD %s", {dwday, dsday, dseas, dyear})
end function

-- test code

sequence dt = {2015,1,1,0,0,0,0,0}
include timedate.e
atom oneday = timedelta(days:=1)
set_timedate_formats({"DD/MM/YYYY"})
for i=1 to 5 do
    printf(1,"%s: %s\n",{format_timedate(dt),discordianDate(dt)})
    dt = adjust_timedate(dt,oneday*72)
    printf(1,"%s: %s\n",{format_timedate(dt),discordianDate(dt)})
    dt = adjust_timedate(dt,oneday)
end for
