Discordian date: Difference between revisions

D entry: updated and shortened lines
(D entry: updated and shortened lines)
Line 351:
<lang d>import std.stdio, std.datetime, std.conv, std.string;
 
string discordianDate(in Date date) /*pure nothrow*/ {
immutable seasons = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"];
static immutable weekdayseasons = ["SweetmornChaos", "BoomtimeDiscord", "PungendayConfusion", "Prickle-Prickle", "Setting Orange"];
"Bureaucracy", "The Aftermath"];
immutable apostle = ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"];
static immutable holidayweekday = ["ChaofluxSweetmorn", "DiscofluxBoomtime", "ConfufluxPungenday", "Bureflux", "Afflux"];
"Prickle-Prickle", "Setting Orange"];
static immutable apostle = ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"];
"Zaraday", "Maladay"];
static immutable holiday = ["Chaoflux", "Discoflux", "Confuflux",
"Bureflux", "Afflux"];
 
autoimmutable dyear = to!stringtext(date.year + 1166);
string discordianDate(in Date date) {
auto dyear = to!string(date.year + 1166);
 
autoimmutable isLeapYear = date.isLeapYear;
if (isLeapYear && date.month == 2 && date.day == 29)
return "St. Tib's Day, in the YOLD " ~ dyear;
 
autoimmutable doy = (isLeapYear && date.dayOfYear; >= 60) ?
date.dayOfYear - 1 :
if (isLeapYear && doy >= 60)
doy-- date.dayOfYear;
 
autoimmutable dsday = doy % 73; // season day
if (dsday == 5) return apostle[doy / 73] ~ ", in the YOLD " ~ dyear;
if (dsday == 50) return holidayapostle[doy / 73] ~ ", in the YOLD " ~ dyear;
if (dsday == 50)
return holiday[doy / 73] ~ ", in the YOLD " ~ dyear;
 
autoimmutable dseas = seasons[doy / 73];
autoimmutable dwday = weekday[(doy - 1) % 5];
 
return format("%s, day %s of %s in the YOLD %s", dwday, dsday, dseas, dyear);
dwday, dsday, dseas, dyear);
<lang} d>unittest {
assert(discordianDate(Date(2010,17, 522)) == "Mungday, in the YOLD 3176");
assert(discordianDate(Date(2010,7,22)) == "Pungenday, day 57 of Confusion in the YOLD 3176");
assert(discordianDate(Date(2012,2,2928)) == "St. Tib's Day, in the YOLD 3178");
assert(discordianDate(Date(2012,2,28)) == "Prickle-Prickle, day 59 of Chaos in the YOLD 3178");
assert(discordianDate(Date(20112012,52, 329)) == "Discoflux, in the YOLD 3177");
"St. Tib's Day, in the YOLD 3178");
assert(discordianDate(Date(2012,3, 1)) == "Setting Orange, day 60 of Chaos in the YOLD 3178");
"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");
}
 
void main() {
autoimmutable today = cast(Date)Clock.currTime();
auto ddate = writeln(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>
{{out}}
<pre>Setting Orange, day 42 of Discord in the YOLD 3178</pre>
 
=={{header|Euphoria}}==