{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
module System.Cron.Types
    ( CronSchedule(..)
    , Crontab(..)
    , CrontabEntry(..)
    , MinuteSpec
    , CronCommand(..)
    , minuteSpec
    , mkMinuteSpec
    , HourSpec
    , hourSpec
    , mkHourSpec
    , MonthSpec
    , monthSpec
    , mkMonthSpec
    , DayOfMonthSpec
    , dayOfMonthSpec
    , mkDayOfMonthSpec
    , DayOfWeekSpec
    , dayOfWeekSpec
    , mkDayOfWeekSpec
    , BaseField(..)
    , SpecificField
    , specificField
    , mkSpecificField
    , RangeField
    , rfBegin
    , rfEnd
    , mkRangeField
    , CronField(..)
    , StepField
    , sfField
    , sfStepping
    , mkStepField
    -- * Commonly Used Schedules
    , yearly
    , monthly
    , daily
    , weekly
    , hourly
    , everyMinute
    -- * Rendering
    , serializeCronSchedule
    , serializeCrontab

    -- * Converting to human-readable string
    -- , displayCronField
    -- , Display(..)
    ) where


-------------------------------------------------------------------------------
import           Control.Applicative as A
import           Data.Data           (Data)
import qualified Data.Foldable       as FT
import           Data.Ix
import           Data.List.NonEmpty  (NonEmpty (..))
import qualified Data.List.NonEmpty  as NE
import           Data.Monoid         as Monoid
import           Data.Text           (Text)
import qualified Data.Text           as T
import           Data.Typeable       (Typeable)
import           GHC.Generics        (Generic)
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- Shorthand schedules
-------------------------------------------------------------------------------


-- | Shorthand for every January 1st at midnight. Parsed with \@yearly, 0 0 1 1 *
yearly :: CronSchedule
yearly :: CronSchedule
yearly = CronSchedule
monthly { month = Months (Field (SpecificField' (SpecificField 1))) }


-- | Shorthand for every 1st of the month at midnight. Parsed with \@monthly, 0 0 1 * *
monthly :: CronSchedule
monthly :: CronSchedule
monthly = CronSchedule
daily { dayOfMonth = DaysOfMonth (Field (SpecificField' (SpecificField 1))) }


-- | Shorthand for every sunday at midnight. Parsed with \@weekly, 0 0 * * 0
weekly :: CronSchedule
weekly :: CronSchedule
weekly = CronSchedule
daily { dayOfWeek = DaysOfWeek (Field (SpecificField' (SpecificField 0))) }


-- | Shorthand for every day at midnight. Parsed with \@daily, 0 0 * * *
daily :: CronSchedule
daily :: CronSchedule
daily = CronSchedule
hourly { hour = Hours (Field (SpecificField' (SpecificField 0))) }


-- | Shorthand for every hour on the hour. Parsed with \@hourly, 0 * * * *
hourly :: CronSchedule
hourly :: CronSchedule
hourly = CronSchedule
everyMinute { minute = Minutes (Field (SpecificField' (SpecificField 0))) }


-- | Shorthand for an expression that always matches. Parsed with * * * * *
everyMinute :: CronSchedule
everyMinute :: CronSchedule
everyMinute = CronSchedule {
      minute :: MinuteSpec
minute     = CronField -> MinuteSpec
Minutes (BaseField -> CronField
Field BaseField
Star)
    , hour :: HourSpec
hour       = CronField -> HourSpec
Hours (BaseField -> CronField
Field BaseField
Star)
    , dayOfMonth :: DayOfMonthSpec
dayOfMonth = CronField -> DayOfMonthSpec
DaysOfMonth (BaseField -> CronField
Field BaseField
Star)
    , month :: MonthSpec
month      = CronField -> MonthSpec
Months (BaseField -> CronField
Field BaseField
Star)
    , dayOfWeek :: DayOfWeekSpec
dayOfWeek  = CronField -> DayOfWeekSpec
DaysOfWeek (BaseField -> CronField
Field BaseField
Star)
    }


-------------------------------------------------------------------------------
-- Types
-------------------------------------------------------------------------------


class ShowT a where
  showT :: a -> Text


instance ShowT Text where
  showT :: Text -> Text
showT = Text -> Text
forall a. a -> a
id


instance ShowT Int where
  showT :: Int -> Text
showT = String -> Text
T.pack (String -> Text) -> (Int -> String) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show


-- | Specification for a cron expression
data CronSchedule = CronSchedule {
      CronSchedule -> MinuteSpec
minute     :: MinuteSpec     -- ^ Which minutes to run. First field in a cron specification.
    , CronSchedule -> HourSpec
hour       :: HourSpec       -- ^ Which hours to run. Second field in a cron specification.
    , CronSchedule -> DayOfMonthSpec
dayOfMonth :: DayOfMonthSpec -- ^ Which days of the month to run. Third field in a cron specification.
    , CronSchedule -> MonthSpec
month      :: MonthSpec      -- ^ Which months to run. Fourth field in a cron specification.
    , CronSchedule -> DayOfWeekSpec
dayOfWeek  :: DayOfWeekSpec  -- ^ Which days of the week to run. Fifth field in a cron specification.
    } deriving (CronSchedule -> CronSchedule -> Bool
(CronSchedule -> CronSchedule -> Bool)
-> (CronSchedule -> CronSchedule -> Bool) -> Eq CronSchedule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CronSchedule -> CronSchedule -> Bool
== :: CronSchedule -> CronSchedule -> Bool
$c/= :: CronSchedule -> CronSchedule -> Bool
/= :: CronSchedule -> CronSchedule -> Bool
Eq, (forall x. CronSchedule -> Rep CronSchedule x)
-> (forall x. Rep CronSchedule x -> CronSchedule)
-> Generic CronSchedule
forall x. Rep CronSchedule x -> CronSchedule
forall x. CronSchedule -> Rep CronSchedule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CronSchedule -> Rep CronSchedule x
from :: forall x. CronSchedule -> Rep CronSchedule x
$cto :: forall x. Rep CronSchedule x -> CronSchedule
to :: forall x. Rep CronSchedule x -> CronSchedule
Generic, Typeable CronSchedule
Typeable CronSchedule =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> CronSchedule -> c CronSchedule)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CronSchedule)
-> (CronSchedule -> Constr)
-> (CronSchedule -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CronSchedule))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CronSchedule))
-> ((forall b. Data b => b -> b) -> CronSchedule -> CronSchedule)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CronSchedule -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CronSchedule -> r)
-> (forall u. (forall d. Data d => d -> u) -> CronSchedule -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CronSchedule -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule)
-> Data CronSchedule
CronSchedule -> Constr
CronSchedule -> DataType
(forall b. Data b => b -> b) -> CronSchedule -> CronSchedule
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CronSchedule -> u
forall u. (forall d. Data d => d -> u) -> CronSchedule -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronSchedule -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronSchedule -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronSchedule
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronSchedule -> c CronSchedule
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronSchedule)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CronSchedule)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronSchedule -> c CronSchedule
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronSchedule -> c CronSchedule
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronSchedule
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronSchedule
$ctoConstr :: CronSchedule -> Constr
toConstr :: CronSchedule -> Constr
$cdataTypeOf :: CronSchedule -> DataType
dataTypeOf :: CronSchedule -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronSchedule)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronSchedule)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CronSchedule)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CronSchedule)
$cgmapT :: (forall b. Data b => b -> b) -> CronSchedule -> CronSchedule
gmapT :: (forall b. Data b => b -> b) -> CronSchedule -> CronSchedule
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronSchedule -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronSchedule -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronSchedule -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronSchedule -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CronSchedule -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> CronSchedule -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CronSchedule -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CronSchedule -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronSchedule -> m CronSchedule
Data, Typeable)


instance Show CronSchedule where
  show :: CronSchedule -> String
show CronSchedule
cs = String
"CronSchedule " String -> ShowS
forall a. Semigroup a => a -> a -> a
Monoid.<> Text -> String
T.unpack (CronSchedule -> Text
forall a. ShowT a => a -> Text
showT CronSchedule
cs)


instance ShowT CronSchedule where
  showT :: CronSchedule -> Text
showT CronSchedule {DayOfWeekSpec
MonthSpec
DayOfMonthSpec
HourSpec
MinuteSpec
month :: CronSchedule -> MonthSpec
dayOfMonth :: CronSchedule -> DayOfMonthSpec
dayOfWeek :: CronSchedule -> DayOfWeekSpec
hour :: CronSchedule -> HourSpec
minute :: CronSchedule -> MinuteSpec
minute :: MinuteSpec
hour :: HourSpec
dayOfMonth :: DayOfMonthSpec
month :: MonthSpec
dayOfWeek :: DayOfWeekSpec
..} = [Text] -> Text
T.unwords [ MinuteSpec -> Text
forall a. ShowT a => a -> Text
showT MinuteSpec
minute
                                      , HourSpec -> Text
forall a. ShowT a => a -> Text
showT HourSpec
hour
                                      , DayOfMonthSpec -> Text
forall a. ShowT a => a -> Text
showT DayOfMonthSpec
dayOfMonth
                                      , MonthSpec -> Text
forall a. ShowT a => a -> Text
showT MonthSpec
month
                                      , DayOfWeekSpec -> Text
forall a. ShowT a => a -> Text
showT DayOfWeekSpec
dayOfWeek
                                      ]

serializeCronSchedule :: CronSchedule -> Text
serializeCronSchedule :: CronSchedule -> Text
serializeCronSchedule = CronSchedule -> Text
forall a. ShowT a => a -> Text
showT


-------------------------------------------------------------------------------
-- | Crontab file, omitting comments.
newtype Crontab = Crontab {
      Crontab -> [CrontabEntry]
crontabEntries :: [CrontabEntry]
    } deriving (Crontab -> Crontab -> Bool
(Crontab -> Crontab -> Bool)
-> (Crontab -> Crontab -> Bool) -> Eq Crontab
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Crontab -> Crontab -> Bool
== :: Crontab -> Crontab -> Bool
$c/= :: Crontab -> Crontab -> Bool
/= :: Crontab -> Crontab -> Bool
Eq, (forall x. Crontab -> Rep Crontab x)
-> (forall x. Rep Crontab x -> Crontab) -> Generic Crontab
forall x. Rep Crontab x -> Crontab
forall x. Crontab -> Rep Crontab x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Crontab -> Rep Crontab x
from :: forall x. Crontab -> Rep Crontab x
$cto :: forall x. Rep Crontab x -> Crontab
to :: forall x. Rep Crontab x -> Crontab
Generic, Typeable Crontab
Typeable Crontab =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Crontab -> c Crontab)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Crontab)
-> (Crontab -> Constr)
-> (Crontab -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Crontab))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Crontab))
-> ((forall b. Data b => b -> b) -> Crontab -> Crontab)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Crontab -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Crontab -> r)
-> (forall u. (forall d. Data d => d -> u) -> Crontab -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Crontab -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Crontab -> m Crontab)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Crontab -> m Crontab)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Crontab -> m Crontab)
-> Data Crontab
Crontab -> Constr
Crontab -> DataType
(forall b. Data b => b -> b) -> Crontab -> Crontab
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Crontab -> u
forall u. (forall d. Data d => d -> u) -> Crontab -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Crontab -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Crontab -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Crontab
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Crontab -> c Crontab
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Crontab)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Crontab)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Crontab -> c Crontab
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Crontab -> c Crontab
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Crontab
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Crontab
$ctoConstr :: Crontab -> Constr
toConstr :: Crontab -> Constr
$cdataTypeOf :: Crontab -> DataType
dataTypeOf :: Crontab -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Crontab)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Crontab)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Crontab)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Crontab)
$cgmapT :: (forall b. Data b => b -> b) -> Crontab -> Crontab
gmapT :: (forall b. Data b => b -> b) -> Crontab -> Crontab
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Crontab -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Crontab -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Crontab -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Crontab -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Crontab -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Crontab -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Crontab -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Crontab -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Crontab -> m Crontab
Data, Typeable)


