From ff174d9536db26945189593bf8194f18fbd5ce3f Mon Sep 17 00:00:00 2001 From: evuez Date: Mon, 1 Apr 2024 15:16:52 +0200 Subject: Initial commit --- src/Cron/Expr.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Cron/Expr.hs (limited to 'src/Cron/Expr.hs') diff --git a/src/Cron/Expr.hs b/src/Cron/Expr.hs new file mode 100644 index 0000000..a6cb4ca --- /dev/null +++ b/src/Cron/Expr.hs @@ -0,0 +1,21 @@ +module Cron.Expr (Expr (..), StepLExpr (..), showExpr) where + +import Data.List.NonEmpty (NonEmpty, intersperse) +import Data.Semigroup (sconcat) +import Intro + +data Expr = Every | Multi (NonEmpty Int) | Range Int Int | Step StepLExpr Int deriving (Show) + +data StepLExpr = StepLEvery | StepLRange Int Int deriving (Show) + +showExpr :: Expr -> String +showExpr = \case + Every -> "*" + Multi ns -> sconcat $ intersperse "," (fmap show ns) + Range n m -> mconcat [show n, "-", show m] + Step n m -> mconcat [showStepLExpr n, "/", show m] + +showStepLExpr :: StepLExpr -> String +showStepLExpr = \case + StepLEvery -> "*" + StepLRange n m -> mconcat [show n, "-", show m] -- cgit v1.2.3