Code Monkey home page Code Monkey logo

cron-swift's Introduction

Cron for Swift

TravisCI

Installation

Swift Package Manager

Add the following line to your Package.swift file

.package(url: "https://github.com/Ponyboy47/Cron-Swift.git", from: "2.3.0")

Usage

import Cron

let job = try? CronJob(pattern: "*/10 * * * * *") { () -> Void in
    print("job executes every 10 seconds")
}

Cron Pattern Syntax

5 - 7 fields separated by TAB or whitespace:

Field name Range Special Characters Remarks
second 0-59 * / , - H
minute 0-59 * / , - H
hour 0-23 * / , - H L W
day of month 1-31 * / , - H
month 1-12 or JAN-DEC * / , -
day of week 0-7 or SUN-SAT * / , - L # 0 or 7 is SUN
year - * / , -

The reference documentation for this implementation is found at Wikipedia.

Special Characters

Asterisk (*)

Asterisk means the full range in the field. For example, * for an hour entry implies 0-23.

Slash (/)

Slashes can be combined with ranges to specify step values.

Comma (,)

Commas are used to separate items of a list.

Hyphen (-)

Hyphens are used for ranges.

Ranges are two numbers separated with a hyphen. For example, 8-11 for an hours entry specifies execution at hours 8, 9, 10 and 11.

Number sign (#)

'#' is allowed for the day-of-week field, and must be followed by a number between one and five. It allows you to specify constructs such as "the second Friday" of a given month.

Hash (H)

The H symbol can be used like a range. For example, H H(0-7) * * * means some time between 0:00 AM (midnight) to 7:59 AM.

The H symbol can be thought of as a random value over a range, but it actually is a hash of the given value, not a random function, so that the value remains stable for it.

Last (L)

When used in the day-of-week field, it allows you to specify constructs such as "the last Friday" ("5L") of a given month. In the day-of-month field, it specifies the last day of the month.

Weekday (W)

This character is used to specify the weekday (Monday to Friday) nearest the given day.

cron-swift's People

Contributors

ponyboy47 avatar safx avatar eliekarouz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.