fix parse of negative posix time

Should never happen, but..
This commit is contained in:
Joey Hess 2018-10-29 23:40:34 -04:00
parent a8ad577d1d
commit 48af284872
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -27,14 +27,16 @@ parsePOSIXTime = uncurry parsePOSIXTime' . separate (== '.')
{- Parses the integral and decimal part of a POSIXTime -}
parsePOSIXTime' :: String -> String -> Maybe POSIXTime
parsePOSIXTime' sn sd = do
n <- readi sn
n <- fromIntegral <$> readi sn
let sd' = takeWhile (/= 's') sd
if null sd'
then return (fromIntegral n)
then return n
else do
d <- readi sd'
let r = d % (10 ^ (length sd'))
return (fromIntegral n + fromRational r)
return $ if n < 0
then n - fromRational r
else n + fromRational r
where
readi :: String -> Maybe Integer
readi = readish