instance ShowT Crontab where
  showT :: Crontab -> Text
showT (Crontab [CrontabEntry]
entries) = Text -> [Text] -> Text
T.intercalate Text
"\n" (CrontabEntry -> Text
forall a. ShowT a => a -> Text
showT (CrontabEntry -> Text) -> [CrontabEntry] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
A.<$> [CrontabEntry]
entries)


instance Show Crontab where
  show :: Crontab -> String
show = Text -> String
T.unpack (Text -> String) -> (Crontab -> Text) -> Crontab -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Crontab -> Text
forall a. ShowT a => a -> Text
showT


serializeCrontab :: Crontab -> Text
serializeCrontab :: Crontab -> Text
serializeCrontab = Crontab -> Text
forall a. ShowT a => a -> Text
showT


-------------------------------------------------------------------------------
newtype CronCommand = CronCommand {
      CronCommand -> Text
cronCommand :: Text
    } deriving (Int -> CronCommand -> ShowS
[CronCommand] -> ShowS
CronCommand -> String
(Int -> CronCommand -> ShowS)
-> (CronCommand -> String)
-> ([CronCommand] -> ShowS)
-> Show CronCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CronCommand -> ShowS
showsPrec :: Int -> CronCommand -> ShowS
$cshow :: CronCommand -> String
show :: CronCommand -> String
$cshowList :: [CronCommand] -> ShowS
showList :: [CronCommand] -> ShowS
Show, CronCommand -> CronCommand -> Bool
(CronCommand -> CronCommand -> Bool)
-> (CronCommand -> CronCommand -> Bool) -> Eq CronCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CronCommand -> CronCommand -> Bool
== :: CronCommand -> CronCommand -> Bool
$c/= :: CronCommand -> CronCommand -> Bool
/= :: CronCommand -> CronCommand -> Bool
Eq, Eq CronCommand
Eq CronCommand =>
(CronCommand -> CronCommand -> Ordering)
-> (CronCommand -> CronCommand -> Bool)
-> (CronCommand -> CronCommand -> Bool)
-> (CronCommand -> CronCommand -> Bool)
-> (CronCommand -> CronCommand -> Bool)
-> (CronCommand -> CronCommand -> CronCommand)
-> (CronCommand -> CronCommand -> CronCommand)
-> Ord CronCommand
CronCommand -> CronCommand -> Bool
CronCommand -> CronCommand -> Ordering
CronCommand -> CronCommand -> CronCommand
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CronCommand -> CronCommand -> Ordering
compare :: CronCommand -> CronCommand -> Ordering
$c< :: CronCommand -> CronCommand -> Bool
< :: CronCommand -> CronCommand -> Bool
$c<= :: CronCommand -> CronCommand -> Bool
<= :: CronCommand -> CronCommand -> Bool
$c> :: CronCommand -> CronCommand -> Bool
> :: CronCommand -> CronCommand -> Bool
$c>= :: CronCommand -> CronCommand -> Bool
>= :: CronCommand -> CronCommand -> Bool
$cmax :: CronCommand -> CronCommand -> CronCommand
max :: CronCommand -> CronCommand -> CronCommand
$cmin :: CronCommand -> CronCommand -> CronCommand
min :: CronCommand -> CronCommand -> CronCommand
Ord, CronCommand -> Text
(CronCommand -> Text) -> ShowT CronCommand
forall a. (a -> Text) -> ShowT a
$cshowT :: CronCommand -> Text
showT :: CronCommand -> Text
ShowT, (forall x. CronCommand -> Rep CronCommand x)
-> (forall x. Rep CronCommand x -> CronCommand)
-> Generic CronCommand
forall x. Rep CronCommand x -> CronCommand
forall x. CronCommand -> Rep CronCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CronCommand -> Rep CronCommand x
from :: forall x. CronCommand -> Rep CronCommand x
$cto :: forall x. Rep CronCommand x -> CronCommand
to :: forall x. Rep CronCommand x -> CronCommand
Generic, Typeable CronCommand
Typeable CronCommand =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> CronCommand -> c CronCommand)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CronCommand)
-> (CronCommand -> Constr)
-> (CronCommand -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CronCommand))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CronCommand))
-> ((forall b. Data b => b -> b) -> CronCommand -> CronCommand)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CronCommand -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CronCommand -> r)
-> (forall u. (forall d. Data d => d -> u) -> CronCommand -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CronCommand -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CronCommand -> m CronCommand)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CronCommand -> m CronCommand)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CronCommand -> m CronCommand)
-> Data CronCommand
CronCommand -> Constr
CronCommand -> DataType
(forall b. Data b => b -> b) -> CronCommand -> CronCommand
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CronCommand -> u
forall u. (forall d. Data d => d -> u) -> CronCommand -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronCommand -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronCommand -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronCommand
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronCommand -> c CronCommand
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronCommand)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CronCommand)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronCommand -> c CronCommand
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronCommand -> c CronCommand
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronCommand
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronCommand
$ctoConstr :: CronCommand -> Constr
toConstr :: CronCommand -> Constr
$cdataTypeOf :: CronCommand -> DataType
dataTypeOf :: CronCommand -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronCommand)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronCommand)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CronCommand)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CronCommand)
$cgmapT :: (forall b. Data b => b -> b) -> CronCommand -> CronCommand
gmapT :: (forall b. Data b => b -> b) -> CronCommand -> CronCommand
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronCommand -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronCommand -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronCommand -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronCommand -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CronCommand -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> CronCommand -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CronCommand -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CronCommand -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronCommand -> m CronCommand
Data, Typeable)


