@@ -166,9 +166,6 @@ instance Result (Binary LB.ByteString) where
166166
167167instance Result ST.Text where
168168 convert f = doConvert f okText $ (either left Right . ST.decodeUtf8')
169−{- | isText f = doConvert f okText $ (Right . ST.decodeUtf8)
170− | otherwise = incompatible f (typeOf ST.empty)
171− "attempt to mix binary and text" -}
172169 -- FIXME: check character encoding
173170
174171instance Result LT.Text where
@@ -183,30 +180,24 @@ instance Result UTCTime where
183180 Just t -> Right t
184181 Nothing -> returnError ConversionFailed f "could not parse"
185182 where ok = mkCompats [TimestampWithTimeZone]
186−{--
183+
187184instance Result Day where
188− convert f = flip (atto ok) f $ case fieldType f of
189− Year -> year
190− _ -> date
191− where ok = mkCompats [Year,Date,NewDate]
192− year = fromGregorian <$> decimal <*> pure 1 <*> pure 1
185+ convert f = atto ok date f
186+ where ok = mkCompats [Date]
193187 date = fromGregorian <$> (decimal <* char '-')
194188 <*> (decimal <* char '-')
195189 <*> decimal
196190
197191instance Result TimeOfDay where
198− convert f = flip (atto ok) f $ do
192+ convert f = atto' ok time f
193+ where ok = mkCompats [Time]
194+ time = do
199195 hours <- decimal <* char ':'
200196 mins <- decimal <* char ':'
201197 secs <- decimal :: Parser Int
202198 case makeTimeOfDayValid hours mins (fromIntegral secs) of
203− Just t -> return t
204− _ -> conversionFailed f "TimeOfDay" "could not parse"
205− where ok = mkCompats [Time]
206−
207−isText :: Field -> Bool
208−isText f = fieldCharSet f /= 63
209−--}
199+ Just t -> return (pure t)
200+ _ -> return (returnError ConversionFailed f "could not parse")
210201newtype Compat = Compat Word64
211202
212203mkCompats :: [BuiltinType] -> Compat
@@ -259,5 +250,16 @@ atto types p0 f dat = doConvert f types (go p0) dat
259250 Left err -> returnError ConversionFailed f err
260251 Right v -> Right v
261252
253+atto' :: forall a. (Typeable a)
254+ => Compat -> Parser (Either SomeException a) -> Field -> Maybe ByteString
255+ -> Either SomeException a
256+atto' types p0 f dat = doConvert f types (go p0) dat
257+ where
258+ go :: Parser (Either SomeException a) -> ByteString -> Either SomeException a
259+ go p s =
260+ case parseOnly p s of
261+ Left err -> returnError ConversionFailed f err
262+ Right v -> v
263+
262264instance Result RawResult where
263265 convert field rawData = Right (RawResult field rawData)