Giter Club home page Giter Club logo

cronos's People

Contributors

aidmsu avatar faithfuldev avatar ggjason avatar jtone123 avatar odinserj avatar pandetthe avatar watfordgnf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cronos's Issues

L-3 raises invalid interval after running

I have this cron expression "0 0 L-3 * *".
It worked fine until after that point in time, then is crashed with the exception below.

System.ArgumentException: Invalid value '2375713936.2261' for parameter 'interval'.
at System.Timers.Timer..ctor(Double interval)
at Domain.Services.CronJobService.ScheduleJob(CancellationToken cancellationToken) in E:\SourceCode\LDS\src\Domain\Domain.Services\CronJobService.cs:line 37
at Domain.Services.CronJobService.StartAsync(CancellationToken cancellationToken) in E:\SourceCode\LDS\src\Domain\Domain.Services\CronJobService.cs:line 24
at LDS.ReportService.CassetteRefilList.StartAsync(CancellationToken cancellationToken) in E:\SourceCode\LDS\src\LDS\LDS.ReportService\Reports\CassetteRefilList.cs:line 46
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

If I change the expression to "0 0 L * *" there is no issue.

I tried changing the expression
"0 0 24 * *" - Works
"0 0 25 * *" - Exception all expressions with the date above 24 give the exception.

any ideas?

Year in cron expression

This dll is really giving correct result. Just curious to know if there is any version available who can handle year as well. Currently, 6 octet cron expression is allowed.

Last day minus 3 days

I have a job running on the last thursday of every month, "0 0 8 * * THUL". (which will occur in either the 3rd or 4th week of the month)

Is it possible to create an expression that provides the occurences 3 days before the occurences returned from the above expression? ("every monday of the week of the last thursday in month").

GetOccurrences method to calculate the next occurrences based on the from date specified.

I need the GetOccurrences method to calculate the next occurrences based on the from date,

Eg: My cron expression is ' Occurs on day 1 of every 3 months' and from date is 'Feb 20 2018' , then the occurences should be

  • 01-May-2018
  • 01-Aug-2018
  • 01-Nov 2018 etc

But the current behaviour is always taking the default date as

  • 01-April-2018
  • 01-Jul-2018
  • 01-Oct-2018

Need help to figure out the issue

Support for different calendars

It seems Cronos only supports Gregorian calendar, Do you have any workaround to use different calendars with Cronos?

Is supporting for other calendars in you future plans?

What's the logic behind the unreachable dates?

Hi! I am trying to familiarize myself with the scenarios in which the GetNextOccurrence can return a DateTime? with null value, and I have a hard time understanding the logic behind the behavior. It seems that calculating the next occurrence for dates after the year 2100 is unsuccessful about half of the time. Here is a minimal example:

