Discordian date: Difference between revisions
Content added Content deleted
(→{{header|C}}: added D) |
|||
Line 179: | Line 179: | ||
Confusion 57, YOLD 3176 |
Confusion 57, YOLD 3176 |
||
</pre> |
</pre> |
||
=={{header|D}}== |
|||
<lang d>import std.stdio, std.datetime, std.conv, std.string; |
|||
immutable seasons = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]; |
|||
immutable weekday = ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"]; |
|||
immutable apostle = ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"]; |
|||
immutable holiday = ["Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"]; |
|||
string discordianDate(Date date) { |
|||
auto dyear = to!string(date.year + 1166); |
|||
auto isLeapYear = date.isLeapYear; |
|||
if (isLeapYear && date.month == 2 && date.day == 29) |
|||
return "St. Tib's Day, in the YOLD " ~ dyear; |
|||
auto dday = date.dayOfYear - 1; |
|||
if (isLeapYear && dday >= 60) |
|||
dday--; |
|||
auto indx = dday / 73; |
|||
auto seas = seasons[indx]; |
|||
auto wday = weekday[dday % 5]; |
|||
auto sday = dday % 73 + 1; // season day |
|||
if (sday == 5) return apostle[indx] ~ ", in the YOLD " ~ dyear; |
|||
if (sday == 50) return holiday[indx] ~ ", in the YOLD " ~ dyear; |
|||
return format("%s, day %s of %s in the YOLD %s", wday, sday, seas, dyear); |
|||
} |
|||
void main() { |
|||
auto today = cast(Date)Clock.currTime(); |
|||
auto ddate = discordianDate(today); |
|||
writeln(ddate); |
|||
} |
|||
</lang> |
|||
<lang d>unittest { |
|||
assert(discordianDate(Date(2010,7,22)) == "Pungenday, day 57 of Confusion in the YOLD 3176"); |
|||
assert(discordianDate(Date(2012,2,28)) == "Prickle-Prickle, day 59 of Chaos in the YOLD 3178"); |
|||
assert(discordianDate(Date(2012,2,29)) == "St. Tib's Day, in the YOLD 3178"); |
|||
assert(discordianDate(Date(2012,3, 1)) == "Setting Orange, day 60 of Chaos in the YOLD 3178"); |
|||
assert(discordianDate(Date(2010,1, 5)) == "Mungday, in the YOLD 3176"); |
|||
assert(discordianDate(Date(2011,5, 3)) == "Discoflux, in the YOLD 3177"); |
|||
}</lang> |
|||
=={{header|F#}}== |
=={{header|F#}}== |