Discordian date: Difference between revisions

→‎Icon and Unicon: and clearly the Discordians had something to say about the end of the Mayan Calendar!
(→‎Icon and Unicon: and clearly the Discordians had something to say about the end of the Mayan Calendar!)
Line 634:
*Main> :! ddate 2 9 2010
Setting Orange, Bureaucracy 26, 3176 YOLD</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
This version is loosely based on a modified translation of the original ddate.c and like the original the leap year functionality is Julian not Gregorian.
<lang Icon>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</lang>
 
Output:<pre>2010-1-1 = Sweetmorn, day 1 of Chaos in the YOLD 3176
2010-7-22 = Pungenday, day 57 of Confusion in the YOLD 3176
2012-2-28 = Prickle-Prickle, day 59 of Chaos in the YOLD 3178
2012-2-29 = St. Tib's Day, in the YOLD 3178
2012-3-1 = Setting Orange, day 60 of Chaos in the YOLD 3178
2010-1-5 = Mungday, in the YOLD 3176
2011-5-3 = Discoflux, in the YOLD 3177
2012-2-28 = Prickle-Prickle, day 59 of Chaos in the YOLD 3178
2012-2-29 = St. Tib's Day, in the YOLD 3178
2012-3-1 = Setting Orange, day 60 of Chaos in the YOLD 3178
2010-7-22 = Pungenday, day 57 of Confusion in the YOLD 3176
2012-12-22 = Sweetmorn, day 64 of The Aftermath in the YOLD 3178</pre>
 
=={{header|J}}==
Anonymous user