Discordian date: Difference between revisions

+Haskell
(→‎{{header|PureBasic}}: Added PureBasic)
(+Haskell)
Line 3:
'''See Also'''
* [[wp:Discordian calendar|Discordian calendar (wiki)]]
 
=={{header|Haskell}}==
<lang haskell>import Data.List
import Data.Time
import Data.Time.Calendar.MonthDay
import System.Locale
 
seasons = words "Chaos Discord Confusion Bureaucracy The_Aftermath"
 
discordianDate (y,m,d) = do
let doy = monthAndDayToDayOfYear (isLeapYear y) m d
(season, dday) = divMod doy 73
dDate
| isLeapYear y && m==2 && d==29 = "St. Tib's Day, " ++ show (y+1166) ++ " YOLD"
| otherwise = seasons!!season ++ " " ++ show dday ++ ", " ++ show (y+1166) ++ " YOLD"
putStrLn dDate
</lang>
Examples:
<pre>*Main> mapM_ discordianDate [(2012,2,28),(2012,2,29),(2010,9,2),(2010,12,6)]
Chaos 59, 3178 YOLD
St. Tib's Day, 3178 YOLD
Bureaucracy 26, 3176 YOLD
The_Aftermath 48, 3176 YOLD</pre>
In GHCi we can also execute shell commands.
* Using Linux utility ddate
<pre>*Main> :! ddate
Today is Setting Orange, the 26th day of Bureaucracy in the YOLD 3176
 
*Main> :! ddate 29 2 2012
Sint Tibs
 
*Main> :! ddate 2 9 2010
Setting Orange, Bureaucracy 26, 3176 YOLD</pre>
 
=={{header|J}}==
Anonymous user