From 0503ba7038a78094363a29408aee4ad6ee4cfb13 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Feb 2017 19:15:09 +0100 Subject: Improved labels --- lib/Postdelay/TimeSpec.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib') 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 timeSpec :: StringParser s m => m (Endo LocalTime) timeSpec = label "Relative time specification" $ - choice [ offsets False - ] + choice [ lexeme (string' "now") *> offsets True + , offsets False + ] offsets :: forall s m. StringParser s m => Bool -- ^ Require sign on first offset? -> m (Endo LocalTime) -offsets (bool optSigned signed -> reqSgn) = fmap fold $ (:) <$> offset reqSgn <*> many (offset optSigned) +offsets reqSgn = fmap fold $ (:) <$> offset reqSgn <*> many (offset False) where asOffset :: Time -> Endo LocalTime asOffset by = Endo $ flexDT.seconds' %~ (^+^ by) - offset :: (m Time -> m Time) -> m (Endo LocalTime) - offset sgn = asOffset <$> lexeme (sgn timeLength) "Time offset" + offset :: Bool -> m (Endo LocalTime) + offset sgnReq@(bool optSigned signed -> sgn) + = asOffset <$> lexeme (sgn timeLength) if sgnReq then "Signed time offset" else "Time offset" timeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ) timeZone = label "Timezone" $ (Left <$> numericTimezone) <|> (Right <$> namedTimezone) -- cgit v1.2.3