From 2e411664ce8da96fd50340b1ecb9e6e2e16f6ca2 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 26 Mar 2016 20:29:15 +0100 Subject: Parse durations --- Data/ConfigManager/Instances.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Data/ConfigManager/Instances.hs (limited to 'Data/ConfigManager/Instances.hs') 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 -- cgit v1.2.3