11 import Control.Arrow.ArrowList
16 yesOrNo :: Bool -> String
21 parseYesOrNo :: ArrowChoice a => a String Bool
23 = proc str -> do case str of
24 "yes" -> returnA -< True
25 "no" -> returnA -< False
26 _ -> returnA -< error ("Expected yes or no: " ++ str)
29 maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c)
33 [] -> returnA -< Nothing
34 (x:_) -> returnA -< Just x
37 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
39 = proc str -> do case str of
44 formatW3CDateTime :: CalendarTime -> String
45 formatW3CDateTime time
46 = formatDateTime time ++ formatTimeZone time
48 formatDateTime :: CalendarTime -> String
50 = printf "%04d-%02d-%02dT%02d:%02d:%02d"
52 (fromEnum (ctMonth time) + 1)
58 formatTimeZone :: CalendarTime -> String
61 of offset | offset < 0 -> '-':(showTZ $ negate offset)
63 | otherwise -> '+':(showTZ offset)
65 showTZ :: Int -> String
67 = let hour = offset `div` 3600
68 min = (offset - hour * 3600) `div` 60
70 show2 hour ++ ":" ++ show2 min
72 show2 :: Int -> String
73 show2 n | n < 10 = '0':(show n)