12 import Control.Arrow.ArrowList
17 yesOrNo :: Bool -> String
22 parseYesOrNo :: ArrowChoice a => a String Bool
24 = proc str -> do case str of
25 "yes" -> returnA -< True
26 "no" -> returnA -< False
27 _ -> returnA -< error ("Expected yes or no: " ++ str)
30 maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c)
34 [] -> returnA -< Nothing
35 (x:_) -> returnA -< Just x
38 defaultTo :: ArrowChoice a => b -> a (Maybe b) b
41 Nothing -> returnA -< def
42 Just x -> returnA -< x
45 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
47 = proc str -> do case str of
52 formatW3CDateTime :: CalendarTime -> String
53 formatW3CDateTime time
54 = formatDateTime time ++ formatTimeZone time
56 formatDateTime :: CalendarTime -> String
58 = printf "%04d-%02d-%02dT%02d:%02d:%02d"
60 (fromEnum (ctMonth time) + 1)
66 formatTimeZone :: CalendarTime -> String
69 of offset | offset < 0 -> '-':(showTZ $ negate offset)
71 | otherwise -> '+':(showTZ offset)
73 showTZ :: Int -> String
75 = let hour = offset `div` 3600
76 min = (offset - hour * 3600) `div` 60
78 show2 hour ++ ":" ++ show2 min
80 show2 :: Int -> String
81 show2 n | n < 10 = '0':(show n)