public DailyTimeIntervalScheduleBuilder endingDailyAfterCount ( final int count ) { ValueEnforcer . isGT0 ( count , "Count" ) ; if ( m_aStartTimeOfDay == null ) throw new IllegalArgumentException ( "You must set the startDailyAt() before calling this endingDailyAfterCount()!" ) ; final Date today = new Date ( ) ; final Date startTimeOfDayDate = m_aStartTimeOfDay . getTimeOfDayForDate ( today ) ; final Date maxEndTimeOfDayDate = TimeOfDay . hourMinuteAndSecondOfDay ( 23 , 59 , 59 ) . getTimeOfDayForDate ( today ) ; final long remainingMillisInDay = maxEndTimeOfDayDate . getTime ( ) - startTimeOfDayDate . getTime ( ) ; long intervalInMillis ; if ( m_eIntervalUnit == EIntervalUnit . SECOND ) intervalInMillis = m_nInterval * CGlobal . MILLISECONDS_PER_SECOND ; else if ( m_eIntervalUnit == EIntervalUnit . MINUTE ) intervalInMillis = m_nInterval * CGlobal . MILLISECONDS_PER_MINUTE ; else if ( m_eIntervalUnit == EIntervalUnit . HOUR ) intervalInMillis = m_nInterval * DateBuilder . MILLISECONDS_IN_DAY ; else throw new IllegalArgumentException ( "The IntervalUnit: " + m_eIntervalUnit + " is invalid for this trigger." ) ; if ( remainingMillisInDay - intervalInMillis <= 0 ) throw new IllegalArgumentException ( "The startTimeOfDay is too late with given Interval and IntervalUnit values." ) ; final long maxNumOfCount = ( remainingMillisInDay / intervalInMillis ) ; if ( count > maxNumOfCount ) throw new IllegalArgumentException ( "The given count " + count + " is too large! The max you can set is " + maxNumOfCount ) ; final long incrementInMillis = ( count - 1 ) * intervalInMillis ; final Date endTimeOfDayDate = new Date ( startTimeOfDayDate . getTime ( ) + incrementInMillis ) ; if ( endTimeOfDayDate . getTime ( ) > maxEndTimeOfDayDate . getTime ( ) ) throw new IllegalArgumentException ( "The given count " + count + " is too large! The max you can set is " + maxNumOfCount ) ; final Calendar cal = PDTFactory . createCalendar ( ) ; cal . setTime ( endTimeOfDayDate ) ; final int hour = cal . get ( Calendar . HOUR_OF_DAY ) ; final int minute = cal . get ( Calendar . MINUTE ) ; final int second = cal . get ( Calendar . SECOND ) ; m_aEndTimeOfDay = TimeOfDay . hourMinuteAndSecondOfDay ( hour , minute , second ) ; return this ; }
Calculate and set the endTimeOfDay using count interval and starTimeOfDay . This means that these must be set before this method is call .