diff options
-rw-r--r-- | lib/Postdelay/TimeSpec.hs | 12 |
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 | ||
39 | timeSpec :: StringParser s m => m (Endo LocalTime) | 39 | timeSpec :: StringParser s m => m (Endo LocalTime) |
40 | timeSpec = label "Relative time specification" $ | 40 | timeSpec = label "Relative time specification" $ |
41 | choice [ offsets False | 41 | choice [ lexeme (string' "now") *> offsets True |
42 | ] | 42 | , offsets False |
43 | ] | ||
43 | 44 | ||
44 | offsets :: forall s m. StringParser s m | 45 | offsets :: 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) |
47 | offsets (bool optSigned signed -> reqSgn) = fmap fold $ (:) <$> offset reqSgn <*> many (offset optSigned) | 48 | offsets 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 | ||
54 | timeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ) | 56 | timeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ) |
55 | timeZone = label "Timezone" $ (Left <$> numericTimezone) <|> (Right <$> namedTimezone) | 57 | timeZone = label "Timezone" $ (Left <$> numericTimezone) <|> (Right <$> namedTimezone) |