Repository: jmrozanec/cron-utils (java)

Issue:
Exception when set DoW as Sunday using QUARTZ definition
In order to verify the problem, replace the day of the week to Sunday on the following test 
https://github.com/jmrozanec/cron-utils/blob/0759550fa7a18067a0decd5953acd4165f0bf0ab/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java#L177

Pull request description:
Fix exception thrown when DoW set as Sunday using QUARTZ definition #508
It fixes the DoW to be map Sunday correctly to 1 instead of 8.
Have also included the unit test for the issue.

Fixes #508

Patch:
diff --git a/src/main/java/com/cronutils/mapper/WeekDay.java b/src/main/java/com/cronutils/mapper/WeekDay.java
index 0783ace..ea10c44 100644
--- a/src/main/java/com/cronutils/mapper/WeekDay.java
+++ b/src/main/java/com/cronutils/mapper/WeekDay.java
@@ -61,7 +61,7 @@ public class WeekDay implements Serializable {
             return mapTo(dayOfWeek, new WeekDay(targetWeekDayDefinition.getMondayDoWValue() + 1, false)) - 1;
         } else {
             //my range is 0-6. I normalize ranges, get the "one" mapping and turn result into original scale
-            return mapTo(dayOfWeek, new WeekDay(targetWeekDayDefinition.getMondayDoWValue() - 1, true)) + 1;
+            return (mapTo(dayOfWeek, new WeekDay(targetWeekDayDefinition.getMondayDoWValue() - 1, true))) % 7 + 1;
         }
     }
 


Test patch:
diff --git a/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java b/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java
index 1e30557..1b87a1d 100755
--- a/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java
+++ b/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java
@@ -186,6 +186,28 @@ public class CronDefinitionBuilderTest {
         assertEquals("0 0 12 ? * 6 *", result);
     }
 
+    /**
+     * Test for issue https://github.com/jmrozanec/cron-utils/issues/508
+     * DoW as Sunday using QUARTZ definition was going out of range [1,7]
+     */
+    @Test
+    public void testDoWProperWeekdayOffsetForSunday(){
+        CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
+        CronBuilder builder = CronBuilder.cron(cronDefinition)
+                .withYear(always())
+                .withMonth(always())
+                .withDoW(on(Weekdays.SUNDAY.getWeekday(cronDefinition)))
+                .withDoM(questionMark())
+                .withHour(on(12))
+                .withMinute(on(0))
+                .withSecond(on(0));
+
+        Cron cron = builder.instance();
+        String result = cron.asString();
+
+        assertEquals("0 0 12 ? * 1 *", result);
+    }
+
     @Test
     public void testSpringSchedule(){
         CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING);