git.iko.soy/typeable/postgresql-simple
on master help sign in
Allow optional seconds when parsing of time of day
fe5e16cLeon P Smith
src/Database/PostgreSQL/Simple/Time/Internal/Parser.hs+6−3
@@ -52,12 +52,15 @@ twoDigits = do
52 let c2d c = ord c .&. 15
52 let c2d c = ord c .&. 15
53 return $! c2d a * 10 + c2d b
53 return $! c2d a * 10 + c2d b
54
54
55−-- | Parse a time of the form @HH:MM:SS[.SSS]@.
55+-- | Parse a time of the form @HH:MM[:SS[.SSS]]@.
56timeOfDay :: Parser Local.TimeOfDay
56timeOfDay :: Parser Local.TimeOfDay
57timeOfDay = do
57timeOfDay = do
58 h <- twoDigits <* char ':'
58 h <- twoDigits <* char ':'
59− m <- twoDigits <* char ':'
59+ m <- twoDigits
60+ mc <- peekChar
61+ s <- case mc of
60− s <- seconds
62+ Just ':' -> anyChar *> seconds
63+ _ -> return 0
61 if h < 24 && m < 60 && s <= 60
64 if h < 24 && m < 60 && s <= 60
62 then return (Local.TimeOfDay h m s)
65 then return (Local.TimeOfDay h m s)
63 else fail "invalid time"
66 else fail "invalid time"