1 module Data.Time.W3C.Parser.Parsec
8 import Data.Time.W3C.Types
12 w3cDateTime :: Stream s m Char => ParsecT s u m W3CDateTime
13 w3cDateTime = read4 >>= mdhmst
16 = ( char '-' >> read2 >>= dhmst year )
25 , w3cTimeZone = Nothing
28 = ( char '-' >> read2 >>= hmst year month )
32 , w3cMonth = Just month
37 , w3cTimeZone = Nothing
49 , w3cMonth = Just month
54 , w3cTimeZone = Nothing
56 st year month day hour minute
62 , w3cMonth = Just month
65 , w3cMinute = Just minute
67 , w3cTimeZone = Just t
74 , w3cMonth = Just month
77 , w3cMinute = Just minute
79 , w3cTimeZone = Just t
83 second = do int <- read2
84 frac <- option 0 (char '.' >> liftM parseFrac (many1 digit))
87 timezone = liftM minutesToTimeZone
88 ( ( char 'Z' >> return 0 )
90 do sign <- ( char '+' >> return 1 )
92 ( char '-' >> return (-1) )
96 return (sign * (h * 60 + m))
100 * (0 / 10) + 0.2 = 0.2
101 * (0.2 / 10) + 0.5 = 0.52
102 * (0.52 / 10) + 0.1 = 0.152 *done*
104 parseFrac :: RealFrac r => String -> r
105 parseFrac = parseFrac' 0 . reverse . map fromC
108 parseFrac' r (d:ds) = parseFrac' (r / 10 + d / 10) ds
110 read4 :: (Stream s m Char, Num n) => ParsecT s u m n
111 read4 = do n1 <- digit'
115 return (n1 * 1000 + n2 * 100 + n3 * 10 + n4)
117 read2 :: (Stream s m Char, Num n) => ParsecT s u m n
118 read2 = do n1 <- digit'
120 return (n1 * 10 + n2)
122 digit' :: (Stream s m Char, Num n) => ParsecT s u m n
123 digit' = liftM fromC digit
125 fromC :: Num n => Char -> n