-------------------------------------------------------------------------------
-- | Essentially a line in a crontab file. It is either a schedule with a
-- command after it or setting an environment variable (e.g. FOO=BAR)
data CrontabEntry = CommandEntry CronSchedule CronCommand
                  | EnvVariable Text Text
                  deriving (CrontabEntry -> CrontabEntry -> Bool
(CrontabEntry -> CrontabEntry -> Bool)
-> (CrontabEntry -> CrontabEntry -> Bool) -> Eq CrontabEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CrontabEntry -> CrontabEntry -> Bool
== :: CrontabEntry -> CrontabEntry -> Bool
$c/= :: CrontabEntry -> CrontabEntry -> Bool
/= :: CrontabEntry -> CrontabEntry -> Bool
Eq, (forall x. CrontabEntry -> Rep CrontabEntry x)
-> (forall x. Rep CrontabEntry x -> CrontabEntry)
-> Generic CrontabEntry
forall x. Rep CrontabEntry x -> CrontabEntry
forall x. CrontabEntry -> Rep CrontabEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CrontabEntry -> Rep CrontabEntry x
from :: forall x. CrontabEntry -> Rep CrontabEntry x
$cto :: forall x. Rep CrontabEntry x -> CrontabEntry
to :: forall x. Rep CrontabEntry x -> CrontabEntry
Generic, Typeable CrontabEntry
Typeable CrontabEntry =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> CrontabEntry -> c CrontabEntry)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CrontabEntry)
-> (CrontabEntry -> Constr)
-> (CrontabEntry -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CrontabEntry))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CrontabEntry))
-> ((forall b. Data b => b -> b) -> CrontabEntry -> CrontabEntry)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r)
-> (forall u. (forall d. Data d => d -> u) -> CrontabEntry -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CrontabEntry -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry)
-> Data CrontabEntry
CrontabEntry -> Constr
CrontabEntry -> DataType
(forall b. Data b => b -> b) -> CrontabEntry -> CrontabEntry
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CrontabEntry -> u
forall u. (forall d. Data d => d -> u) -> CrontabEntry -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CrontabEntry
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CrontabEntry -> c CrontabEntry
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CrontabEntry)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CrontabEntry)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CrontabEntry -> c CrontabEntry
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CrontabEntry -> c CrontabEntry
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CrontabEntry
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CrontabEntry
$ctoConstr :: CrontabEntry -> Constr
toConstr :: CrontabEntry -> Constr
$cdataTypeOf :: CrontabEntry -> DataType
dataTypeOf :: CrontabEntry -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CrontabEntry)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CrontabEntry)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CrontabEntry)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CrontabEntry)
$cgmapT :: (forall b. Data b => b -> b) -> CrontabEntry -> CrontabEntry
gmapT :: (forall b. Data b => b -> b) -> CrontabEntry -> CrontabEntry
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CrontabEntry -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CrontabEntry -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> CrontabEntry -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CrontabEntry -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CrontabEntry -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CrontabEntry -> m CrontabEntry
Data, Typeable)


instance ShowT CrontabEntry where
  showT :: CrontabEntry -> Text
showT (CommandEntry CronSchedule
s CronCommand
c) = CronSchedule -> Text
forall a. ShowT a => a -> Text
showT CronSchedule
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> CronCommand -> Text
forall a. ShowT a => a -> Text
showT CronCommand
c
  showT (EnvVariable Text
n Text
v)  = Text -> Text
forall a. ShowT a => a -> Text
showT Text
n Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
forall a. ShowT a => a -> Text
showT Text
v


instance Show CrontabEntry where
  show :: CrontabEntry -> String
show = Text -> String
T.unpack (Text -> String)
-> (CrontabEntry -> Text) -> CrontabEntry -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CrontabEntry -> Text
forall a. ShowT a => a -> Text
showT

