summaryrefslogtreecommitdiff
path: root/lib/Postdelay/TimeSpec.hs
diff options
context:
space:
mode:
authorGregor Kleen <aethoago@141.li>2017-02-15 19:15:09 +0100
committerGregor Kleen <aethoago@141.li>2017-02-15 19:15:09 +0100
commit0503ba7038a78094363a29408aee4ad6ee4cfb13 (patch)
tree1136430c617c0ef5d6d8754fe2159e03263f4cd7 /lib/Postdelay/TimeSpec.hs
parent127c1212d7704392363e3614f339627bf514cfcf (diff)
downloadpostdelay-0503ba7038a78094363a29408aee4ad6ee4cfb13.tar
postdelay-0503ba7038a78094363a29408aee4ad6ee4cfb13.tar.gz
postdelay-0503ba7038a78094363a29408aee4ad6ee4cfb13.tar.bz2
postdelay-0503ba7038a78094363a29408aee4ad6ee4cfb13.tar.xz
postdelay-0503ba7038a78094363a29408aee4ad6ee4cfb13.zip
Improved labels
Diffstat (limited to 'lib/Postdelay/TimeSpec.hs')
-rw-r--r--lib/Postdelay/TimeSpec.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Postdelay/TimeSpec.hs b/lib/Postdelay/TimeSpec.hs
index fbbce6b..a72f87e 100644
--- a/lib/Postdelay/TimeSpec.hs
+++ b/lib/Postdelay/TimeSpec.hs
@@ -38,18 +38,20 @@ utcOffset = iso ((% Minute) . fromIntegral . timeZoneMinutes) (minutesToTimeZone
38 38
39timeSpec :: StringParser s m => m (Endo LocalTime) 39timeSpec :: StringParser s m => m (Endo LocalTime)
40timeSpec = label "Relative time specification" $ 40timeSpec = label "Relative time specification" $
41 choice [ offsets False 41 choice [ lexeme (string' "now") *> offsets True
42 ] 42 , offsets False
43 ]
43 44
44offsets :: forall s m. StringParser s m 45offsets :: forall s m. StringParser s m
45 => Bool -- ^ Require sign on first offset? 46 => Bool -- ^ Require sign on first offset?
46 -> m (Endo LocalTime) 47 -> m (Endo LocalTime)
47offsets (bool optSigned signed -> reqSgn) = fmap fold $ (:) <$> offset reqSgn <*> many (offset optSigned) 48offsets reqSgn = fmap fold $ (:) <$> offset reqSgn <*> many (offset False)
48 where 49 where
49 asOffset :: Time -> Endo LocalTime 50 asOffset :: Time -> Endo LocalTime
50 asOffset by = Endo $ flexDT.seconds' %~ (^+^ by) 51 asOffset by = Endo $ flexDT.seconds' %~ (^+^ by)
51 offset :: (m Time -> m Time) -> m (Endo LocalTime) 52 offset :: Bool -> m (Endo LocalTime)
52 offset sgn = asOffset <$> lexeme (sgn timeLength) <?> "Time offset" 53 offset sgnReq@(bool optSigned signed -> sgn)
54 = asOffset <$> lexeme (sgn timeLength) <?> if sgnReq then "Signed time offset" else "Time offset"
53 55
54timeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ) 56timeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ)
55timeZone = label "Timezone" $ (Left <$> numericTimezone) <|> (Right <$> namedTimezone) 57timeZone = label "Timezone" $ (Left <$> numericTimezone) <|> (Right <$> namedTimezone)