cron-utils icon indicating copy to clipboard operation
cron-utils copied to clipboard

Incorrect descriptor result

Open kostya05983 opened this issue 5 years ago • 3 comments

Hello, @jmrozanec. I use next cron expression 0 0 0 ? * 6 * and use class CronDescriptor.instanse(Msg.getCurrent()).describe() I want to get at 00:00 at and Saturday day. I get at 00:00 at and Friday days I debug code and find that in DescriptionStrategyFactory, diff is always =-1, but if it is 0 result will be correct.

final Function<Integer, String> nominal = integer -> {
            int diff = definition instanceof DayOfWeekFieldDefinition ? DayOfWeek.MONDAY.getValue() - ((DayOfWeekFieldDefinition) definition).getMondayDoWValue().getMondayDoWValue() : 0;
            return DayOfWeek.of(integer + diff < 1 ? 7 : integer + diff).getDisplayName(TextStyle.FULL, bundle.getLocale());
        };

kostya05983 avatar May 13 '19 07:05 kostya05983

@kostya05983 thank you for reporting this. We would appreciate if you can send a PR with the corresponding test. We will try to fix it as soon as possible and release a new version with it. Help is always welcome! 😄

jmrozanec avatar May 13 '19 09:05 jmrozanec

@jmrozanec I understand that it is happened because the week starts on sunday, how do you think, is it possible to provide functionality to start week on monday?

kostya05983 avatar May 13 '19 16:05 kostya05983

@kostya05983 please notice that we support Cron specifications to have a flexible start of week: you just need to specify which index corresponds to Monday at CronDefinitionBuilder: withMondayDoWValue(yourValueHere) Please let us know if further explanations are needed. Best!

jmrozanec avatar Jul 28 '19 10:07 jmrozanec