aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJoris2018-01-28 12:13:09 +0100
committerJoris2018-06-11 12:28:29 +0200
commit33b85b7f12798f5762d940ed5c30f775cdd7b751 (patch)
treedaf8cfb7b0a16b2fce65848fc0ca2831f33a0701 /common
parentab17b6339d16970c3845ec4f153bfeed89eae728 (diff)
WIP
Diffstat (limited to 'common')
-rw-r--r--common/common.cabal1
-rw-r--r--common/src/Common/Model/CreatePayment.hs3
-rw-r--r--common/src/Common/Model/InitResult.hs3
-rw-r--r--common/src/Common/Util/Time.hs26
4 files changed, 31 insertions, 2 deletions
diff --git a/common/common.cabal b/common/common.cabal
index 7eadb49..6e5c8fb 100644
--- a/common/common.cabal
+++ b/common/common.cabal
@@ -29,6 +29,7 @@ Library
Common.Model
Common.Msg
Common.Util.Text
+ Common.Util.Time
Common.View.Format
other-modules:
diff --git a/common/src/Common/Model/CreatePayment.hs b/common/src/Common/Model/CreatePayment.hs
index 8e2ab73..cd0b01d 100644
--- a/common/src/Common/Model/CreatePayment.hs
+++ b/common/src/Common/Model/CreatePayment.hs
@@ -2,7 +2,7 @@ module Common.Model.CreatePayment
( CreatePayment(..)
) where
-import Data.Aeson (FromJSON)
+import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)
import Data.Time.Calendar (Day)
import GHC.Generics (Generic)
@@ -19,3 +19,4 @@ data CreatePayment = CreatePayment
} deriving (Show, Generic)
instance FromJSON CreatePayment
+instance ToJSON CreatePayment
diff --git a/common/src/Common/Model/InitResult.hs b/common/src/Common/Model/InitResult.hs
index 542e6c7..f4c08a9 100644
--- a/common/src/Common/Model/InitResult.hs
+++ b/common/src/Common/Model/InitResult.hs
@@ -10,7 +10,8 @@ import Common.Model.Init (Init)
data InitResult =
InitSuccess Init
- | InitEmpty (Either Text (Maybe Text))
+ | InitError Text
+ | InitEmpty
deriving (Show, Generic)
instance FromJSON InitResult
diff --git a/common/src/Common/Util/Time.hs b/common/src/Common/Util/Time.hs
new file mode 100644
index 0000000..9ab7ab5
--- /dev/null
+++ b/common/src/Common/Util/Time.hs
@@ -0,0 +1,26 @@
+module Common.Util.Time
+ ( timeToDay
+ , parseDay
+ ) where
+
+import Data.Text (Text)
+import qualified Data.Text as T
+import Data.Time (UTCTime)
+import qualified Data.Time as Time
+import Data.Time.Calendar (Day)
+import Data.Time.LocalTime
+import qualified Text.Read as T
+
+timeToDay :: UTCTime -> IO Day
+timeToDay time = localDay . (flip utcToLocalTime time) <$> getTimeZone time
+
+parseDay :: Text -> Maybe Day
+parseDay str = do
+ (d, m, y) <-
+ case T.splitOn str "/" of
+ [d, m, y] -> Just (d, m, y)
+ _ -> Nothing
+ d' <- T.readMaybe . T.unpack $ d
+ m' <- T.readMaybe . T.unpack $ m
+ y' <- T.readMaybe . T.unpack $ y
+ return $ Time.fromGregorian y' m' d'