diff options
author | evuez <julien@mulga.net> | 2024-04-01 15:16:52 +0200 |
---|---|---|
committer | evuez <julien@mulga.net> | 2024-04-03 22:45:16 +0200 |
commit | ff174d9536db26945189593bf8194f18fbd5ce3f (patch) | |
tree | 327cf783e3c24a0b4b035f548b0ea7206ea9b0f9 /src/Cron/Expr.hs | |
download | uncron-ff174d9536db26945189593bf8194f18fbd5ce3f.tar.gz |
Initial commit
Diffstat (limited to 'src/Cron/Expr.hs')
-rw-r--r-- | src/Cron/Expr.hs | 21 |
1 files changed, 21 insertions, 0 deletions
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] |