git.iko.soy/typeable/bloodhound
on master help sign in
TimeInterval Read/Show instances now roundtrip

λ> let read_show_roundtrip a = ((read . show) (a :: TimeInterval) == a) λ> :t read_show_roundtrip read_show_roundtrip :: TimeInterval -> Bool λ> quickCheck read_show_roundtrip +++ OK, passed 100 tests.

commit4553454fa77c70c528a5a8738ad6dac679f83341 authorDmitry Dzhus <dima@dzhus.org> dateThu 26 May 2016, 11:17 (10 years ago) parentca21210
1 file changed+12−1
src/Database/Bloodhound/Types.hs+12−1
src/Database/Bloodhound/Types.hs+12−1
@@ -305,6 +305,7 @@ import GHC.Enum
305305import GHC.Generics (Generic)
306306import Network.HTTP.Client
307307import qualified Network.HTTP.Types.Method as NHTM
308+import qualified Text.Read as TR
308309
309310import Database.Bloodhound.Types.Class
310311import Database.Bloodhound.Types.Internal
@@ -1566,7 +1567,7 @@ data TimeInterval = Weeks
15661567 | Days
15671568 | Hours
15681569 | Minutes
1569− | Seconds deriving (Eq, Read)
1570+ | Seconds deriving Eq
15701571
15711572data Interval = Year
15721573 | Quarter
@@ -1712,6 +1713,16 @@ instance Show TimeInterval where
17121713 show Minutes = "m"
17131714 show Seconds = "s"
17141715
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+
17151726instance ToJSON Aggregation where
17161727 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
17171728 omitNulls ["terms" .= omitNulls [ toJSON' term,