-------------------------------------------------------------------------------
-- | Minutes field of a cron expression
newtype MinuteSpec = Minutes {
      MinuteSpec -> CronField
minuteSpec :: CronField
    } deriving (MinuteSpec -> MinuteSpec -> Bool
(MinuteSpec -> MinuteSpec -> Bool)
-> (MinuteSpec -> MinuteSpec -> Bool) -> Eq MinuteSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MinuteSpec -> MinuteSpec -> Bool
== :: MinuteSpec -> MinuteSpec -> Bool
$c/= :: MinuteSpec -> MinuteSpec -> Bool
/= :: MinuteSpec -> MinuteSpec -> Bool
Eq, MinuteSpec -> Text
(MinuteSpec -> Text) -> ShowT MinuteSpec
forall a. (a -> Text) -> ShowT a
$cshowT :: MinuteSpec -> Text
showT :: MinuteSpec -> Text
ShowT, (forall x. MinuteSpec -> Rep MinuteSpec x)
-> (forall x. Rep MinuteSpec x -> MinuteSpec) -> Generic MinuteSpec
forall x. Rep MinuteSpec x -> MinuteSpec
forall x. MinuteSpec -> Rep MinuteSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MinuteSpec -> Rep MinuteSpec x
from :: forall x. MinuteSpec -> Rep MinuteSpec x
$cto :: forall x. Rep MinuteSpec x -> MinuteSpec
to :: forall x. Rep MinuteSpec x -> MinuteSpec
Generic, Typeable MinuteSpec
Typeable MinuteSpec =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> MinuteSpec -> c MinuteSpec)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c MinuteSpec)
-> (MinuteSpec -> Constr)
-> (MinuteSpec -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c MinuteSpec))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c MinuteSpec))
-> ((forall b. Data b => b -> b) -> MinuteSpec -> MinuteSpec)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r)
-> (forall u. (forall d. Data d => d -> u) -> MinuteSpec -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> MinuteSpec -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec)
-> Data MinuteSpec
MinuteSpec -> Constr
MinuteSpec -> DataType
(forall b. Data b => b -> b) -> MinuteSpec -> MinuteSpec
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> MinuteSpec -> u
forall u. (forall d. Data d => d -> u) -> MinuteSpec -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MinuteSpec
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MinuteSpec -> c MinuteSpec
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MinuteSpec)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MinuteSpec)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MinuteSpec -> c MinuteSpec
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MinuteSpec -> c MinuteSpec
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MinuteSpec
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MinuteSpec
$ctoConstr :: MinuteSpec -> Constr
toConstr :: MinuteSpec -> Constr
$cdataTypeOf :: MinuteSpec -> DataType
dataTypeOf :: MinuteSpec -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MinuteSpec)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MinuteSpec)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MinuteSpec)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MinuteSpec)
$cgmapT :: (forall b. Data b => b -> b) -> MinuteSpec -> MinuteSpec
gmapT :: (forall b. Data b => b -> b) -> MinuteSpec -> MinuteSpec
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MinuteSpec -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> MinuteSpec -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> MinuteSpec -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MinuteSpec -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MinuteSpec -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MinuteSpec -> m MinuteSpec
Data, Typeable)


instance Show MinuteSpec where
  show :: MinuteSpec -> String
show (Minutes CronField
cf) = CronField -> String
forall a. Show a => a -> String
show CronField
cf


--TODO: qc all of these
mkMinuteSpec :: CronField -> Maybe MinuteSpec
mkMinuteSpec :: CronField -> Maybe MinuteSpec
mkMinuteSpec CronField
cf
  | CronField -> Int -> Int -> Bool
validCF CronField
cf Int
0 Int
59 = MinuteSpec -> Maybe MinuteSpec
forall a. a -> Maybe a
Just (CronField -> MinuteSpec
Minutes CronField
cf)
  | Bool
otherwise       = Maybe MinuteSpec
forall a. Maybe a
Nothing


-------------------------------------------------------------------------------
-- | Hours field of a cron expression
newtype HourSpec = Hours {
      HourSpec -> CronField
hourSpec :: CronField
    } deriving (HourSpec -> HourSpec -> Bool
(HourSpec -> HourSpec -> Bool)
-> (HourSpec -> HourSpec -> Bool) -> Eq HourSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HourSpec -> HourSpec -> Bool
== :: HourSpec -> HourSpec -> Bool
$c/= :: HourSpec -> HourSpec -> Bool
/= :: HourSpec -> HourSpec -> Bool
Eq, HourSpec -> Text
(HourSpec -> Text) -> ShowT HourSpec
forall a. (a -> Text) -> ShowT a
$cshowT :: HourSpec -> Text
showT :: HourSpec -> Text
ShowT, (forall x. HourSpec -> Rep HourSpec x)
-> (forall x. Rep HourSpec x -> HourSpec) -> Generic HourSpec
forall x. Rep HourSpec x -> HourSpec
forall x. HourSpec -> Rep HourSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HourSpec -> Rep HourSpec x
from :: forall x. HourSpec -> Rep HourSpec x
$cto :: forall x. Rep HourSpec x -> HourSpec
to :: forall x. Rep HourSpec x -> HourSpec
Generic, Typeable HourSpec
Typeable HourSpec =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> HourSpec -> c HourSpec)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c HourSpec)
-> (HourSpec -> Constr)
-> (HourSpec -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c HourSpec))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HourSpec))
-> ((forall b. Data b => b -> b) -> HourSpec -> HourSpec)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> HourSpec -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> HourSpec -> r)
-> (forall u. (forall d. Data d => d -> u) -> HourSpec -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> HourSpec -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> HourSpec -> m HourSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HourSpec -> m HourSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HourSpec -> m HourSpec)
-> Data HourSpec
HourSpec -> Constr
HourSpec -> DataType
(forall b. Data b => b -> b) -> HourSpec -> HourSpec
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> HourSpec -> u
forall u. (forall d. Data d => d -> u) -> HourSpec -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HourSpec -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HourSpec -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HourSpec
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HourSpec -> c HourSpec
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HourSpec)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HourSpec)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HourSpec -> c HourSpec
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HourSpec -> c HourSpec
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HourSpec
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HourSpec
$ctoConstr :: HourSpec -> Constr
toConstr :: HourSpec -> Constr
$cdataTypeOf :: HourSpec -> DataType
dataTypeOf :: HourSpec -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HourSpec)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HourSpec)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HourSpec)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HourSpec)
$cgmapT :: (forall b. Data b => b -> b) -> HourSpec -> HourSpec
gmapT :: (forall b. Data b => b -> b) -> HourSpec -> HourSpec
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HourSpec -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HourSpec -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HourSpec -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HourSpec -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> HourSpec -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> HourSpec -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HourSpec -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HourSpec -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HourSpec -> m HourSpec
Data, Typeable)


instance Show HourSpec where
  show :: HourSpec -> String
show (Hours CronField
cf) = CronField -> String
forall a. Show a => a -> String
show CronField
cf


mkHourSpec :: CronField -> Maybe HourSpec
mkHourSpec :: CronField -> Maybe HourSpec
mkHourSpec CronField
cf
  | CronField -> Int -> Int -> Bool
validCF CronField
cf Int
0 Int
23 = HourSpec -> Maybe HourSpec
forall a. a -> Maybe a
Just (CronField -> HourSpec
Hours CronField
cf)
  | Bool
otherwise       = Maybe HourSpec
forall a. Maybe a
Nothing


-------------------------------------------------------------------------------
-- | Day of month field of a cron expression
newtype DayOfMonthSpec = DaysOfMonth {
      DayOfMonthSpec -> CronField
dayOfMonthSpec :: CronField
    } deriving (DayOfMonthSpec -> DayOfMonthSpec -> Bool
(DayOfMonthSpec -> DayOfMonthSpec -> Bool)
-> (DayOfMonthSpec -> DayOfMonthSpec -> Bool) -> Eq DayOfMonthSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DayOfMonthSpec -> DayOfMonthSpec -> Bool
== :: DayOfMonthSpec -> DayOfMonthSpec -> Bool
$c/= :: DayOfMonthSpec -> DayOfMonthSpec -> Bool
/= :: DayOfMonthSpec -> DayOfMonthSpec -> Bool
Eq, DayOfMonthSpec -> Text
(DayOfMonthSpec -> Text) -> ShowT DayOfMonthSpec
forall a. (a -> Text) -> ShowT a
$cshowT :: DayOfMonthSpec -> Text
showT :: DayOfMonthSpec -> Text
ShowT, (forall x. DayOfMonthSpec -> Rep DayOfMonthSpec x)
-> (forall x. Rep DayOfMonthSpec x -> DayOfMonthSpec)
-> Generic DayOfMonthSpec
forall x. Rep DayOfMonthSpec x -> DayOfMonthSpec
forall x. DayOfMonthSpec -> Rep DayOfMonthSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DayOfMonthSpec -> Rep DayOfMonthSpec x
from :: forall x. DayOfMonthSpec -> Rep DayOfMonthSpec x
$cto :: forall x. Rep DayOfMonthSpec x -> DayOfMonthSpec
to :: forall x. Rep DayOfMonthSpec x -> DayOfMonthSpec
Generic, Typeable DayOfMonthSpec
Typeable DayOfMonthSpec =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> DayOfMonthSpec -> c DayOfMonthSpec)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DayOfMonthSpec)
-> (DayOfMonthSpec -> Constr)
-> (DayOfMonthSpec -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DayOfMonthSpec))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DayOfMonthSpec))
-> ((forall b. Data b => b -> b)
    -> DayOfMonthSpec -> DayOfMonthSpec)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> DayOfMonthSpec -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> DayOfMonthSpec -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> DayOfMonthSpec -> m DayOfMonthSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DayOfMonthSpec -> m DayOfMonthSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> DayOfMonthSpec -> m DayOfMonthSpec)
