Giter Site home page Giter Site logo

npcron's Introduction

CronCppParser

A parser for Cron syntax that follows whatever specified in CronTabGuru Try to make it easy to use with simple interfaces:

  • Create a Parser to validate the syntax of Cron
  • Get a Cron Clock Object to determine the next time_point of scheduler specified by given Cron Expression

Sample

    std::string expression = "0 0 1-25/3 1/3 *";
    try
    {
        auto clock = Cron::Parser(expression).createClock();
        //you can also use clock.getNext() to get std::chrono::time_point value
        std::cout << "your next action from now is at: " << clock.getNextCTime() << std::endl;
        std::cout << "Next 10 scheduled Time from now is: \n";
        for(int i = 0; i < 10; ++i)
        {
            std::cout << clock.getNextCTime(false /*true = current moment*/) << "\n";
        }
    }
    catch(const Cron::BadSyntaxException& s)
    {
        std::cout << s << std::endl;
    }
    catch(const Cron::ImpossibleValueException s1)
    {
        std::cout << s1 << std::endl;
    }

Possible output:

your next action from now is at: Mon Apr 01 00:00:00 2019
Next 10 scheduled Time from now is: 
Thu Apr 04 00:00:00 2019
Sun Apr 07 00:00:00 2019
Wed Apr 10 00:00:00 2019
Sat Apr 13 00:00:00 2019
Tue Apr 16 00:00:00 2019
Fri Apr 19 00:00:00 2019
Mon Apr 22 00:00:00 2019
Thu Apr 25 00:00:00 2019
Mon Jul 01 00:00:00 2019
Thu Jul 04 00:00:00 2019
try
    {
        std::string expression = "0 0 35 2 *";
        auto clock = Cron::Parser(expression).createClock();
    }
    catch(const Cron::BadSyntaxException& s)
    {
        std::cout << s << std::endl;
    }
    catch(const Cron::ImpossibleValueException& s1)
    {
        std::cout << s1 << std::endl;
    }

Output:

Bad Syntax at field MDAY[ 35 ]: Invalid field mday with value: 35

npcron's People

Contributors

sepcon avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

timic3

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.