Skip to content

Commit

Permalink
Update comments and variable names to mirror change from JodaTime->JD…
Browse files Browse the repository at this point in the history
…K8 time.
  • Loading branch information
jmrozanec committed Aug 7, 2016
1 parent 2895776 commit 8e1fc51
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
21 changes: 11 additions & 10 deletions src/main/java/com/cronutils/model/time/ExecutionTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.cronutils.model.time.generator.FieldValueGeneratorFactory.createDayOfWeekValueGeneratorInstance;
import static java.time.temporal.TemporalAdjusters.lastDayOfMonth;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
Expand Down Expand Up @@ -116,7 +117,7 @@ public static ExecutionTime forCron(Cron cron) {

/**
* Provide nearest date for next execution.
* @param date - jodatime DateTime instance. If null, a NullPointerException will be raised.
* @param date - ZonedDateTime instance. If null, a NullPointerException will be raised.
* @return ZonedDateTime instance, never null. Next execution time.
*/
public ZonedDateTime nextExecution(ZonedDateTime date) {
Expand All @@ -135,7 +136,7 @@ public ZonedDateTime nextExecution(ZonedDateTime date) {
/**
* If date is not match, will return next closest match.
* If date is match, will return this date.
* @param date - reference DateTime instance - never null;
* @param date - reference ZonedDateTime instance - never null;
* @return ZonedDateTime instance, never null. Value obeys logic specified above.
* @throws NoSuchValueException
*/
Expand Down Expand Up @@ -341,11 +342,11 @@ TimeNode generateDays(CronDefinition cronDefinition, ZonedDateTime date){

/**
* Provide nearest time for next execution.
* @param date - jodatime DateTime instance. If null, a NullPointerException will be raised.
* @return jodatime Duration instance, never null. Time to next execution.
* @param date - ZonedDateTime instance. If null, a NullPointerException will be raised.
* @return Duration instance, never null. Time to next execution.
*/
public java.time.Duration timeToNextExecution(ZonedDateTime date){
return java.time.Duration.between(date, nextExecution(date));
public Duration timeToNextExecution(ZonedDateTime date){
return Duration.between(date, nextExecution(date));
}

/**
Expand All @@ -368,11 +369,11 @@ public ZonedDateTime lastExecution(ZonedDateTime date){

/**
* Provide nearest time from last execution.
* @param date - jodatime DateTime instance. If null, a NullPointerException will be raised.
* @return jodatime Duration instance, never null. Time from last execution.
* @param date - ZonedDateTime instance. If null, a NullPointerException will be raised.
* @return Duration instance, never null. Time from last execution.
*/
public java.time.Duration timeFromLastExecution(ZonedDateTime date){
return java.time.Duration.between(lastExecution(date), date);
public Duration timeFromLastExecution(ZonedDateTime date){
return Duration.between(lastExecution(date), date);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private int generateValue(On on, int year, int month, int reference) throws NoSu

private int generateHashValues(On on, int year, int month){
DayOfWeek dowForFirstDoM = LocalDate.of(year, month, 1).getDayOfWeek();//1-7
int requiredDoW = ConstantsMapper.weekDayMapping(mondayDoWValue, ConstantsMapper.JAVA8, on.getTime().getValue());//to normalize to joda-time value
int requiredDoW = ConstantsMapper.weekDayMapping(mondayDoWValue, ConstantsMapper.JAVA8, on.getTime().getValue());//to normalize to jdk8-time value
int requiredNth = on.getNth().getValue();
int baseDay = 1;//day 1 from given month
int diff = dowForFirstDoM.getValue() - requiredDoW;
Expand All @@ -119,7 +119,7 @@ private int generateLValues(On on, int year, int month) throws NoSuchValueExcept
int lastDoM = LocalDate.of(year, month, 1).lengthOfMonth();
LocalDate lastDoMDateTime = LocalDate.of(year, month, lastDoM);
int dowForLastDoM = lastDoMDateTime.getDayOfWeek().getValue();//1-7
int requiredDoW = ConstantsMapper.weekDayMapping(mondayDoWValue, ConstantsMapper.JAVA8, on.getTime().getValue());//to normalize to joda-time value
int requiredDoW = ConstantsMapper.weekDayMapping(mondayDoWValue, ConstantsMapper.JAVA8, on.getTime().getValue());//to normalize to jdk8-time value
int dowDiff = dowForLastDoM - requiredDoW;

if(dowDiff==0){
Expand Down Expand Up @@ -148,7 +148,7 @@ private int generateLValues(On on, int year, int month) throws NoSuchValueExcept
private int generateNoneValues(On on, int year, int month, int reference) {
// the day of week the first of the month is on
int dowForFirstDoM = LocalDate.of(year, month, 1).getDayOfWeek().getValue();// 1-7
// the day of week we need, normalize to jodatime
// the day of week we need, normalize to jdk8time
int requiredDoW = ConstantsMapper.weekDayMapping(mondayDoWValue, ConstantsMapper.JAVA8, on.getTime().getValue());
// the first day of the month
int baseDay = 1;// day 1 from given month
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/com/cronutils/mapper/ConstantsMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
public class ConstantsMapperTest {

@Test
public void testWeekDayMappingQuartzToJodatime() throws Exception {
public void testWeekDayMappingQuartzToJDK8time() throws Exception {
WeekDay quartz = ConstantsMapper.QUARTZ_WEEK_DAY;
WeekDay jodatime = ConstantsMapper.JAVA8;
WeekDay jdktime = ConstantsMapper.JAVA8;
for(int j=2; j<8; j++){
assertEquals(j-1, ConstantsMapper.weekDayMapping(quartz, jodatime, j));
assertEquals(j-1, ConstantsMapper.weekDayMapping(quartz, jdktime, j));
}
assertEquals(7, ConstantsMapper.weekDayMapping(quartz, jodatime, 1));
assertEquals(7, ConstantsMapper.weekDayMapping(quartz, jdktime, 1));
}

@Test
public void testWeekDayMappingJodatimeToQuartz() throws Exception {
public void testWeekDayMappingJDK8ToQuartz() throws Exception {
WeekDay quartz = ConstantsMapper.QUARTZ_WEEK_DAY;
WeekDay jodatime = ConstantsMapper.JAVA8;
WeekDay jdktime = ConstantsMapper.JAVA8;
for(int j=1; j<7; j++){
assertEquals(j+1, ConstantsMapper.weekDayMapping(jodatime, quartz, j));
assertEquals(j+1, ConstantsMapper.weekDayMapping(jdktime, quartz, j));
}
assertEquals(1, ConstantsMapper.weekDayMapping(jodatime, quartz, 7));
assertEquals(1, ConstantsMapper.weekDayMapping(jdktime, quartz, 7));
}

@Test
Expand All @@ -56,22 +56,22 @@ public void testWeekDayMappingCrontabToQuartz() throws Exception {
}

@Test
public void testWeekDayMappingCrontabToJodatime() throws Exception {
public void testWeekDayMappingCrontabToJDK8() throws Exception {
WeekDay crontab = ConstantsMapper.CRONTAB_WEEK_DAY;
WeekDay jodatime = ConstantsMapper.JAVA8;
WeekDay jdktime = ConstantsMapper.JAVA8;
for(int j=1; j<7; j++){
assertEquals(j, ConstantsMapper.weekDayMapping(crontab, jodatime, j));
assertEquals(j, ConstantsMapper.weekDayMapping(crontab, jdktime, j));
}
assertEquals(7, ConstantsMapper.weekDayMapping(crontab, jodatime, 0));
assertEquals(7, ConstantsMapper.weekDayMapping(crontab, jdktime, 0));
}

@Test
public void testWeekDayMappingJodatimeToCrontab() throws Exception {
public void testWeekDayMappingJDK8ToCrontab() throws Exception {
WeekDay crontab = ConstantsMapper.CRONTAB_WEEK_DAY;
WeekDay jodatime = ConstantsMapper.JAVA8;
WeekDay jdktime = ConstantsMapper.JAVA8;
for(int j=1; j<7; j++){
assertEquals(j, ConstantsMapper.weekDayMapping(jodatime, crontab, j));
assertEquals(j, ConstantsMapper.weekDayMapping(jdktime, crontab, j));
}
assertEquals(0, ConstantsMapper.weekDayMapping(jodatime, crontab, 7));
assertEquals(0, ConstantsMapper.weekDayMapping(jdktime, crontab, 7));
}
}

0 comments on commit 8e1fc51

Please sign in to comment.