-> Data DayOfMonthSpec
DayOfMonthSpec -> Constr
DayOfMonthSpec -> DataType
(forall b. Data b => b -> b) -> DayOfMonthSpec -> DayOfMonthSpec
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> DayOfMonthSpec -> u
forall u. (forall d. Data d => d -> u) -> DayOfMonthSpec -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DayOfMonthSpec
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DayOfMonthSpec -> c DayOfMonthSpec
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DayOfMonthSpec)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DayOfMonthSpec)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DayOfMonthSpec -> c DayOfMonthSpec
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DayOfMonthSpec -> c DayOfMonthSpec
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DayOfMonthSpec
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DayOfMonthSpec
$ctoConstr :: DayOfMonthSpec -> Constr
toConstr :: DayOfMonthSpec -> Constr
$cdataTypeOf :: DayOfMonthSpec -> DataType
dataTypeOf :: DayOfMonthSpec -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DayOfMonthSpec)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DayOfMonthSpec)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DayOfMonthSpec)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DayOfMonthSpec)
$cgmapT :: (forall b. Data b => b -> b) -> DayOfMonthSpec -> DayOfMonthSpec
gmapT :: (forall b. Data b => b -> b) -> DayOfMonthSpec -> DayOfMonthSpec
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfMonthSpec -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DayOfMonthSpec -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> DayOfMonthSpec -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> DayOfMonthSpec -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> DayOfMonthSpec -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> DayOfMonthSpec -> m DayOfMonthSpec
Data, Typeable)


instance Show DayOfMonthSpec where
  show :: DayOfMonthSpec -> String
show (DaysOfMonth CronField
cf) = CronField -> String
forall a. Show a => a -> String
show CronField
cf


mkDayOfMonthSpec :: CronField -> Maybe DayOfMonthSpec
mkDayOfMonthSpec :: CronField -> Maybe DayOfMonthSpec
mkDayOfMonthSpec CronField
cf
  | CronField -> Int -> Int -> Bool
validCF CronField
cf Int
1 Int
31 = DayOfMonthSpec -> Maybe DayOfMonthSpec
forall a. a -> Maybe a
Just (CronField -> DayOfMonthSpec
DaysOfMonth CronField
cf)
  | Bool
otherwise       = Maybe DayOfMonthSpec
forall a. Maybe a
Nothing


-------------------------------------------------------------------------------
-- | Month field of a cron expression
newtype MonthSpec = Months {
      MonthSpec -> CronField
monthSpec :: CronField
    } deriving (MonthSpec -> MonthSpec -> Bool
(MonthSpec -> MonthSpec -> Bool)
-> (MonthSpec -> MonthSpec -> Bool) -> Eq MonthSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MonthSpec -> MonthSpec -> Bool
== :: MonthSpec -> MonthSpec -> Bool
$c/= :: MonthSpec -> MonthSpec -> Bool
/= :: MonthSpec -> MonthSpec -> Bool
Eq, MonthSpec -> Text
(MonthSpec -> Text) -> ShowT MonthSpec
forall a. (a -> Text) -> ShowT a
$cshowT :: MonthSpec -> Text
showT :: MonthSpec -> Text
ShowT, (forall x. MonthSpec -> Rep MonthSpec x)
-> (forall x. Rep MonthSpec x -> MonthSpec) -> Generic MonthSpec
forall x. Rep MonthSpec x -> MonthSpec
forall x. MonthSpec -> Rep MonthSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MonthSpec -> Rep MonthSpec x
from :: forall x. MonthSpec -> Rep MonthSpec x
$cto :: forall x. Rep MonthSpec x -> MonthSpec
to :: forall x. Rep MonthSpec x -> MonthSpec
Generic, Typeable MonthSpec
Typeable MonthSpec =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> MonthSpec -> c MonthSpec)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c MonthSpec)
-> (MonthSpec -> Constr)
-> (MonthSpec -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c MonthSpec))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MonthSpec))
-> ((forall b. Data b => b -> b) -> MonthSpec -> MonthSpec)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> MonthSpec -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> MonthSpec -> r)
-> (forall u. (forall d. Data d => d -> u) -> MonthSpec -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> MonthSpec -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec)
-> Data MonthSpec
MonthSpec -> Constr
MonthSpec -> DataType
(forall b. Data b => b -> b) -> MonthSpec -> MonthSpec
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> MonthSpec -> u
forall u. (forall d. Data d => d -> u) -> MonthSpec -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MonthSpec -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MonthSpec -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MonthSpec
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MonthSpec -> c MonthSpec
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MonthSpec)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MonthSpec)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MonthSpec -> c MonthSpec
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MonthSpec -> c MonthSpec
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MonthSpec
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MonthSpec
$ctoConstr :: MonthSpec -> Constr
toConstr :: MonthSpec -> Constr
$cdataTypeOf :: MonthSpec -> DataType
dataTypeOf :: MonthSpec -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MonthSpec)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MonthSpec)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MonthSpec)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MonthSpec)
$cgmapT :: (forall b. Data b => b -> b) -> MonthSpec -> MonthSpec
gmapT :: (forall b. Data b => b -> b) -> MonthSpec -> MonthSpec
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MonthSpec -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MonthSpec -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MonthSpec -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MonthSpec -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> MonthSpec -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> MonthSpec -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MonthSpec -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MonthSpec -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MonthSpec -> m MonthSpec
Data, Typeable)


instance Show MonthSpec where
  show :: MonthSpec -> String
show (Months CronField
cf) = CronField -> String
forall a. Show a => a -> String
show CronField
cf


mkMonthSpec :: CronField -> Maybe MonthSpec
mkMonthSpec :: CronField -> Maybe MonthSpec
mkMonthSpec CronField
cf
  | CronField -> Int -> Int -> Bool
validCF CronField
cf Int
1 Int
12 = MonthSpec -> Maybe MonthSpec
forall a. a -> Maybe a
Just (CronField -> MonthSpec
Months CronField
cf)
  | Bool
otherwise       = Maybe MonthSpec
forall a. Maybe a
Nothing


