aboutsummaryrefslogtreecommitdiff
path: root/src/Cron/Expr.hs
blob: a6cb4ca700f84ec1f602707cd5a5c6f215d9925c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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]