aboutsummaryrefslogtreecommitdiff
path: root/Data/ConfigManager/Instances.hs
diff options
context:
space:
mode:
authorJoris2016-03-26 20:29:15 +0100
committerJoris2016-03-26 20:29:36 +0100
commit2e411664ce8da96fd50340b1ecb9e6e2e16f6ca2 (patch)
tree4d9399723a470a2fcd24b1df05aeb481468492de /Data/ConfigManager/Instances.hs
parent88aef982ff7a1be7fba2abf7264773b511608404 (diff)
Parse durations
Diffstat (limited to 'Data/ConfigManager/Instances.hs')
-rw-r--r--Data/ConfigManager/Instances.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/Data/ConfigManager/Instances.hs b/Data/ConfigManager/Instances.hs
new file mode 100644
index 0000000..0855117
--- /dev/null
+++ b/Data/ConfigManager/Instances.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE UndecidableInstances #-}
+{-# LANGUAGE IncoherentInstances #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Data.ConfigManager.Instances
+ () where
+
+import qualified Data.Text as T
+import Data.Time.Clock (DiffTime, NominalDiffTime)
+
+import Text.Read (readMaybe)
+
+import Data.ConfigManager.Types.Internal
+import Data.ConfigManager.Parser.Duration (parseDuration)
+
+instance Configured DiffTime where
+ convert value = parseDuration value
+
+instance Configured NominalDiffTime where
+ convert value = realToFrac <$> parseDuration value
+
+instance Read a => Configured a where
+ convert = readMaybe . T.unpack