jmrozanec / cron-utils

Cron utils for parsing, validations and human readable descriptions as well as date/time interoperability.
http://cron-utils.com
Apache License 2.0
1.15k stars 262 forks source link

Is there a chance to have CronMapper from QUARTZ to SPRING53 ? #579

Open unstoppable95 opened 1 year ago

unstoppable95 commented 1 year ago

Hi guys, I'd like to have a mapper from QUARTZ format to SPRING53 as I need to support additional L, # for days of the week and L,W day of the month. After creating my custom one and calling .map method I keep getting a problem that "value missing for a#b cron expresion" even it it's already there inside Cron when I call mapper.map() method (from is quartz definition and to is spring53 type inside CronMapper constuctor). Is there a chance to support this feature in upcoming weeks/months?

jmrozanec commented 1 year ago

@unstoppable95 could you provide some PR with a test, to reproduce the issue?

unstoppable95 commented 1 year ago

just add new static method in CronMapper class: public static CronMapper fromQuartzToSpring53() { return new CronMapper( CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ), CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING53), setQuestionMark() ); }

and then try to use in some test e.g: @Test public void testRangeOfTimeQuartzToSpring53() { final String expected = "0 15 10 ? * 5#3"; final String expression = "0 15 10 ? * 6#3 1984"; assertEquals(expected, CronMapper.fromQuartzToSpring53().map(quartzParser().parse(expression)).asString()); }

and this results in "IllegalArgumentExpression....value missing for a#b cron expression" and main problem is in inside at com.cronutils.model.field.expression.On.(On.java:43), not sure if this precondition check there is correct.

Regards & sorry for not creating PR, I did not have git installed on this PC and can't to this without local admin role...

mkouba commented 2 months ago

@unstoppable95 Do you happen to know if SPRING53 to QUARTZ mapping works correctly?

I mean, if you build a custom CronMapper in a similar way to com.cronutils.mapper.CronMapper.fromSpringToQuartz().

mkouba commented 2 months ago

It seems to work (at least for simple cases) but it would be nice to have the CronMapper#fromSpring53ToQuartz() method too.