Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: Incorrect next execution date calculation for "0 15 10 ? * 6#3" #628

Open
liuyuquan150 opened this issue Jul 4, 2024 · 1 comment

Comments

@liuyuquan150
Copy link

Bug: Incorrect next execution date calculation for "0 15 10 ? * 6#3"

Description

I encountered a bug in cron-utils version 9.2.0 when calculating the next execution date for the cron expression "0 15 10 ? * 6#3" using CronType.SPRING53. The expected result should be July 19th, 2024, but the method returns July 20th, 2024.

Steps to Reproduce

  1. Use the following code to parse the cron expression and calculate the next execution time:

    import com.cronutils.model.Cron;
    import com.cronutils.model.definition.CronDefinitionBuilder;
    import com.cronutils.model.time.ExecutionTime;
    import com.cronutils.parser.CronParser;
    import com.cronutils.descriptor.CronDescriptor;
    import com.cronutils.model.CronType;
    
    import java.time.ZonedDateTime;
    import java.time.LocalDateTime;
    import java.util.Locale;
    import java.util.Optional;
    
    public class Main {
        public static void main(String[] args){
            CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING53));
            Cron quartzCron = parser.parse("0 15 10 ? * 6#3");
            ZonedDateTime now = ZonedDateTime.now();
            ExecutionTime executionTime = ExecutionTime.forCron(quartzCron);
            Optional<ZonedDateTime> zonedDateTimeOptional = executionTime.nextExecution(now);
            if (zonedDateTimeOptional.isPresent()) {
                ZonedDateTime zonedDateTime = zonedDateTimeOptional.get();
                LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
                System.err.println(localDateTime);
            }
        }
    }
  2. Run the code. The expected result should be the third Friday of the current month (July 2024), which is July 19th, 2024, at 10:15 AM local time.

Actual Result

The method returns July 20th, 2024, instead of July 19th, 2024.

Environment Information

  • cron-utils version: 9.2.0
  • Java version: 17
  • Operating system: Windows 10

Expected Result

The next execution date for the cron expression "0 15 10 ? * 6#3" should be July 19th, 2024, at 10:15 AM local time.

Additional Information

Below is the output of the code:

2024-07-20T10:15
@austek
Copy link

austek commented Jul 8, 2024

looks to be be duplicate of #605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants