CronSchedule

sealed trait CronSchedule extends Schedule

Defines cron-like utility for scheduled times.

Scheduled Times

CronSchedule determines its scheduled times using fields, where each field is a sorted sequence of distinct values specifying a component of time.

The times field specifies local times in schedule. It must include at least one value.

The daysOfMonth field specifies days of month in schedule. If empty, then every day is implied unless daysOfWeek is non-empty.

The months field specifies months in schedule. If empty, then every month is implied.

The daysOfWeek field specifies days of week in schedule. If empty, then every day is implied unless daysOfMonth is non-empty.

If both daysOfMonth and daysOfWeek are non-empty, then scheduled times are determined as a union of both fields.

import java.time.LocalTime.NOON
import java.time.Month.{ OCTOBER, NOVEMBER, DECEMBER }

import little.time.CronSchedule
import little.time.Implicits.TimeStringType

// Create schedule
val schedule = CronSchedule(
 times       = Seq(NOON),
 daysOfMonth = Seq(1, 15),
 months      = Seq(OCTOBER, NOVEMBER, DECEMBER))

val start = "2020-10-01".toLocalDate
val end   = "2020-12-31".toLocalDate

// Iterate over scheduled times
schedule.between(start, end).foreach { time =>
 println(s"${time.toLocalDate} at ${time.toLocalTime}")
}

// Create schedule using cron-like syntax
val altSchedule = CronSchedule("0 12 1,15 Oct-Dec *")
Companion
object
trait Schedule
class Object
trait Matchable
class Any

Value members

Abstract methods

def daysOfMonth: Seq[Int]

Gets days of month.

Gets days of month.

def daysOfWeek: Seq[DayOfWeek]

Gets days of week.

Gets days of week.

def months: Seq[Month]

Gets months.

Gets months.

def times: Seq[LocalTime]

Gets times.

Gets times.

def withDaysOfMonth(days: Seq[Int]): CronSchedule

Creates new cron schedule by replacing days of month.

Creates new cron schedule by replacing days of month.

Value Params
days

days of month

Returns

new cron schedule

def withDaysOfWeek(days: Seq[DayOfWeek]): CronSchedule

Creates new cron schedule by replacing days of week.

Creates new cron schedule by replacing days of week.

Value Params
days

days of week

Returns

new cron schedule

def withMonths(months: Seq[Month]): CronSchedule

Creates new cron schedule by replacing months.

Creates new cron schedule by replacing months.

Value Params
months

months

Returns

new cron schedule

def withTimes(times: Seq[LocalTime]): CronSchedule

Creates new cron schedule by replacing times.

Creates new cron schedule by replacing times.

Value Params
times

times

Returns

new cron schedule

Concrete methods

def withDaysOfMonth(one: Int, more: Int*): CronSchedule

Creates new cron schedule by replacing days of month.

Creates new cron schedule by replacing days of month.

Value Params
more

additional days of month

one

day of month

Returns

new cron schedule

def withDaysOfWeek(one: DayOfWeek, more: DayOfWeek*): CronSchedule

Creates new cron schedule by replacing days of week.

Creates new cron schedule by replacing days of week.

Value Params
more

additional days of week

one

day of week

Returns

new cron schedule

def withMonths(one: Month, more: Month*): CronSchedule

Creates new cron schedule by replacing months.

Creates new cron schedule by replacing months.

Value Params
more

additional months

one

month

Returns

new cron schedule

def withTimes(one: LocalTime, more: LocalTime*): CronSchedule

Creates new cron schedule by replacing times.

Creates new cron schedule by replacing times.

Value Params
more

additional times

one

time

Returns

new cron schedule

Inherited methods

def +(time: LocalDateTime): Schedule

Creates new schedule by adding supplied scheduled time.

Creates new schedule by adding supplied scheduled time.

Value Params
time

schedule time

Returns

new schedule

Note

Alias to add

Inherited from
Schedule
def ++(other: Schedule): Schedule

Creates new schedule by combining supplied schedule.

Creates new schedule by combining supplied schedule.

Value Params
other

schedule

Returns

new schedule

Note

Alias to combine

Inherited from
Schedule
def add(time: LocalDateTime): Schedule

Creates new schedule by adding supplied scheduled time.

Creates new schedule by adding supplied scheduled time.

Value Params
time

schedule time

Returns

new schedule

Inherited from
Schedule
def between(start: LocalDate, end: LocalDate): Iterator[LocalDateTime]

Gets scheduled times in given period.

Gets scheduled times in given period.

Equivalent to: between(start.atTime(LocalTime.MIN), end.atTime(LocalTime.MAX))

Value Params
end

end of period

start

start of period

Note

Both start and end are inclusive.

Inherited from
Schedule
def between(start: LocalDateTime, end: LocalDateTime): Iterator[LocalDateTime]

Gets scheduled times in given period.

Gets scheduled times in given period.

Value Params
end

end of period

start

start of period

Note

Both start and end are inclusive.

Inherited from
Schedule
def combine(other: Schedule): Schedule

Creates new schedule by combining supplied schedule.

Creates new schedule by combining supplied schedule.

Value Params
other

schedule

Returns

new schedule

Inherited from
Schedule
def next(after: LocalDateTime): Option[LocalDateTime]

Gets next scheduled time after given time.

Gets next scheduled time after given time.

Value Params
after

time after which scheduled time occurs

Inherited from
Schedule