From 5b09b096e38ed231b62df57736e87c989b481b5d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Feb 2017 18:17:26 +0100 Subject: Purely relative time specifications --- lib/Postdelay/TimeSpec.hs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'lib/Postdelay/TimeSpec.hs') 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 import Control.Monad.IO.Class import Control.Applicative +import Control.Lens hiding ((#)) -import Data.Semigroup +import Data.Bool +import Data.Semigroup hiding (option) import Data.Monoid (Endo(..)) +import Data.Foldable +import Data.VectorSpace import Data.Time +import Data.Time.Lens import Data.Time.Zones +seconds' :: Timeable t => Lens' t Time +seconds' = seconds . iso (% Second) (# Second) + + pTimeSpec :: StringParser s m => m (Endo LocalTime) -pTimeSpec = empty +pTimeSpec = label "Relative time specification" $ + choice [ pOffsets False + ] + +pOffsets :: forall s m. StringParser s m + => Bool -- ^ Require sign on first offset? + -> m (Endo LocalTime) +pOffsets (bool optSigned signed -> reqSgn) = fmap fold $ (:) <$> offset reqSgn <*> many (offset optSigned) + 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" pTimeZone :: (StringParser s m, MonadIO m) => m (Either TimeZone TZ) -pTimeZone = empty +pTimeZone = label "Timezone" $ + empty -- cgit v1.2.3