string expression = "0 0 15 6 *"; // June, 15
var cronExpression = CronExpression.Parse(expression);
Console.WriteLine($"Expression: {cronExpression}");
for (int i = 1; i <= 24; i++)
{
    var fromUtc = new DateTime(2150, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMonths(i);
    var nextUtc = cronExpression.GetNextOccurrence(fromUtc);
    Console.WriteLine($"Date: {fromUtc}, NextOccurrence: {(nextUtc.HasValue ? nextUtc.Value.ToString() : "-")}");
}

Output:

Expression: 0 0 0 15 6 *
Date: 02/01/2150 00:00:00, NextOccurrence: 06/15/2150 00:00:00
Date: 03/01/2150 00:00:00, NextOccurrence: 06/15/2150 00:00:00
Date: 04/01/2150 00:00:00, NextOccurrence: 06/15/2150 00:00:00
Date: 05/01/2150 00:00:00, NextOccurrence: 06/15/2150 00:00:00
Date: 06/01/2150 00:00:00, NextOccurrence: 06/15/2150 00:00:00
Date: 07/01/2150 00:00:00, NextOccurrence: -
Date: 08/01/2150 00:00:00, NextOccurrence: -
Date: 09/01/2150 00:00:00, NextOccurrence: -
Date: 10/01/2150 00:00:00, NextOccurrence: -
Date: 11/01/2150 00:00:00, NextOccurrence: -
Date: 12/01/2150 00:00:00, NextOccurrence: -
Date: 01/01/2151 00:00:00, NextOccurrence: 06/15/2151 00:00:00
Date: 02/01/2151 00:00:00, NextOccurrence: 06/15/2151 00:00:00
Date: 03/01/2151 00:00:00, NextOccurrence: 06/15/2151 00:00:00
Date: 04/01/2151 00:00:00, NextOccurrence: 06/15/2151 00:00:00
Date: 05/01/2151 00:00:00, NextOccurrence: 06/15/2151 00:00:00
Date: 06/01/2151 00:00:00, NextOccurrence: 06/15/2151 00:00:00
Date: 07/01/2151 00:00:00, NextOccurrence: -
Date: 08/01/2151 00:00:00, NextOccurrence: -
Date: 09/01/2151 00:00:00, NextOccurrence: -
Date: 10/01/2151 00:00:00, NextOccurrence: -
Date: 11/01/2151 00:00:00, NextOccurrence: -
Date: 12/01/2151 00:00:00, NextOccurrence: -
Date: 01/01/2152 00:00:00, NextOccurrence: 06/15/2152 00:00:00

Live demo.

Could you explain why the calculation fails when the month+day of the starting date is
larger than the month+day in the Cron expression?

Thanks!

Missing a date over fall DST

Hi,

I'm having an issues with Cronos v0.6.2 when trying to generates a list of occurrences across last daylight saving change.

Here is a simple code to reproduce. It try to generate each 1/4h from 00:00 utc to 03:00 utc the night of dst for the Western Europe timezone.

        var tzi = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
        var begin = new DateTime(2017, 10, 29, 00, 00, 00, DateTimeKind.Utc);
        var end = new DateTime(2017, 10, 29, 03, 00, 00, DateTimeKind.Utc);
        var expr = CronExpression.Parse("0/15 * * * *");

        var dates = expr.GetOccurrences(begin, end, tzi);

        foreach (var d in dates)
        {
            Console.WriteLine(d);
        }

        Console.ReadKey();

Result is :

29-10-17 01:00:00
29-10-17 01:15:00
29-10-17 01:30:00
29-10-17 01:45:00
29-10-17 02:15:00
29-10-17 02:30:00
29-10-17 02:45:00

Unless I missed something, expected result would be :

29-10-17 01:00:00
29-10-17 01:15:00
29-10-17 01:30:00
29-10-17 01:45:00
29-10-17 02:00:00
29-10-17 02:15:00
29-10-17 02:30:00
29-10-17 02:45:00

Year Support

I'm currently evaluating hangfire and need to be able to support a date range when the job should run. I saw in commit 8dc1b11 that year support was removed since it caused ambiguity with the seconds field so it seems like I would have to place those date checks in the job itself which I'd rather not do. Would it be possible to add year support only if there are 7 fields specified in the cron expression meaning if you want to specify a year, you also have to specify seconds?

Assembly signing

Hi there,

I wanted to know whether there was the possibility of having a signed version of the assembly distributed to NuGet? I was thinking of using this framework as a dependency of one of my own (WIP) frameworks, but unfortunately mine is signed and won't build as this package doesn't have a strong name.

Thanks

invalid value for system.timers.timer

hi,
I am getting error when I am setting CronExpression for month.

Error Message: Invalid value '2376995117.7807' for parameter 'interval'.'

// Cron setting
services.AddCronJob(c =>
{
c.TimeZoneInfo = TimeZoneInfo.Local;
c.CronExpression = @"0 0 1 * *";
});

when google for this issue I found that System.Timers.Timer only store maximum 25 day time value

What are they different

            var cronExp = CronExpression.Parse("0 0 * * * ?", CronFormat.IncludeSeconds);
            var nrt = cronExp.GetNextOccurrence(DateTime.UtcNow, false);
            Console.WriteLine($"{nrt} - {nrt?.Kind}");
            var nrt2 = cronExp.GetNextOccurrence(DateTime.UtcNow, true);
            Console.WriteLine($"{nrt2} - {nrt2?.Kind}");

            Console.WriteLine();

            DateTimeOffset? nrt3 = cronExp.GetNextOccurrence(DateTimeOffset.UtcNow, TimeZoneInfo.Local, false);
            Console.WriteLine($"{nrt3} - {nrt3?.DateTime.Kind}");
            DateTimeOffset? nrt4 = cronExp.GetNextOccurrence(DateTimeOffset.UtcNow, TimeZoneInfo.Local, true);
            Console.WriteLine($"{nrt4} - {nrt4?.DateTime.Kind}");

return are same.

2019-03-21 6:00:00 AM - Utc
2019-03-21 6:00:00 AM - Utc

2019-03-21 2:00:00 PM +08:00 - Unspecified
2019-03-21 2:00:00 PM +08:00 - Unspecified

Feature Request: "TryParse" or/and "IsValid" methods

Hi everyone,

could be possible to have one of these two methods to avoid everytime to catch the CronFormatException?
If you allow users to contribute on the project, I'll be enthusiast to create a PR on that.

Thanks for attention.

Next Occurence returning the wrong month

If you look at the configuration Ii have below using this library, I selected the following:
"First Monday of each Month" (starting in April)

However the first occurence returns back the current month which is March. the same issue happens for each month of the year selected where I am expecting it to return next month, not the current month. This seems to be happening somehwere within the libray when using the get next occurence method.

I'm using library ver 0.71

image

.Net Core 2+ support

Could you add .Net Standard 2 support to the NuGet package so we don't have an explicit dependency on NetStandard.Library, please?

Cron job run every three (or n) days?

I want to run a job every three or five (or n) days from now, and I wrote the expression '0 8 */5 * *'.

If now is '2018/05/17',

and I get the occurrences:

0 8 */5 * *
2018/5/21 8:00:00
2018/5/26 8:00:00
2018/5/31 8:00:00
2018/6/1 8:00:00
2018/6/6 8:00:00
2018/6/11 8:00:00
2018/6/16 8:00:00
2018/6/21 8:00:00
2018/6/26 8:00:00
2018/7/1 8:00:00
2018/7/6 8:00:00
2018/7/11 8:00:00
2018/7/16 8:00:00
2018/7/21 8:00:00
2018/7/26 8:00:00
2018/7/31 8:00:00
2018/8/1 8:00:00
2018/8/6 8:00:00

but, which I expected are:

0 8 */5 * *
2018/5/22 8:00:00     -- wrong
2018/5/27 8:00:00     -- wrong
2018/6/1 8:00:00
2018/6/6 8:00:00
2018/6/11 8:00:00
2018/6/16 8:00:00
2018/6/21 8:00:00
2018/6/26 8:00:00
2018/7/1 8:00:00
2018/7/6 8:00:00
2018/7/11 8:00:00
2018/7/16 8:00:00
2018/7/21 8:00:00
2018/7/26 8:00:00
2018/7/31 8:00:00
2018/8/5 8:00:00      -- wrong
2018/8/10 8:00:00     -- wrong

Do the cron expression that I wrote is wrong? Or the Cronos don't support this situation?

Any one help me?

Thanks,
Leaf

Support for value list separator in parts that start with */

Hello.

Find the case CronExpression.Parse("* * * * */2,3") that fails with exception:

Minutes: Unexpected character ','.

And it not work at any position (minute, hour, etc.). Is it a bug? Or it's partial support for not standard special character / ?

Support NodaTime

Further to #36 (comment), is there any plan to support NodaTime fully, either via an additional shim package or just by including NodaTime in the core functionality?

For example, there's no easy way to fully implement

ZonedDateTime? GetNextOccurence(ZonedDateTime fromZoned, bool inclusive)

externally as you can't guarantee there's an equivalent System.TimeZoneInfo for any given NodaTime.DateTimeZone which is more feature rich. Whereas you can largely guarantee the opposite is true.

Shouldn't 0 0 15,L * ? work?

0 0 15,L * ? should produce the 15th of the month or the Last day of the month. Instead it complains about the L not being a number.

Am I missing something or should this be supported?

Thanks
Jim

GetNextOccurrence based on today's date

Hi. I have a problem getting next occurrence time or i just miss something in Cronos documentation.

Problem:
User can set scheduler, which is done with the cron expression. User can set date and time and interval. For example 1.2.2012 15:00:00 every two days. But the date doesn't change often, only when user set new time or interval, what means if today is 20.2.2012 12:00:00, then GetNextOccurrence() get the 3.2.2012 15:00:00 as result, but i want to get 21.2.2012, which is the next relevant run time.
Workaround:

var occs = expression.GetOccurrences(schedule.Time, DateTime.UtcNow, TimeZoneInfo.Local).ToList();
job.NextRunTime = expression.GetNextOccurrence(occs.Last(), TimeZoneInfo.Local);

I just get all occurrences till today and then i use last one to get the ACTUAL next one.

Does it make sense to have a function like: GetNextOccurrenceBasedOnDateTimeNow(...)?

Thank You

Weekly with Steps not working

A Step is working with every date part place holder. But the Day of the week place holder not considering */5 (with n number of Steps ahead when an weekly interval is given)

every second '* * * * * *' throws an exception

Parsing of "* * * * * " (six stars here, markdown hides a star) throws an exception
CronExpression.Parse("
* * * * * *")

Cronos.CronFormatException: Unexpected character '*'.
at Cronos.CronExpression.ThrowFormatException(String format, Object[] args) in C:\projects\cronos\src\Cronos\CronExpression.cs:line 1014
at Cronos.CronExpression.Parse(String expression) in C:\projects\cronos\src\Cronos\CronExpression.cs:line 91

Wrong value reported on `GetNextOccurrence` function

Wrong value reported for next occurrence, ignores remaining time for this current date.

Consider the following:

    var strExpression = "25 23 */3 * *";
    var cronExpression = Cronos.CronExpression.Parse(strExpression, Cronos.CronFormat.Standard);
    var nextOccurrence = cronExpression.GetNextOccurrence(DateTime.UtcNow);

    var now = DateTime.UtcNow; // 2020-09-30 16:32:00
    var nextFireShouldBe = new DateTime(now.Year, now.Month, now.Day, 23, 25, 0);

    //nextOccurrence    => 2020-10-01 23:25:00
    //nextFireShouldBe  => 2020-09-30 23:25:00

Next occurrence should be on same date, but is pushed for tomorrow instead

Issue with multiple days for MonthlyDoW

Hi,

First of all, your library is awesome! I do however have issues with multiple days of week in the MontlyDoW schedule.
34 15 * 1,12 2#1,2#L is the cron string I'm using. Parsing fails with:
Days of week: Unexpected character ','.
Now if I leave a single value for days of week such as 34 15 * 1,12 2#1 it works as expected. Is there any way to make it work with multiple values?

Thanks.
Bogdan

Is hangfire support second ?

RecurringJob.AddOrUpdate( () => Console.WriteLine("Recurring!"), "* * * * * *", queue: "test");
image

but in HangfireIO/Cronos's README.md

                                   Allowed values    Allowed special characters   Comment

┌───────────── second (optional) 0-59 * , - /
│ ┌───────────── minute 0-59 * , - /
│ │ ┌───────────── hour 0-23 * , - /
│ │ │ ┌───────────── day of month 1-31 * , - / L W ?
│ │ │ │ ┌───────────── month 1-12 or JAN-DEC * , - /
│ │ │ │ │ ┌───────────── day of week 0-6 or SUN-SAT * , - / # L ? Both 0 and 7 means SUN
│ │ │ │ │ │


Autodetect parse with seconds

Hi,
I'm using Cronos inside application which read user configurations which could have standard minutes form or extended with seconds. Problem is, i do not know if user enter one or another and Parse() method without second parameter throws Cronos.CronFormatException: Unexpected character '*'..
How should i detect if it is standard form or extended when Cronos can't detect it by itself?

GetOccurrences -- Issue

When cron expression is set to run job at every 30+ mints, for example "*/40 * * * *", it shows next occurrences as

8/6/2021 3:40:00 AM
8/6/2021 4:00:00 AM
8/6/2021 4:40:00 AM
8/6/2021 5:00:00 AM
8/6/2021 5:40:00 AM
8/6/2021 6:00:00 AM
8/6/2021 6:40:00 AM
8/6/2021 7:00:00 AM
8/6/2021 7:40:00 AM
8/6/2021 8:00:00 AM

It's not continuing the 40 mints gap between the executions.

feature request: GetPriorOccurrence

Would you please consider returning the return the DateTime when a task would have been due going back in time.

I am currently using the real hack

_expression.GetOccurrences(scheduled.AddDays(-60), scheduled, _timeZoneInfo, false, false).Last();

0 0 1 8 0 can not be parsed

Frankly, the "0 0 1 8 0" was a well-formed value, It indicates "At 00:00 on day-of-month 1 and on Sunday in August".
but it can not be parsed on version 0.7.0
Any latest implementation of this project?

nuget version

I see csproj has version 1.0, but published Cronos nuget has version 0.7 and there is also Longbow.Cronos nuget with version 1.0.

What nuget should be used - is current?

Marek

DST execution skipped

Hi
first of all I want to thank you for the great library.
One thing doesn't seem to be working correctly. I am in Europe and DST was applied on 28/3/21 from 2 to 3 am CET which is one hour ahead of UTC. When I ask for the next occurrence 1 minute before DST it returns the right UTC timestamp. Doing the same at DST change it returns the next occurrence 1 week later.
Dim expression As Cronos.CronExpression = Cronos.CronExpression.Parse("0 2 * * 0")
Dim nextOccurrence As DateTimeOffset = expression.GetNextOccurrence(start, timeZone, True)
Return nextOccurrence.DateTime

log time - GetNextOccurrence - start
2021-03-28 01:59:01,812 - 2021-03-28T01:00:00.0000000 - 2021-03-28T00:59:00.0000000Z
2021-03-28 03:00:01,163 - 2021-04-04T00:00:00.0000000 - 2021-03-28T01:00:00.0000000Z

Am I doing something wrong here?
Thanks.
Martin

Feature request: CronExpression description

This is a feature request for a new method on CronExpression that provides a human-readable description of the cron expression.

For example 30 12 LW * * would show 12:30 on the last weekday of the month

Possible edge condition problem

I could very well be wrong about this. That happens a lot, but given the following setup, I'd expect all four tests to pass here.

private readonly TimeZoneInfo EST = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
private readonly DateTimeOffset Jan1st2000 = new DateTimeOffset(2000, 01, 01, 00, 00, 00, new TimeSpan(-4, 0, 0));

// Asking just BEFORE midnight should yield the 1st (Works)
CronExpression.Parse("0 0 * * 6").GetNextOccurrence(Jan1st2000.AddMilliseconds(-1), EST).ShouldBe(new DateTime(2000, 01, 01));

// Asking exactly AT midnight should also yield the 1st (Works)
CronExpression.Parse("0 0 * * 6").GetNextOccurrence(Jan1st2000, EST).ShouldBe(new DateTime(2000, 01, 01));

// Asking just AFTER midnight should yield the 8th (Only the first one works)
CronExpression.Parse("0 0 * * 6").GetNextOccurrence(Jan1st2000.AddHours(1), EST).ShouldBe(new DateTime(2000, 01, 08));
CronExpression.Parse("0 0 * * 6").GetNextOccurrence(Jan1st2000.AddSeconds(61), EST).ShouldBe(new DateTime(2000, 01, 08));

Once I'm outside the first hour, it correctly jumps to the next Saturday, but shouldn't moving outside the first minute also yield the next Saturday? The individual fields are supposed to be AND-ed together, right? If I've moved my "now" outside the first minute of the first hour, then it shouldn't count again until the next Saturday midnight... right?

Apologies if I'm overlooking the obvious here. I've been staring at this too long.

GetNextOccurence_s_?

Hi guys, I'm using NCronTab right now because it has a GetNextOccurence*s* method that returns an IEnumerable<T> of DateTime's when you give it a date range. Is there a good way to get the same result from your library? Thanks!

.Net 6 and .Net8 Support?

Hi, I am wondering if there are plans to support the latest LTS versions of .Net. I know some projects wish to stick to netstandard for compatibility purposes, but it seems worth asking about at least. I can make an attempt at a PR with this update as well, just let me know if you have any recommended steps to test/verify before I begin.

Feature Request: Support an array of cron expressions

My users have just asked if they can change the current schedule of every 30 mins between 10am and 5pm to also include 5pm.

I can't see a way of doing this without also including 5:30pm therefore i would like to have an array of two expressions built into one so that GetNextOccurrence will get the next one from either expression.

            var expressions = new string[]
            {
                "0,30 10-16 * * 1-5", 
                "0 17 * * 1-5"
            };
            var cronosExpression = CronExpression.Parse(expressions);

I've reworked my app to handle this in my IHostedService manually but there might be others who will need something like this in the future too, it's easy enough to do in a Linux crontab because you just run the same script twice.

0,30 10-16 * * 1-5  /opt/example.sh
0 17 * * 1-5        /opt/example.sh

GetOcccurances from and to inclusive does not work

Hi!

Could be me misunderstanding something, but im getting different results with the following call:

DateTime startTime = {'5/20/2022 12:00:00 AM' }; //obv as a DateTime object
DateTime endTime= {'5/31/2022 12:00:00 AM' }; // obv as a DateTime object
string expression = '0 0 9 * * 1,2,3,4,5';
var cron = cronExpression.Parse(expression , CronFormat.IncludeSeconds);
cronExpression.GetOccurances(startTime, endTime, true, true).
this returns, as expected the following:
5/20/2022 9:00
5/23/2022 9:00
5/24/2022 9:00
5/25/2022 9:00
5/26/2022 9:00
5/27/2022 9:00
5/30/2022 9:00

however, changing the expression to the following
string expression = '0 0 0 * * 1,2,3,4,5';

removes 5/20 from the list, despite it being the exact same call?

I could theoretically move the input times back by a second, but that's a hacky fix id rather not do.

Again, not sure if this is expected behavior, or if I'm just being dumb. Let me know if you can help. Thanks!

Cronos.CronFormatException: "Unexpected character '*'."

expression "0 0 4 ? * * *" generated on site

CronExpression.Parse("0 0 4 ? * * *", CronFormat.Standard) \\ Cronos.CronFormatException: "Unexpected character '*'."
CronExpression.Parse("0 0 4 ? * * *", CronFormat.IncludeSeconds) \\ Cronos.CronFormatException: "Unexpected character '*'."

why can't it be parsed?

Cronos 0.7.1

Problem with parsing days of month with comma

Hello!

Today I found some error when try to parse 0 0 15,28 * * (in 15 and 28 day of each month at midnight) expression. In this case I used format without seconds, just five positions. But when I used CronExpression.Parse method, then I saw get exception with message Cronos.CronFormatException: Hours: Value must be a number between 0 and 23 (all inclusive).. I checked tests with commas and don't found this.

It is problem with autodetect format or not?

P.S. I fixed this problem when used format with seconds, just adding zero in seconds position 0 0 0 15,28 * *.

0 0/3 * 1/1 * ? cannot be parsed

I tried using the 0 0/3 * 1/1 * ? Cron expression but it tells me the ? character is unexpected.

I don't understand why it has issues parsing this since I've been using it with Quartz.Net and it works fine.

What is the problem?

Thanks

CronExpression.ToString is not parseable anymore

It looks like a ToString method is not symetric - what I mean by that is that one would expect from CronExpression to pass through Parse→ToString→Parse cycle to produce an equivalent expression as in the first parse.

The motivation for that is that stringified cron expression may be i.e. serialized and restored later.

Simple example to reproduce an issue:

var expr = CronExpression.Parse("*/5 * * * *");
var serialized = expr.ToString(); // 0 0,5,10,15,20,25,30,35,40,45,50,55 * * * *
var expr2 = CronExpression.Parse(serialized);
/*
Cronos.CronFormatException
Days of month: Value must be a number between 1 and 31 (all inclusive).
   at Cronos.CronExpression.ThrowFormatException(CronField field, String format, Object[] args)
   at Cronos.CronExpression.ParseDayOfMonth(Char*& pointer, CronExpressionFlag& flags, Byte& lastDayOffset)
   at Cronos.CronExpression.Parse(String expression, CronFormat format)
*/

I think, the easiest way to solve this, would be to attach original cron expression string as an extra field of the CronExpression class:

  • Expression strings are small and usually written by humans, so keeping them arround won't occupy much memory.
  • This would make ToString method much faster (useful i.e. for logging).
  • The whole class would still be under 64 bytes, therefore fit into CPU cache line.

Second weekday of the month

Hello everyone,

I am trying to run a script on both the first and second weekday of the month. While the first weekday is fine ( [0 0 1W * *] as in nearest weekday to 1st of month), I can't find a solution for the second weekday. 2W only works if the 1st falls within the Mon-Thu range. Otherwise 1W and 2W will be mapped to the same day. Does somebody have a solution for that? This would be an awesome feature to have.

Thanks and best regards

Support for multiple day of week specifiers

Hi,
I would like to ask if there is a plan to support multple day of week specifiers.
For example this cron expression is currenlty not supported:
0 0 11 ? 8/2 SAT,SUN#3
It means: "At 11:00 AM, on the third Saturday and Sunday of the month, every 2 months, August through December" and allow to apply the "#" specifier to two days of week Saturday and Sunday.
Thanks, regards,
D

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.