diff options
author | Joris | 2019-09-05 20:46:36 +0200 |
---|---|---|
committer | Joris | 2019-09-05 20:46:36 +0200 |
commit | 317e7b1e7319182e5caa5169119aea9fc8d660b6 (patch) | |
tree | dc9f9c458c42d1e2c60a12ff55267e042c88f6ba /src/lib/haskell/Utils | |
parent | 223ae6aa0b14c071d5719ada0cc6b43e9199a81b (diff) |
Enable the listener only during some hours
Diffstat (limited to 'src/lib/haskell/Utils')
-rw-r--r-- | src/lib/haskell/Utils/Time.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/haskell/Utils/Time.hs b/src/lib/haskell/Utils/Time.hs new file mode 100644 index 0000000..88aeeb6 --- /dev/null +++ b/src/lib/haskell/Utils/Time.hs @@ -0,0 +1,29 @@ +module Utils.Time + ( getCurrentFormattedTime + , asleepDuration + ) where + +import Data.Text (Text) +import qualified Data.Text as T +import Data.Time.Clock (DiffTime) +import qualified Data.Time.Clock as Clock +import qualified Data.Time.Format as Format +import qualified Data.Time.LocalTime as LocalTime + +getCurrentFormattedTime :: IO Text +getCurrentFormattedTime = do + zonedTime <- LocalTime.getZonedTime + return (T.pack $ Format.formatTime Format.defaultTimeLocale "%Hh%M" zonedTime) + +asleepDuration :: DiffTime -> DiffTime -> DiffTime -> Maybe DiffTime +asleepDuration from to t = + if t < from && from < to then + Just $ from - t + else if t > to && to > from then + Just $ day - t + from + else if t > to && t < from then + Just $ from - t + else + Nothing + where + day = (realToFrac Clock.nominalDay) :: DiffTime |