blob: 4248e6894b4eea9f000492805bd49e499c5def91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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)
|