Cronos icon indicating copy to clipboard operation
Cronos copied to clipboard

ToString creates unparsable string in case CronFormat.IncludeSeconds is set

Open codingWombat opened this issue 1 year ago • 0 comments

I am using a 3rd party lib that uses Cronos for handling cron expressions. This lib always uses CronFormat.IncludeSeconds internally so if I want to run sth. every minute I need need to use 0 * * * * *. This is no problem in the first place, the first call to CronExpression.Parse(expression, CronFormat.IncludeSeconds) omits the 0 and returns if ToString is called * * * * * if this is used later to call CronExpression.Parse with CronFromat.IncludeSeconds an exception is thrown.

This behaviour was introduced with the fix for https://github.com/HangfireIO/Cronos/issues/15 I agree to the suggestion that was made, in some way it should be memorized that the initial expression was created explicitly with CronFormat.IncludeSeconds.

The code to reproduce this behavior is more then simple:

using Cronos;

const string expression = "0 1 * * * *";

var cronExpression = CronExpression.Parse(expression, CronFormat.IncludeSeconds);
Console.WriteLine(cronExpression.ToString());

CronExpression.Parse(cronExpression.ToString(), CronFormat.IncludeSeconds);

codingWombat avatar Jun 23 '24 10:06 codingWombat