Description
Parse Cron Format Strings, Compose Cron Format Strings and Caluclate Execution Date Candidates
Crontab alternatives and similar packages
Based on the "Date and Time" category.
Alternatively, view Crontab alternatives based on common mentions on social networks and blogs.
-
filtrex
A library for performing and validating complex filters from a client (e.g. smart filters) -
Ex_Cldr_Dates_Times
Date & times formatting functions for the Common Locale Data Repository (CLDR) package https://github.com/elixir-cldr/cldr -
jalaali
Jalaali (also known as Jalali, Persian, Khorshidi, Shamsi) calendar implementation in Elixir. -
timex_interval
A date/time interval library for Elixir projects, based on Timex. -
block_timer
Macros to use :timer.apply_after and :timer.apply_interval with a block -
emojiclock
An Elixir module for returning an emoji clock for a given hour -
Calixir
Calixir is a port of the Lisp calendar software calendrica-4.0 to Elixir. -
japan_municipality_key
Elixir Library for Japan municipality key converting
Access the most powerful time series database as a service
Do you think we are missing an alternative of Crontab or a related project?
Popular Comparisons
README
Crontab
Elixir library for parsing, writing, and calculating Cron format strings.
Installation
Add :crontab
to your list of dependencies in mix.exs
:
def deps do
[
{:crontab, "~> 1.1"}
]
end
For Elixir version before 1.4, ensure :crontab
is started before your
application:
def application do
[
applications: [:crontab]
]
end
Usage
Import Cron expression sigil
Everywhere you want to use the Cron expression sigil (e[cron expression]
).
import Crontab.CronExpression
Extended Cron expressions
An extended Cron expression has more precision than a normal Cron expression. It also specifies the second.
If you want to use extended Cron expressions with the sigil, just append an e
.
Checking if a Cron Expression Matches a date
iex> import Crontab.CronExpression
iex> Crontab.DateChecker.matches_date?(~e[*/2], ~N[2017-01-01 01:01:00])
false
iex> Crontab.DateChecker.matches_date?(~e[*], ~N[2017-01-01 01:01:00])
true
Find Next / Previous Execution Date candidates
All the date parameters default to now.
For previous, just replace next
in the code below.
iex> import Crontab.CronExpression
iex> Crontab.Scheduler.get_next_run_date(~e[*/2], ~N[2017-01-01 01:01:00])
{:ok, ~N[2017-01-01 01:02:00]}
iex> Crontab.Scheduler.get_next_run_date!(~e[*/2], ~N[2017-01-01 01:01:00])
~N[2017-01-01 01:02:00]
iex> Crontab.Scheduler.get_next_run_dates(3, ~e[*/2], ~N[2017-01-01 01:01:00])
{:ok,
[~N[2017-01-01 01:02:00], ~N[2017-01-01 01:04:00], ~N[2017-01-01 01:06:00]]}
iex> Crontab.Scheduler.get_next_run_dates!(3, ~e[*/2], ~N[2017-01-01 01:01:00])
[~N[2017-01-01 01:02:00], ~N[2017-01-01 01:04:00], ~N[2017-01-01 01:06:00]]
Parse Cron Expressions
If you statically define cron expressions, use the ~e[cron expression]
sigil.
For dynamic cron expressions, there is a Parser module.
The parser module takes an optional extended
flag. This is to mark if the
expression contains seconds. This defaults to false
.
iex> Crontab.CronExpression.Parser.parse "* * * * *"
{:ok,
%Crontab.CronExpression{day: [:*], hour: [:*], minute: [:*],
month: [:*], weekday: [:*], year: [:*]}}
iex> Crontab.CronExpression.Parser.parse! "* * * * *"
%Crontab.CronExpression{day: [:*], hour: [:*], minute: [:*],
month: [:*], weekday: [:*], year: [:*]}
Compose Cron expressions
iex> Crontab.CronExpression.Composer.compose %Crontab.CronExpression{}
"* * * * * *"
iex> Crontab.CronExpression.Composer.compose %Crontab.CronExpression{minute: [9, {:-, 4, 6}, {:/, :*, 9}]}
"9,4-6,*/9 * * * * *"
Copyright and License
Copyright (c) 2016, SK & T AG, JOSHMARTIN GmbH, Jonatan Männchen
This library is MIT licensed. See the LICENSE for details.
*Note that all licence references and agreements mentioned in the Crontab README section above
are relevant to that project's source code only.