summaryrefslogtreecommitdiff
path: root/Model/Types.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-16 13:18:34 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-16 13:18:34 +0100
commit57d594818c14652681dce54d324b6b76941b2f4e (patch)
treef3e1e02e2fa41ff0d87eace034d6c883668841c5 /Model/Types.hs
parent3d828feba67f21ae62d1e6eb598a22ffaebf1174 (diff)
parent3bfe0bdcb79b398a387e202c5150b5e6fd230d3a (diff)
downloadbar-57d594818c14652681dce54d324b6b76941b2f4e.tar
bar-57d594818c14652681dce54d324b6b76941b2f4e.tar.gz
bar-57d594818c14652681dce54d324b6b76941b2f4e.tar.bz2
bar-57d594818c14652681dce54d324b6b76941b2f4e.tar.xz
bar-57d594818c14652681dce54d324b6b76941b2f4e.zip
Merge branch 'feat/openYes'
Diffstat (limited to 'Model/Types.hs')
-rw-r--r--Model/Types.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/Model/Types.hs b/Model/Types.hs
new file mode 100644
index 0000000..61bebfd
--- /dev/null
+++ b/Model/Types.hs
@@ -0,0 +1,35 @@
1{-# LANGUAGE DeriveGeneric #-}
2
3module Model.Types
4 ( ItemDate(..)
5 , isNever, isUnknown, isKnown
6 ) where
7
8import ClassyPrelude.Yesod
9
10data ItemDate = DateUnknown | DateKnown Day | DateNever
11 deriving (Eq, Ord, Show, Read, Generic)
12
13isNever, isUnknown, isKnown :: ItemDate -> Bool
14isNever DateNever = True
15isNever _ = False
16isUnknown DateUnknown = True
17isUnknown _ = False
18isKnown (DateKnown _) = True
19isKnown _ = False
20
21unknownVerb :: IsString a => a
22unknownVerb = "unknown"
23
24instance ToJSON ItemDate where
25 toJSON DateNever = Null
26 toJSON DateUnknown = String unknownVerb
27 toJSON (DateKnown d) = toJSON d
28instance FromJSON ItemDate where
29 parseJSON Null = pure DateNever
30 parseJSON v@(String inp)
31 | unknownVerb == inp = pure DateUnknown
32 | otherwise = DateKnown <$> parseJSON v
33 parseJSON v = DateKnown <$> parseJSON v
34
35derivePersistFieldJSON "ItemDate"