Git Product home page Git Product logo

swiftcron's Introduction

SwiftCron

Build Status codecov CocoaPod Version

A cron expression parser that can take a cron string and give you the next run date and time specified in the string.


Installation

CocoaPods

Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'SwiftCron'

Carthage

Cartfile:

github "thecodedself/swiftcron" >= 0.4.5

Swift Package Manager

Package.swift:

.Package(url: "https://github.com/TheCodedSelf/SwiftCron.git", majorVersion: 0)

Usage

Create a Cron Expression

Creating a cron expression is easy. Just invoke the initializer with the fields you want.

// Midnight every 8th day of the month
let myCronExpression = CronExpression(minute: "0", hour: "0", day: "8")
// Executes May 9th, 2024 at 11:30am
let anotherExpression = CronExpression(minute: "30", hour: "11", day: "9", month: "5", year: "2024") 
// Every tuesday at 6:00pm
let everyTuesday = CronExpression(minute: "0", hour: "18", weekday: "3")

Manually create an expression

If you'd like to manually write the expression yourself, The cron format is as follows:

* * * * * *
(Minute) (Hour) (Day) (Month) (Weekday) (Year)

Initialize an instance of CronExpression with a string specifying the format.

// Every 11th May at midnight
let every11May = CronExpression(cronString: "0 0 11 5 * *")

Get the next run date

Once you have your CronExpression, you can get the next time the cron will run. Call the getNextRunDate(_:) method and pass in the date to begin the search on.

// Every Friday 13th at midday
let myCronExpression = CronExpression(minute: "0", hour: "12", day: "13", weekday: "5")

let dateToStartSearchOn = NSDate()
let nextRunDate = myCronExpression.getNextRunDate(dateToStartSearchOn)

Contributing

  • Pull requests for bug fixes and new features are most welcome.
  • Pull requests will only be merged once the Travis CI build passes.

Requirements

  • iOS 9.0 or greater
  • Xcode 8.0 or greater
  • Swift 3 or greater

swiftcron's People

Contributors

angrymango avatar dynamicy avatar thecodedself avatar zeeshankhan avatar

Watchers

 avatar  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.