git.iko.soy/typeable/bloodhound
on master help sign in
TimeInterval Read/Show instances now roundtrip
4553454Dmitry Dzhus
src/Database/Bloodhound/Types.hs+12−1
@@ -305,6 +305,7 @@ import GHC.Enum
305import GHC.Generics (Generic)
305import GHC.Generics (Generic)
306import Network.HTTP.Client
306import Network.HTTP.Client
307import qualified Network.HTTP.Types.Method as NHTM
307import qualified Network.HTTP.Types.Method as NHTM
308+import qualified Text.Read as TR
308
309
309import Database.Bloodhound.Types.Class
310import Database.Bloodhound.Types.Class
310import Database.Bloodhound.Types.Internal
311import Database.Bloodhound.Types.Internal
@@ -1566,7 +1567,7 @@ data TimeInterval = Weeks
1566 | Days
1567 | Days
1567 | Hours
1568 | Hours
1568 | Minutes
1569 | Minutes
1569− | Seconds deriving (Eq, Read)
1570+ | Seconds deriving Eq
1570
1571
1571data Interval = Year
1572data Interval = Year
1572 | Quarter
1573 | Quarter
@@ -1712,6 +1713,16 @@ instance Show TimeInterval where
1712 show Minutes = "m"
1713 show Minutes = "m"
1713 show Seconds = "s"
1714 show Seconds = "s"
1714
1715
1716+instance Read TimeInterval where
1717+ readPrec = f =<< TR.get
1718+ where
1719+ f 'w' = return Weeks
1720+ f 'd' = return Days
1721+ f 'h' = return Hours
1722+ f 'm' = return Minutes
1723+ f 's' = return Seconds
1724+ f _ = fail "TimeInterval expected one of w, d, h, m, s"
1725+
1715instance ToJSON Aggregation where
1726instance ToJSON Aggregation where
1716 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1727 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1717 omitNulls ["terms" .= omitNulls [ toJSON' term,
1728 omitNulls ["terms" .= omitNulls [ toJSON' term,