11 import Control.Arrow.ArrowList
16 parseYesOrNo :: ArrowChoice a => a String Bool
18 = proc str -> do case str of
19 "yes" -> returnA -< True
20 "no" -> returnA -< False
21 _ -> returnA -< error ("Expected yes or no: " ++ str)
24 maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c)
28 [] -> returnA -< Nothing
29 (x:_) -> returnA -< Just x
32 defaultTo :: ArrowChoice a => b -> a (Maybe b) b
35 Nothing -> returnA -< def
36 Just x -> returnA -< x
39 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
41 = proc str -> do case str of
46 formatW3CDateTime :: CalendarTime -> String
47 formatW3CDateTime time
48 = formatDateTime time ++ formatTimeZone time
50 formatDateTime :: CalendarTime -> String
52 = printf "%04d-%02d-%02dT%02d:%02d:%02d"
54 (fromEnum (ctMonth time) + 1)
60 formatTimeZone :: CalendarTime -> String
63 of offset | offset < 0 -> '-':(showTZ $ negate offset)
65 | otherwise -> '+':(showTZ offset)
67 showTZ :: Int -> String
69 = let hour = offset `div` 3600
70 min = (offset - hour * 3600) `div` 60
72 show2 hour ++ ":" ++ show2 min
74 show2 :: Int -> String
75 show2 n | n < 10 = '0':(show n)