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 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
40 = proc str -> do case str of
45 formatW3CDateTime :: CalendarTime -> String
46 formatW3CDateTime time
47 = formatDateTime time ++ formatTimeZone time
49 formatDateTime :: CalendarTime -> String
51 = printf "%04d-%02d-%02dT%02d:%02d:%02d"
53 (fromEnum (ctMonth time) + 1)
59 formatTimeZone :: CalendarTime -> String
62 of offset | offset < 0 -> '-':(showTZ $ negate offset)
64 | otherwise -> '+':(showTZ offset)
66 showTZ :: Int -> String
68 = let hour = offset `div` 3600
69 min = (offset - hour * 3600) `div` 60
71 show2 hour ++ ":" ++ show2 min
73 show2 :: Int -> String
74 show2 n | n < 10 = '0':(show n)
78 chomp :: String -> String
79 chomp = reverse . snd . break (/= '\n') . reverse