module TimeSpec (spec) where import Data.Time.Clock (DiffTime) import qualified Data.Time.Clock as Clock import Test.Hspec import qualified Utils.Time as TimeUtils spec :: Spec spec = describe "Utils.Time" $ describe "asleepDuration" $ do it "should not be asleep in range" $ do TimeUtils.asleepDuration (hour 8) (hour 22) (hour 15) `shouldBe` Nothing it "should not be asleep in day overlapping range" $ do TimeUtils.asleepDuration (hour 22) (hour 8) (hour 6) `shouldBe` Nothing it "should be asleep before the range" $ do TimeUtils.asleepDuration (hour 10) (hour 12) (hour 6) `shouldBe` Just (hour 4) it "should be asleep after the range" $ do TimeUtils.asleepDuration (hour 10) (hour 14) (hour 15) `shouldBe` Just (hour 19) it "should be asleep before a day overlapping range" $ do TimeUtils.asleepDuration (hour 23) (hour 1) (hour 3) `shouldBe` Just (hour 20) hour :: Int -> DiffTime hour h = Clock.secondsToDiffTime (fromIntegral h * 60 * 60)