summaryrefslogtreecommitdiff
path: root/lib/Postdelay/TimeSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Postdelay/TimeSpec.hs')
-rw-r--r--lib/Postdelay/TimeSpec.hs28
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/Postdelay/TimeSpec.hs b/lib/Postdelay/TimeSpec.hs
index 5c41180..03baf85 100644
--- a/lib/Postdelay/TimeSpec.hs
+++ b/lib/Postdelay/TimeSpec.hs
@@ -14,16 +14,38 @@ import Text.Megaparsec
14 14
15import Control.Monad.IO.Class 15import Control.Monad.IO.Class
16import Control.Applicative 16import Control.Applicative
17import Control.Lens hiding ((#))
17 18
18import Data.Semigroup 19import Data.Bool
20import Data.Semigroup hiding (option)
19import Data.Monoid (Endo(..)) 21import Data.Monoid (Endo(..))
22import Data.Foldable
23import Data.VectorSpace
20 24
21import Data.Time 25import Data.Time
26import Data.Time.Lens
22import Data.Time.Zones 27import Data.Time.Zones
23 28
24 29
30seconds' :: Timeable t => Lens' t Time
31seconds' = seconds . iso (% Second) (# Second)
32
33
25pTimeSpec :: StringParser s m => m (Endo LocalTime) 34pTimeSpec :: StringParser s m => m (Endo LocalTime)
26pTimeSpec = empty 35pTimeSpec = label "Relative time specification" $
36 choice [ pOffsets False
37 ]
38
39pOffsets :: forall s m. StringParser s m
40 => Bool -- ^ Require sign on first offset?
41 -> m (Endo LocalTime)
42pOffsets (bool optSigned signed -> reqSgn) = fmap fold $ (:) <$> offset reqSgn <*> many (offset optSigned)
43 where
44 asOffset :: Time -> Endo LocalTime
45 asOffset by = Endo $ flexDT.seconds' %~ (^+^ by)
46 offset :: (m Time -> m Time) -> m (Endo LocalTime)
47 offset sgn = asOffset <$> lexeme (sgn timeLength) <?> "Time offset"
27 48
28pTimeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ) 49pTimeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ)
29pTimeZone = empty 50pTimeZone = label "Timezone" $
51 empty