Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

⏰ Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.

License

NotificationsYou must be signed in to change notification settings

maennchen/crontab

Repository files navigation

Logo featuring a clock

CICoverage StatusModule VersionHex DocsTotal DownloadLicenseLast Updated

Elixir library for parsing, writing, and calculating Cron format strings.


Installation

Add:crontab to your list of dependencies inmix.exs:

defdepsdo[{:crontab,"~> 1.1"}]end

Usage

Import Cron expression sigil

Everywhere you want to use the Cron expression sigil (e[cron expression]).

importCrontab.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 ane.

Checking if a Cron Expression Matches a date

iex>importCrontab.CronExpressioniex>Crontab.DateChecker.matches_date?(~e[*/2],~N[2017-01-01 01:01:00])falseiex>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 replacenext in the code below.

iex>importCrontab.CronExpressioniex>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>Enum.take(Crontab.Scheduler.get_next_run_dates(~e[*/2],~N[2017-01-01 01:01:00]),3)[~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 optionalextended flag. This is to mark if theexpression contains seconds. This defaults tofalse.

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 theLICENSE for details.

About

⏰ Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp