X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-w3c.git;a=blobdiff_plain;f=Data%2FTime%2FW3C%2FParser.hs;h=5bf2f9e674315d32092568d9d154b0bc8a257fae;hp=539a024280152be30c6643d4cbbac91157c86821;hb=376869bc3a4e7c2e22fb47152ba2d459b82efdd0;hpb=3d738487d6fb1077d139fd689279a1ebd27a9fdc diff --git a/Data/Time/W3C/Parser.hs b/Data/Time/W3C/Parser.hs index 539a024..5bf2f9e 100644 --- a/Data/Time/W3C/Parser.hs +++ b/Data/Time/W3C/Parser.hs @@ -1,3 +1,4 @@ +-- | Parse W3C Date and Time string. module Data.Time.W3C.Parser ( parse ) @@ -5,11 +6,19 @@ module Data.Time.W3C.Parser import qualified Text.Parsec as P +import Data.Convertible import Data.Time.W3C.Parser.Parsec import Data.Time.W3C.Types -parse :: String -> Maybe W3CDateTime -parse src - = case P.parse w3cDateTime "" src of - Right w3c -> Just w3c - Left _ -> Nothing +-- | 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 \ No newline at end of file