tharwaninitin / cron4zio

Cron4ZIO is library to run ZIO effects based on cron expressions.
Apache License 2.0
5 stars 0 forks source link

withMondayDoWValue problem in cronDefinition #2

Closed floatfield closed 1 year ago

floatfield commented 1 year ago

Hi! I wonder if cronDefinition is correct in package cron4zio. It seems to me that there should be

.withDayOfWeek().withValidRange(1, 7).withMondayDoWValue(1).supportsHash().supportsL().supportsQuestionMark().and()

instead of

.withDayOfWeek().withValidRange(1, 7).withMondayDoWValue(0).supportsHash().supportsL().supportsQuestionMark().and()

If I try something like this with the given definition

import com.cronutils.descriptor.CronDescriptor
import com.cronutils.model.definition.{CronConstraintsFactory, CronDefinition, CronDefinitionBuilder}
import com.cronutils.parser.CronParser

val cronDefinition: CronDefinition = CronDefinitionBuilder.defineCron()
  .withSeconds().withValidRange(0, 59).and()
  .withMinutes().withValidRange(0, 59).and()
  .withHours().withValidRange(0, 23).and()
  .withDayOfMonth().withValidRange(1, 31).supportsL().supportsW().supportsLW().supportsQuestionMark().and()
  .withMonth().withValidRange(1, 12).and()
  .withDayOfWeek().withValidRange(1, 7).withMondayDoWValue(0).supportsHash().supportsL().supportsQuestionMark().and()
  .withYear().withValidRange(1970, 2099).withStrictRange().optional().and()
  .withCronValidation(CronConstraintsFactory.ensureEitherDayOfWeekOrDayOfMonth())
  .instance()

val cronParser = new CronParser(cronDefinition)

val cron = cronParser.parse("0 25 17 ? * WED")

val desc = CronDescriptor.instance()
val description = desc.describe(cron) // at 17:25 at Thursday day

it gives a schedule for thursday instead of wednesday. Or do I miss something?

tharwaninitin commented 1 year ago

Hey @floatfield ,

Yes you are correct. Thanks for identifying this issue, it has been fixed now in the new version 1.0.0

Cheers !!