time-w3c-0.1: Data/Time/W3C/Parser.hs
-- | Parse W3C Date and Time string.
module Data.Time.W3C.Parser
( parse
)
where
import qualified Text.Parsec as P
import Data.Convertible
import Data.Time.W3C.Parser.Parsec
import Data.Time.W3C.Types
-- | Parse W3C Date and Time string to anything convertible from
-- 'W3CDateTime' type. The most obvious acceptable type is the
-- 'W3CDateTime' itself. If the given string is ill-formatted, 'parse'
-- returns 'Prelude.Nothing'.
parse :: Convertible W3CDateTime t => String -> Maybe t
parse src = case P.parse p "" src of
Right w3c -> Just (convert w3c)
Left _ -> Nothing
where
p = do w3c <- w3cDateTime
_ <- P.eof
return w3c