GithubHelp home page GithubHelp logo

Comments (8)

mtdowling avatar mtdowling commented on May 21, 2024

This site reports the cron expression as invalid: http://www.cronmaker.com/

I wonder if the test site you're using is working correctly.

from cron-expression.

patrioticcow avatar patrioticcow commented on May 21, 2024

well, im trying to do a cron: At 14:13 on the 3rd during every February but only if the event takes place on Wednesdays. that seems the right cron..

if i replace the last 3 with * then there is no exception, but i need it every Wednesdays

if i use that website, i get 0 13 14 ? 1/3 WED#3 * but the script gives Invalid CRON field value ? as position 3

from cron-expression.

swekaj avatar swekaj commented on May 21, 2024

That's also an invalid CRON for this library for two reason: it appears to have a 'seconds' field and it uses ? instead of *

Your original expressions should be valid, but it won't match what you want (as indicated by the CRON tester output). I'm pretty sure you'd have to use 13 14 2 3 3#1 * to match only the first Wednesday, however I can't seem to find a cron tester online that supports (and recognizes) the #1 bit.

@mtdowling I'm pretty sure that http://www.cronmaker.com/ is broken. I tried * * * * * and it said the expression was invalid.

from cron-expression.

swekaj avatar swekaj commented on May 21, 2024

@patrioticcow, are you sure you're using the most recent version? It works fine for me on 1.0.4:

$ php -a
Interactive mode enabled

php > require(__DIR__.'/vendor/autoload.php');
php > $c = Cron\CronExpression::factory('13 14 3 2 3');
php > print_r($c->getNextRunDate());
DateTime Object
(
    [date] => 2016-02-03 14:13:00.000000
    [timezone_type] => 3
    [timezone] => UTC
)

from cron-expression.

patrioticcow avatar patrioticcow commented on May 21, 2024

try tunning

foreach ($cron->getMultipleRunDates(5, 'now') as $date) {
    if($date) var_dump($date);
}

from cron-expression.

swekaj avatar swekaj commented on May 21, 2024

That threw the exception you reported. If you change it to get each run date individually (instead of all 5 at once), then you can see that there are no more occurrences beyond 2027 that are within the testable range. That limit is imposed by the library to prevent cron schedules that will never be due causing an infinite loop.

That said, you can get around the limit with something like the following:

$dates = array();
for ($i = 0; $i <= 5; $i++) {
    $date = $i === 0 ? null : $dates[$i - 1];
    $dates[] = $cron->getNextRunDate($date, 0);
}

from cron-expression.

patrioticcow avatar patrioticcow commented on May 21, 2024

it looks like i have to do lots of testing, when creating the cron to begin with, and make sure the this lib supports it.

Thanks

from cron-expression.

swekaj avatar swekaj commented on May 21, 2024

The weird dates are because February 3rd only falls on a Wednesday every 5 - 7 years. If you wanted every Wednesday after the third of February, then the cron would be something like 13 14 3-29 2 3

from cron-expression.

Related Issues (20)

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.