View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.enrollment.class1.hold.util;
17  
18  import java.util.Date;
19  
20  /**
21   * @author ocleirig
22   * 
23   * A helper for effective date comparisons.
24   *
25   */
26  public final class EffectiveDateUtils {
27  
28  	/**
29  	 * 
30  	 */
31  	private EffectiveDateUtils() {
32  	}
33  
34  
35  	/**
36  	 * The targetDate is effective if:
37  	 * 1. startDate <= targetDate
38  	 * 2. targetDate <= endDate or endDate is null.
39  	 * 
40  	 * @param startDate the begining of the date range.
41  	 * @param endDate the end of the date range or null if no end has been set.
42  	 * @param targetDate the time of interest that we want to determine to be inside or outside of the date range.
43  	 * 
44  	 * @return true if the targetDate is effective, false otherwise.
45  	 */
46  	public static boolean isTargetDateEffective(Date startDate, Date endDate, Date targetDate) {
47  		
48  		// TODO: this seems like a specialized version of DateRange 
49  		// that might be something to investigate.
50  		if (startDate.equals(targetDate) || startDate.before(targetDate)) {
51  			
52  			if (endDate == null || endDate.equals(targetDate) || endDate.after(targetDate))
53  				return true;
54  			else
55  				return false;
56  		}
57  		else
58  			return false;
59  	}
60  }