Skip to content

Commit

Permalink
rename isWeekend to todayIsWeekend, add isWeekend (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
hendi authored Jun 24, 2020
1 parent 6989a66 commit 00757e5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions IHP/HaskellSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module IHP.HaskellSupport (
, forEach
, textToInt
, isWeekend
, todayIsWeekend
, debug
) where

Expand Down Expand Up @@ -180,12 +181,26 @@ textToInt text = case Attoparsec.parseOnly (Attoparsec.decimal <* Attoparsec.end
-- > do
-- > todayIsWeekend <- isWeekend
-- > when todayIsWeekend (putStrLn "It's weekend!")
isWeekend :: IO Bool
isWeekend = do
todayIsWeekend :: IO Bool
todayIsWeekend = do
now <- Data.Time.getCurrentTime
let today = Data.Time.utctDay now
let weekday = Data.Time.dayOfWeek today
return ((weekday == Data.Time.Saturday) || (weekday == Data.Time.Sunday))
return (isWeekend today)

-- | Returns @True@ when day is Saturday or Sunday.
--
-- __Example:__
--
-- >>> isWeekend $ fromGregorian 2019 10 7
-- False
--
-- >>> isWeekend $ fromGregorian 2020 6 13
-- True
isWeekend :: Day -> Bool
isWeekend day =
weekday == Data.Time.Saturday || weekday == Data.Time.Sunday
where
weekday = Data.Time.dayOfWeek day

-- | Debug-print a value during evaluation
--
Expand Down

0 comments on commit 00757e5

Please sign in to comment.