aboutsummaryrefslogtreecommitdiff
path: root/src/lib/haskell/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/haskell/Utils')
-rw-r--r--src/lib/haskell/Utils/Time.hs29
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