-------------------------------------------------------------------------------
-- | Day of week field of a cron expression
newtype DayOfWeekSpec = DaysOfWeek {
      DayOfWeekSpec -> CronField
dayOfWeekSpec :: CronField
    } deriving (DayOfWeekSpec -> DayOfWeekSpec -> Bool
(DayOfWeekSpec -> DayOfWeekSpec -> Bool)
-> (DayOfWeekSpec -> DayOfWeekSpec -> Bool) -> Eq DayOfWeekSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DayOfWeekSpec -> DayOfWeekSpec -> Bool
== :: DayOfWeekSpec -> DayOfWeekSpec -> Bool
$c/= :: DayOfWeekSpec -> DayOfWeekSpec -> Bool
/= :: DayOfWeekSpec -> DayOfWeekSpec -> Bool
Eq, DayOfWeekSpec -> Text
(DayOfWeekSpec -> Text) -> ShowT DayOfWeekSpec
forall a. (a -> Text) -> ShowT a
$cshowT :: DayOfWeekSpec -> Text
showT :: DayOfWeekSpec -> Text
ShowT, (forall x. DayOfWeekSpec -> Rep DayOfWeekSpec x)
-> (forall x. Rep DayOfWeekSpec x -> DayOfWeekSpec)
-> Generic DayOfWeekSpec
forall x. Rep DayOfWeekSpec x -> DayOfWeekSpec
forall x. DayOfWeekSpec -> Rep DayOfWeekSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DayOfWeekSpec -> Rep DayOfWeekSpec x
from :: forall x. DayOfWeekSpec -> Rep DayOfWeekSpec x
$cto :: forall x. Rep DayOfWeekSpec x -> DayOfWeekSpec
to :: forall x. Rep DayOfWeekSpec x -> DayOfWeekSpec
Generic, Typeable DayOfWeekSpec
Typeable DayOfWeekSpec =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> DayOfWeekSpec -> c DayOfWeekSpec)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DayOfWeekSpec)
-> (DayOfWeekSpec -> Constr)
-> (DayOfWeekSpec -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DayOfWeekSpec))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DayOfWeekSpec))
-> ((forall b. Data b => b -> b) -> DayOfWeekSpec -> DayOfWeekSpec)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r)
-> (forall u. (forall d. Data d => d -> u) -> DayOfWeekSpec -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> DayOfWeekSpec -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec)
-> Data DayOfWeekSpec
DayOfWeekSpec -> Constr
DayOfWeekSpec -> DataType
(forall b. Data b => b -> b) -> DayOfWeekSpec -> DayOfWeekSpec
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> DayOfWeekSpec -> u
forall u. (forall d. Data d => d -> u) -> DayOfWeekSpec -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DayOfWeekSpec
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DayOfWeekSpec -> c DayOfWeekSpec
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DayOfWeekSpec)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DayOfWeekSpec)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DayOfWeekSpec -> c DayOfWeekSpec
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DayOfWeekSpec -> c DayOfWeekSpec
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DayOfWeekSpec
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DayOfWeekSpec
$ctoConstr :: DayOfWeekSpec -> Constr
toConstr :: DayOfWeekSpec -> Constr
$cdataTypeOf :: DayOfWeekSpec -> DataType
dataTypeOf :: DayOfWeekSpec -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DayOfWeekSpec)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DayOfWeekSpec)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DayOfWeekSpec)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DayOfWeekSpec)
$cgmapT :: (forall b. Data b => b -> b) -> DayOfWeekSpec -> DayOfWeekSpec
gmapT :: (forall b. Data b => b -> b) -> DayOfWeekSpec -> DayOfWeekSpec
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DayOfWeekSpec -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DayOfWeekSpec -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> DayOfWeekSpec -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DayOfWeekSpec -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DayOfWeekSpec -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DayOfWeekSpec -> m DayOfWeekSpec
Data, Typeable)


instance Show DayOfWeekSpec where
  show :: DayOfWeekSpec -> String
show (DaysOfWeek CronField
cf) = CronField -> String
forall a. Show a => a -> String
show CronField
cf


mkDayOfWeekSpec :: CronField -> Maybe DayOfWeekSpec
mkDayOfWeekSpec :: CronField -> Maybe DayOfWeekSpec
mkDayOfWeekSpec CronField
cf
  -- 0-7 is a matter of some debate but we'll be liberal here
  | CronField -> Int -> Int -> Bool
validCF CronField
cf Int
0 Int
7  = DayOfWeekSpec -> Maybe DayOfWeekSpec
forall a. a -> Maybe a
Just (CronField -> DayOfWeekSpec
DaysOfWeek CronField
cf)
  | Bool
otherwise       = Maybe DayOfWeekSpec
forall a. Maybe a
Nothing


-------------------------------------------------------------------------------
validCF
    :: CronField
    -> Int
    -- ^ Min value
    -> Int
    -- ^ Max value
    -> Bool
validCF :: CronField -> Int -> Int -> Bool
validCF (Field BaseField
bf) Int
mn Int
mx          = BaseField -> Int -> Int -> Bool
validBF BaseField
bf Int
mn Int
mx
validCF (ListField NonEmpty BaseField
bfs) Int
mn Int
mx     = (BaseField -> Bool) -> NonEmpty BaseField -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
FT.all (\BaseField
bf -> BaseField -> Int -> Int -> Bool
validBF BaseField
bf Int
mn Int
mx) NonEmpty BaseField
bfs
validCF (StepField' (StepField BaseField
bf Int
step)) Int
mn Int
mx = BaseField -> Int -> Int -> Bool
validBF BaseField
bf Int
mn Int
mx Bool -> Bool -> Bool
&& (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
mn, Int
mx) Int
step


-------------------------------------------------------------------------------
validBF
    :: BaseField
    -> Int
    -- ^ Min value
    -> Int
    -- ^ Max value
    -> Bool
validBF :: BaseField -> Int -> Int -> Bool
validBF BaseField
Star Int
_ Int
_ = Bool
True
validBF (SpecificField' (SpecificField Int
n)) Int
mn Int
mx =
  (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
mn, Int
mx) Int
n
validBF (RangeField' (RangeField Int
n1 Int
n2)) Int
mn Int
mx =
  (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
mn, Int
mx) Int
n1 Bool -> Bool -> Bool
&& (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
mn, Int
mx) Int
n2


-------------------------------------------------------------------------------
-- | Individual field of a cron expression.
data BaseField = Star                         -- ^ Matches anything
               | SpecificField' SpecificField -- ^ Matches a specific value (e.g. 1)
               | RangeField' RangeField       -- ^ Matches a range of values (e.g. 1-3)
               deriving (BaseField -> BaseField -> Bool
(BaseField -> BaseField -> Bool)
-> (BaseField -> BaseField -> Bool) -> Eq BaseField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BaseField -> BaseField -> Bool
== :: BaseField -> BaseField -> Bool
$c/= :: BaseField -> BaseField -> Bool
/= :: BaseField -> BaseField -> Bool
Eq, (forall x. BaseField -> Rep BaseField x)
-> (forall x. Rep BaseField x -> BaseField) -> Generic BaseField
forall x. Rep BaseField x -> BaseField
forall x. BaseField -> Rep BaseField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BaseField -> Rep BaseField x
from :: forall x. BaseField -> Rep BaseField x
$cto :: forall x. Rep BaseField x -> BaseField
to :: forall x. Rep BaseField x -> BaseField
Generic, Typeable BaseField
Typeable BaseField =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BaseField -> c BaseField)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BaseField)
-> (BaseField -> Constr)
-> (BaseField -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BaseField))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseField))
-> ((forall b. Data b => b -> b) -> BaseField -> BaseField)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BaseField -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BaseField -> r)
-> (forall u. (forall d. Data d => d -> u) -> BaseField -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BaseField -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BaseField -> m BaseField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BaseField -> m BaseField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BaseField -> m BaseField)
-> Data BaseField
BaseField -> Constr
BaseField -> DataType
(forall b. Data b => b -> b) -> BaseField -> BaseField
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BaseField -> u
forall u. (forall d. Data d => d -> u) -> BaseField -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseField -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseField -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseField
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseField -> c BaseField
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseField)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseField)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseField -> c BaseField
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseField -> c BaseField
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseField
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseField
$ctoConstr :: BaseField -> Constr
toConstr :: BaseField -> Constr
$cdataTypeOf :: BaseField -> DataType
dataTypeOf :: BaseField -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseField)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseField)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseField)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseField)
$cgmapT :: (forall b. Data b => b -> b) -> BaseField -> BaseField
gmapT :: (forall b. Data b => b -> b) -> BaseField -> BaseField
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseField -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseField -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseField -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseField -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BaseField -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BaseField -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BaseField -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BaseField -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseField -> m BaseField
Data, Typeable)


