private int generateNoneValues ( final On on , final int year , final int month , final int reference ) { // the day of week the first of the month is on final int dowForFirstDoM = LocalDate . of ( year , month , 1 ) . getDayOfWeek ( ) . getValue ( ) ; // 1-7 // the day of week we need, normalize to jdk8time final int requiredDoW = ConstantsMapper . weekDayMapping ( mondayDoWValue , ConstantsMapper . JAVA8 , on . getTime ( ) . getValue ( ) ) ; // the first day of the month int baseDay = 1 ; // day 1 from given month // the difference between the days of week final int diff = dowForFirstDoM - requiredDoW ; // //base day remains the same if diff is zero if ( diff < 0 ) { baseDay = baseDay + Math . abs ( diff ) ; } if ( diff > 0 ) { baseDay = baseDay + 7 - diff ; } // if baseDay is greater than the reference, we are returning the initial matching day value //Fix issue #92 if ( reference < 1 ) { return baseDay ; } while ( baseDay <= reference ) { baseDay += 7 ; } return baseDay ; }
Generate valid days of the month for the days of week expression . This method requires that you pass it a - 1 for the reference value when starting to generate a sequence of day values . That allows it to handle the special case of which day of the month is the initial matching value .