module Data.DDate(DDateTime,
DDate,
Yold,
Season,
Day,
weekdays,
seasons,
fluxes,
holydays,
yold,
convertSeason,
convertDay,
holyday,
convertDateTime,
convertDate,
ddateToDDateTime,
ddateTimeToDDate,
)
where
import Data.Dates (DateTime(DateTime), getCurrentDateTime)
import Data.Time.Calendar (isLeapYear)
data DDatable = DT DDateTime
| D DDate
data DDateTime = DDateTime {
year :: Yold,
season :: Season,
day :: Day,
hour :: Int,
minute :: Int,
second :: Int
}
deriving (Eq, Ord)
instance Show DDateTime where
show (DDateTime y s d h m sec) =
show (DDate y s d) ++ ", " ++ pad(show h) ++ ":" ++
pad (show m) ++ ":" ++ pad (show sec)
where pad s = replicate (2 (length s)) '0' ++ s
data DDate = DDate {
y :: Yold,
s :: Season,
d :: Day
}
instance Show DDate where
show (DDate y s d@(Day dayval)) =
show d ++ ", " ++ show s ++ " the " ++ dayofmonth dayval ++
", " ++ show y ++ " YOLD"
type Yold = Int
data Season = Season Int
deriving (Eq, Ord)
instance Show Season where
show (Season s) = seasons !! s
data Day = Day Int
deriving (Eq, Ord)
instance Show Day where
show (Day d) = weekdays !! (weekday d)
weekdays :: [String]
weekdays = [ "Sweetmorn"
, "Boomtime"
, "Pungenday"
, "Prickle-Prickle"
, "Setting Orange"
]
seasons :: [String]
seasons = [ "Chaos"
, "Discord"
, "Confusion"
, "Bureacracy"
, "The Aftermath"
]
fluxes :: [String]
fluxes = [ "Chaoflux"
, "Discoflux"
, "Confuflux"
, "Bureflux"
, "Afflux"
]
holydays :: [String]
holydays = [ "Mungday"
, "Mojoday"
, "Syaday"
, "Zaraday"
, "Maladay"
]
convertSeason :: Int -> Season
convertSeason x = Season $ quot x 73
weekday :: Int -> Int
weekday x = rem x 5
convertDay :: Int -> Day
convertDay x = Day $ rem x 73
dayofmonth :: Int -> String
dayofmonth x =
if day > 3 && day < 21
then sday ++ "th"
else case mod day 10 of
1 -> sday ++ "st"
2 -> sday ++ "nd"
3 -> sday ++ "rd"
_ -> sday ++ "th"
where day = rem x 73
sday = show $ day
yold :: Int -> Yold
yold year = (year + 1166)
holyday' :: Int -> String
holyday' day
| rem day 73 == 50 =
printHoly holydays day
| rem day 73 == 5 =
printHoly fluxes day
| otherwise = ""
where printHoly l x = "\nCelebrate " ++ l !! quot x 73 ++ "!"
holyday :: DDatable -> String
holyday (DT (DDateTime _ _ (Day d) _ _ _)) = holyday' d
holyday (D (DDate _ _ (Day d))) = holyday' d
monthdays :: [Int]
monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
convertDateTime :: DateTime -> DDateTime
convertDateTime dt@(DateTime y m d h min s) =
let totalDays = d + sum (take (m 1) monthdays)
in DDateTime (yold y) (convertSeason totalDays) (convertDay totalDays) h min s
convertDate :: DateTime -> DDate
convertDate dt@(DateTime y m d _ _ _) =
let totalDays = d + sum (take (m 1) monthdays)
in DDate (yold y) (convertSeason totalDays) (convertDay totalDays)
ddateToDDateTime :: DDate -> DDateTime
ddateToDDateTime (DDate y s d) = DDateTime y s d 0 0 0
ddateTimeToDDate :: DDateTime -> DDate
ddateTimeToDDate (DDateTime y s d _ _ _) = DDate y s d
currentDDateTime :: IO DDateTime
currentDDateTime = do
dt <- getCurrentDateTime
return $ convertDateTime dt