instance ShowT BaseField where
  showT :: BaseField -> Text
showT BaseField
Star               = Text
"*"
  showT (SpecificField' SpecificField
f) = SpecificField -> Text
forall a. ShowT a => a -> Text
showT SpecificField
f
  showT (RangeField' RangeField
rf)   = RangeField -> Text
forall a. ShowT a => a -> Text
showT RangeField
rf


instance Show BaseField where
  show :: BaseField -> String
show = Text -> String
T.unpack (Text -> String) -> (BaseField -> Text) -> BaseField -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BaseField -> Text
forall a. ShowT a => a -> Text
showT


-------------------------------------------------------------------------------
newtype SpecificField = SpecificField {
      SpecificField -> Int
specificField :: Int
    } deriving (SpecificField -> SpecificField -> Bool
(SpecificField -> SpecificField -> Bool)
-> (SpecificField -> SpecificField -> Bool) -> Eq SpecificField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SpecificField -> SpecificField -> Bool
== :: SpecificField -> SpecificField -> Bool
$c/= :: SpecificField -> SpecificField -> Bool
/= :: SpecificField -> SpecificField -> Bool
Eq, SpecificField -> Text
(SpecificField -> Text) -> ShowT SpecificField
forall a. (a -> Text) -> ShowT a
$cshowT :: SpecificField -> Text
showT :: SpecificField -> Text
ShowT, (forall x. SpecificField -> Rep SpecificField x)
-> (forall x. Rep SpecificField x -> SpecificField)
-> Generic SpecificField
forall x. Rep SpecificField x -> SpecificField
forall x. SpecificField -> Rep SpecificField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SpecificField -> Rep SpecificField x
from :: forall x. SpecificField -> Rep SpecificField x
$cto :: forall x. Rep SpecificField x -> SpecificField
to :: forall x. Rep SpecificField x -> SpecificField
Generic, Typeable SpecificField
Typeable SpecificField =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> SpecificField -> c SpecificField)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SpecificField)
-> (SpecificField -> Constr)
-> (SpecificField -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SpecificField))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c SpecificField))
-> ((forall b. Data b => b -> b) -> SpecificField -> SpecificField)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SpecificField -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SpecificField -> r)
-> (forall u. (forall d. Data d => d -> u) -> SpecificField -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SpecificField -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SpecificField -> m SpecificField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SpecificField -> m SpecificField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SpecificField -> m SpecificField)
-> Data SpecificField
SpecificField -> Constr
SpecificField -> DataType
(forall b. Data b => b -> b) -> SpecificField -> SpecificField
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> SpecificField -> u
forall u. (forall d. Data d => d -> u) -> SpecificField -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SpecificField -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SpecificField -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SpecificField
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SpecificField -> c SpecificField
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SpecificField)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SpecificField)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SpecificField -> c SpecificField
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SpecificField -> c SpecificField
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SpecificField
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SpecificField
$ctoConstr :: SpecificField -> Constr
toConstr :: SpecificField -> Constr
$cdataTypeOf :: SpecificField -> DataType
dataTypeOf :: SpecificField -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SpecificField)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SpecificField)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SpecificField)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SpecificField)
$cgmapT :: (forall b. Data b => b -> b) -> SpecificField -> SpecificField
gmapT :: (forall b. Data b => b -> b) -> SpecificField -> SpecificField
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SpecificField -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SpecificField -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SpecificField -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SpecificField -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SpecificField -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> SpecificField -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SpecificField -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SpecificField -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SpecificField -> m SpecificField
Data, Typeable)


instance Show SpecificField where
  show :: SpecificField -> String
show = Text -> String
T.unpack (Text -> String)
-> (SpecificField -> Text) -> SpecificField -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpecificField -> Text
forall a. ShowT a => a -> Text
showT


mkSpecificField :: Int -> Maybe SpecificField
mkSpecificField :: Int -> Maybe SpecificField
mkSpecificField Int
n
  | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 = SpecificField -> Maybe SpecificField
forall a. a -> Maybe a
Just (Int -> SpecificField
SpecificField Int
n)
  | Bool
otherwise = Maybe SpecificField
forall a. Maybe a
Nothing


-------------------------------------------------------------------------------
data RangeField = RangeField {
      RangeField -> Int
rfBegin :: Int
    , RangeField -> Int
rfEnd   :: Int
    } deriving (RangeField -> RangeField -> Bool
(RangeField -> RangeField -> Bool)
-> (RangeField -> RangeField -> Bool) -> Eq RangeField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RangeField -> RangeField -> Bool
== :: RangeField -> RangeField -> Bool
$c/= :: RangeField -> RangeField -> Bool
/= :: RangeField -> RangeField -> Bool
Eq, (forall x. RangeField -> Rep RangeField x)
-> (forall x. Rep RangeField x -> RangeField) -> Generic RangeField
forall x. Rep RangeField x -> RangeField
forall x. RangeField -> Rep RangeField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RangeField -> Rep RangeField x
from :: forall x. RangeField -> Rep RangeField x
$cto :: forall x. Rep RangeField x -> RangeField
to :: forall x. Rep RangeField x -> RangeField
Generic, Typeable RangeField
Typeable RangeField =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> RangeField -> c RangeField)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c RangeField)
-> (RangeField -> Constr)
-> (RangeField -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c RangeField))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c RangeField))
-> ((forall b. Data b => b -> b) -> RangeField -> RangeField)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> RangeField -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> RangeField -> r)
-> (forall u. (forall d. Data d => d -> u) -> RangeField -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> RangeField -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> RangeField -> m RangeField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RangeField -> m RangeField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RangeField -> m RangeField)
-> Data RangeField
RangeField -> Constr
RangeField -> DataType
(forall b. Data b => b -> b) -> RangeField -> RangeField
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> RangeField -> u
forall u. (forall d. Data d => d -> u) -> RangeField -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RangeField -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RangeField -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RangeField
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RangeField -> c RangeField
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RangeField)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RangeField)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RangeField -> c RangeField
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RangeField -> c RangeField
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RangeField
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RangeField
$ctoConstr :: RangeField -> Constr
toConstr :: RangeField -> Constr
$cdataTypeOf :: RangeField -> DataType
dataTypeOf :: RangeField -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RangeField)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RangeField)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RangeField)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RangeField)
$cgmapT :: (forall b. Data b => b -> b) -> RangeField -> RangeField
gmapT :: (forall b. Data b => b -> b) -> RangeField -> RangeField
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RangeField -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RangeField -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RangeField -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RangeField -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RangeField -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> RangeField -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RangeField -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RangeField -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RangeField -> m RangeField
Data, Typeable)


instance ShowT RangeField where
  showT :: RangeField -> Text
showT (RangeField Int
x Int
y) = Int -> Text
forall a. ShowT a => a -> Text
showT Int
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. ShowT a => a -> Text
showT Int
y


instance Show RangeField where
  show :: RangeField -> String
