aboutsummaryrefslogtreecommitdiff
path: root/src/test/haskell/TimeSpec.hs
diff options
context:
space:
mode:
authorJoris2019-09-05 20:46:36 +0200
committerJoris2019-09-05 20:46:36 +0200
commit317e7b1e7319182e5caa5169119aea9fc8d660b6 (patch)
treedc9f9c458c42d1e2c60a12ff55267e042c88f6ba /src/test/haskell/TimeSpec.hs
parent223ae6aa0b14c071d5719ada0cc6b43e9199a81b (diff)
downloadad-listener-317e7b1e7319182e5caa5169119aea9fc8d660b6.tar.gz
ad-listener-317e7b1e7319182e5caa5169119aea9fc8d660b6.tar.bz2
ad-listener-317e7b1e7319182e5caa5169119aea9fc8d660b6.zip
Enable the listener only during some hours
Diffstat (limited to 'src/test/haskell/TimeSpec.hs')
-rw-r--r--src/test/haskell/TimeSpec.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/haskell/TimeSpec.hs b/src/test/haskell/TimeSpec.hs
new file mode 100644
index 0000000..4248e68
--- /dev/null
+++ b/src/test/haskell/TimeSpec.hs
@@ -0,0 +1,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)