summaryrefslogtreecommitdiff
path: root/lib/Postdelay/TimeSpec.hs
diff options
context:
space:
mode:
authorGregor Kleen <aethoago@141.li>2017-02-16 19:03:30 +0100
committerGregor Kleen <aethoago@141.li>2017-02-16 19:03:30 +0100
commit4343e02ca8431e61e2dc1755d1288dd6c55c9a23 (patch)
tree2f1397eb4c8649dffb7ae2adaedfd101bdda4fab /lib/Postdelay/TimeSpec.hs
parent333ea946916b005134e7ba249178acad4858a67d (diff)
downloadpostdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar.gz
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar.bz2
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.tar.xz
postdelay-4343e02ca8431e61e2dc1755d1288dd6c55c9a23.zip
Bounded numeric parsers
Diffstat (limited to 'lib/Postdelay/TimeSpec.hs')
-rw-r--r--lib/Postdelay/TimeSpec.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Postdelay/TimeSpec.hs b/lib/Postdelay/TimeSpec.hs
index 384de4b..edd70c1 100644
--- a/lib/Postdelay/TimeSpec.hs
+++ b/lib/Postdelay/TimeSpec.hs
@@ -56,13 +56,18 @@ timeSpec = label "Relative time specification" $
56 ] 56 ]
57 57
58 toEndo :: [RWS LocalTime () LocalTime a] -> Endo LocalTime 58 toEndo :: [RWS LocalTime () LocalTime a] -> Endo LocalTime
59 toEndo acts = Endo $ \t -> fst $ execRWS (sequence acts) t t 59 toEndo (sequence -> act) = Endo $ \t -> fst $ execRWS act t t
60 60
61timeOfDay, dateSpec :: StringParser s m => m (RWS LocalTime () LocalTime ()) 61timeOfDay, dateSpec :: StringParser s m => m (RWS LocalTime () LocalTime ())
62timeOfDay = label "Time of day" $ shiftBack (1 % Day) . assign time <$> choice 62timeOfDay = label "Time of day" $ shiftBack (1 % Day) . assign time <$> choice
63 [ TimeOfDay 0 0 0 <$ string' "midnight" 63 [ TimeOfDay 0 0 0 <$ string' "midnight"
64 , TimeOfDay 12 0 0 <$ string' "noon" 64 , TimeOfDay 12 0 0 <$ string' "noon"
65 , TimeOfDay 16 0 0 <$ string' "teatime" 65 , TimeOfDay 16 0 0 <$ string' "teatime"
66 , try $ do
67 h <- boundedNatural True $ 0 <=..<= 24
68 m <- boundedNatural True $ 0 <=..<= 59
69 s <- option 0 $ boundedRational True $ 0 <=..< 61
70 return $ TimeOfDay h m s
66 ] 71 ]
67dateSpec = label "Date" $ (date <~) <$> choice 72dateSpec = label "Date" $ (date <~) <$> choice
68 [ view date <$ string' "today" 73 [ view date <$ string' "today"