show = Text -> String
T.unpack (Text -> String) -> (RangeField -> Text) -> RangeField -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RangeField -> Text
forall a. ShowT a => a -> Text
showT


mkRangeField :: Int -> Int -> Maybe RangeField
mkRangeField :: Int -> Int -> Maybe RangeField
mkRangeField Int
x Int
y
  | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
y    = RangeField -> Maybe RangeField
forall a. a -> Maybe a
Just (Int -> Int -> RangeField
RangeField Int
x Int
y)
  | Bool
otherwise = Maybe RangeField
forall a. Maybe a
Nothing



-------------------------------------------------------------------------------
data CronField = Field BaseField
               | ListField (NonEmpty BaseField) -- ^ Matches a list of expressions.
               | StepField' StepField           -- ^ Matches a stepped expression, e.g. (*/2).
               deriving ((forall x. CronField -> Rep CronField x)
-> (forall x. Rep CronField x -> CronField) -> Generic CronField
forall x. Rep CronField x -> CronField
forall x. CronField -> Rep CronField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CronField -> Rep CronField x
from :: forall x. CronField -> Rep CronField x
$cto :: forall x. Rep CronField x -> CronField
to :: forall x. Rep CronField x -> CronField
Generic, Typeable CronField
Typeable CronField =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> CronField -> c CronField)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CronField)
-> (CronField -> Constr)
-> (CronField -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CronField))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CronField))
-> ((forall b. Data b => b -> b) -> CronField -> CronField)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CronField -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CronField -> r)
-> (forall u. (forall d. Data d => d -> u) -> CronField -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CronField -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CronField -> m CronField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CronField -> m CronField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CronField -> m CronField)
-> Data CronField
CronField -> Constr
CronField -> DataType
(forall b. Data b => b -> b) -> CronField -> CronField
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CronField -> u
forall u. (forall d. Data d => d -> u) -> CronField -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronField -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronField -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronField
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronField -> c CronField
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronField)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CronField)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronField -> c CronField
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CronField -> c CronField
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronField
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CronField
$ctoConstr :: CronField -> Constr
toConstr :: CronField -> Constr
$cdataTypeOf :: CronField -> DataType
dataTypeOf :: CronField -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronField)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CronField)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CronField)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CronField)
$cgmapT :: (forall b. Data b => b -> b) -> CronField -> CronField
gmapT :: (forall b. Data b => b -> b) -> CronField -> CronField
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronField -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CronField -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronField -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CronField -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CronField -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> CronField -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CronField -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CronField -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CronField -> m CronField
Data, Typeable)


instance Eq CronField where
  Field BaseField
a == :: CronField -> CronField -> Bool
== Field BaseField
b = BaseField
a BaseField -> BaseField -> Bool
forall a. Eq a => a -> a -> Bool
== BaseField
b
  Field BaseField
a == ListField (BaseField
b :| []) = BaseField
a BaseField -> BaseField -> Bool
forall a. Eq a => a -> a -> Bool
== BaseField
b
  ListField NonEmpty BaseField
as == ListField NonEmpty BaseField
bs = NonEmpty BaseField
as NonEmpty BaseField -> NonEmpty BaseField -> Bool
forall a. Eq a => a -> a -> Bool
== NonEmpty BaseField
bs
  ListField (BaseField
a :| []) == Field BaseField
b = BaseField
a BaseField -> BaseField -> Bool
forall a. Eq a => a -> a -> Bool
== BaseField
b
  StepField' StepField
a == StepField' StepField
b = StepField
a StepField -> StepField -> Bool
forall a. Eq a => a -> a -> Bool
== StepField
b
  CronField
_ == CronField
_ = Bool
False


instance ShowT CronField where
  showT :: CronField -> Text
showT (Field BaseField
f)       = BaseField -> Text
forall a. ShowT a => a -> Text
showT BaseField
f
  showT (ListField NonEmpty BaseField
xs)  = Text -> [Text] -> Text
T.intercalate Text
"," (NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
NE.toList (BaseField -> Text
forall a. ShowT a => a -> Text
showT (BaseField -> Text) -> NonEmpty BaseField -> NonEmpty Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty BaseField
xs))
  showT (StepField' StepField
sf) = StepField -> Text
forall a. ShowT a => a -> Text
showT StepField
sf


instance Show CronField where
  show :: CronField -> String
show = Text -> String
T.unpack (Text -> String) -> (CronField -> Text) -> CronField -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CronField -> Text
forall a. ShowT a => a -> Text
showT


-------------------------------------------------------------------------------
data StepField = StepField { StepField -> BaseField
sfField    :: BaseField
                           , StepField -> Int
sfStepping :: Int
                           } deriving (StepField -> StepField -> Bool
(StepField -> StepField -> Bool)
-> (StepField -> StepField -> Bool) -> Eq StepField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StepField -> StepField -> Bool
== :: StepField -> StepField -> Bool
$c/= :: StepField -> StepField -> Bool
/= :: StepField -> StepField -> Bool
Eq, (forall x. StepField -> Rep StepField x)
-> (forall x. Rep StepField x -> StepField) -> Generic StepField
forall x. Rep StepField x -> StepField
forall x. StepField -> Rep StepField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. StepField -> Rep StepField x
from :: forall x. StepField -> Rep StepField x
$cto :: forall x. Rep StepField x -> StepField
to :: forall x. Rep StepField x -> StepField
Generic, Typeable StepField
Typeable StepField =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> StepField -> c StepField)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c StepField)
-> (StepField -> Constr)
-> (StepField -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c StepField))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StepField))
-> ((forall b. Data b => b -> b) -> StepField -> StepField)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> StepField -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> StepField -> r)
-> (forall u. (forall d. Data d => d -> u) -> StepField -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> StepField -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> StepField -> m StepField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> StepField -> m StepField)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> StepField -> m StepField)
-> Data StepField
StepField -> Constr
StepField -> DataType
(forall b. Data b => b -> b) -> StepField -> StepField
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> StepField -> u
forall u. (forall d. Data d => d -> u) -> StepField -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> StepField -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> StepField -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c StepField
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> StepField -> c StepField
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c StepField)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StepField)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> StepField -> c StepField
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> StepField -> c StepField
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c StepField
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c StepField
$ctoConstr :: StepField -> Constr
toConstr :: StepField -> Constr
$cdataTypeOf :: StepField -> DataType
dataTypeOf :: StepField -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c StepField)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c StepField)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StepField)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StepField)
$cgmapT :: (forall b. Data b => b -> b) -> StepField -> StepField
gmapT :: (forall b. Data b => b -> b) -> StepField -> StepField
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> StepField -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> StepField -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> StepField -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> StepField -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> StepField -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> StepField -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> StepField -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> StepField -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> StepField -> m StepField
Data, Typeable)


instance ShowT StepField where
  showT :: StepField -> Text
showT (StepField BaseField
f Int
step) = BaseField -> Text
forall a. ShowT a => a -> Text
showT BaseField
f Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. ShowT a => a -> Text
showT Int
step


instance Show StepField where
  show :: StepField -> String
show = Text -> String
T.unpack (Text -> String) -> (StepField -> Text) -> StepField -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StepField -> Text
forall a. ShowT a => a -> Text
showT


mkStepField :: BaseField -> Int -> Maybe StepField
mkStepField :: BaseField -> Int -> Maybe StepField
mkStepField BaseField
bf Int
n
  | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0     = StepField -> Maybe StepField
forall a. a -> Maybe a
Just (BaseField -> Int -> StepField
StepField BaseField
bf Int
n)
  | Bool
otherwise = Maybe StepField
forall a. Maybe a
Nothing