]> gitweb @ CieloNegro.org - time-w3c.git/blob - Data/Time/W3C/Parser.hs
Haddock comments
[time-w3c.git] / Data / Time / W3C / Parser.hs
1 -- | Parse W3C Date and Time string.
2 module Data.Time.W3C.Parser
3     ( parse
4     )
5     where
6
7 import qualified Text.Parsec as P
8
9 import Data.Convertible
10 import Data.Time.W3C.Parser.Parsec
11 import Data.Time.W3C.Types
12
13 -- | Parse W3C Date and Time string to anything convertible from
14 -- 'W3CDateTime' type. The most obvious acceptable type is the
15 -- 'W3CDateTime' itself. If the given string is ill-formatted, 'parse'
16 -- returns 'Prelude.Nothing'.
17 parse :: Convertible W3CDateTime t => String -> Maybe t
18 parse src = case P.parse p "" src of
19               Right w3c -> Just (convert w3c)
20               Left  _   -> Nothing
21     where
22       p = do w3c <- w3cDateTime
23              _   <- P.eof
24              return w3c