module Monky.Examples.Time
( getTimeHandle
, getFancyTimeHandle
, THandle
, FTHandle
)
where
import Formatting
import qualified Data.Text as T
import Control.Arrow ((***))
import Monky.Modules
import Monky.Time hiding (getTimeHandle)
import qualified Monky.Time as MT (getTimeHandle)
newtype THandle = TH TimeHandle
getTimeHandle :: String
-> IO THandle
getTimeHandle = fmap TH . MT.getTimeHandle
instance PollModule THandle where
getOutput (TH h) = do
ts <- getTime h
return
[ MonkyImage "clock" '🕐'
, MonkyPlain $ T.pack ts
]
timeToXBM :: (Int, Int) -> (Int, Int)
timeToXBM = (`mod` 12) *** (`div` 15)
newtype FTHandle = FTH TimeHandle
getFancyTimeHandle :: String
-> IO FTHandle
getFancyTimeHandle = fmap FTH . MT.getTimeHandle
instance PollModule FTHandle where
getOutput (FTH h) = do
ts <- getTime h
t <- getHM h
let (th, tm) = timeToXBM t
return
[ MonkyImage (sformat (int % "-" % int) th tm) '🕐'
, MonkyPlain . T.pack $ ts
]