Discordian date: Difference between revisions

no edit summary
No edit summary
Line 223:
Setting Orange, day 26 of Bureaucracy in the YOLD 3178
Setting Orange, day 73 of The Aftermath in the YOLD 3178</pre>
 
=={{header|AppleScript}}==
 
<lang applescript>on gregorianToDiscordian(inputDate) -- Input: AppleScript date object.
(* Rules:
Discordian weeks have five days each and always start at the beginning of the year. There are seventy-three in a year. (73 * 5 = 365.)
Discordian seasons have seventy-three days each. There are five of them in a year.
In leap years, an extra day called "St. Tib's Day" is inserted between days 59 and 60, the same slot as the Gregorian 29th February. It's considered to be outside the Discordian week and season, so the day after it is Setting Orange, Chaos 60, not Sweetmorn, Chaos 61. Discordian dates always correspond to particular Gregorian dates.
Year 1 YOLD is 1166 BC.
This handler is only guaranteed for AD Gregorian dates and it's the calling process's responsibility to convert any user text input from the user's format to an AS date object.
Since the Discordian calendar is an American invention, this handler's output is in the US style: "Weekday, Season day, year".
*)
-- Calculate the input date's day-of-year number.
copy inputDate to startOfYear
tell startOfYear to set {its day, its month} to {1, January}
set dayOfYear to (inputDate - startOfYear) div days + 1
-- If it's a leap year, special-case St. Tib's Day, or adjust the day-of-year number if the day comes after that.
set y to inputDate's year
if ((y mod 4 is 0) and ((y mod 100 > 0) or (y mod 400 is 0))) then
if (dayOfYear is 60) then
set dayOfYear to "St. Tib's Day"
else if (dayOfYear > 60) then
set dayOfYear to dayOfYear - 1
end if
end if
-- Start the output text with either "St. Tib's Day" or the weekday, season, and day-of-season number.
if (dayOfYear is "St. Tib's Day") then
set outputText to dayOfYear
else
tell dayOfYear - 1
set dayOfWeek to it mod 5 + 1
set seasonNumber to it div 73 + 1
set dayOfSeason to it mod 73 + 1
end tell
set theWeekdays to {"Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"}
set theSeasons to {"Chaos ", "Discord ", "Confusion ", "Bureaucracy ", "The Aftermath "}
set outputText to (item dayOfWeek of theWeekdays) & ", " & (item seasonNumber of theSeasons) & dayOfSeason
end if
-- Append the Discordian year number and return the result.
return outputText & ", " & (y + 1166)
end gregorianToDiscordian
 
set gregorianDate to (current date)'s date string
set ASDate to date gregorianDate
set discordianDate to gregorianToDiscordian(ASDate)
return {Gregorian:gregorianDate, Discordian:discordianDate}</lang>
 
{{output}}
<pre>{Gregorian:"Tuesday 25 February 2020", Discordian:"Sweetmorn, Chaos 56, 3186"}</pre>
 
=={{header|AWK}}==
557

edits