001 package org.hackystat.sensorbase.resource.projects; 002 003 import javax.xml.datatype.XMLGregorianCalendar; 004 005 import org.hackystat.sensorbase.resource.projects.jaxb.Project; 006 import org.hackystat.utilities.tstamp.Tstamp; 007 008 /** 009 * Methods that really should be part of the Project JAXB class, but I don't know 010 * how to extend that class with additional methods. 011 * 012 * @author Philip Johnson 013 */ 014 public class ProjectUtils { 015 016 /** 017 * Returns true if the passed date falls within the project start date. Due to time zones 018 * and other issues, we are going to be lenient with the definition. Basically, we will 019 * accept the day before the project start date, and any day afterwards. 020 * @param project The project. 021 * @param date The date of interest. 022 * @return True if date is after the day before the project start date. 023 */ 024 public static boolean isValidStartTime(Project project, XMLGregorianCalendar date) { 025 XMLGregorianCalendar lenientStart = Tstamp.incrementDays(project.getStartTime(), -2); 026 return Tstamp.lessThan(lenientStart, date); 027 } 028 029 /** 030 * Returns true if the passed date falls within the project end date. Due to time zones 031 * and other issues, we will accept the day after the official project end date as well. 032 * @param project The project. 033 * @param date The date of interest. 034 * @return True if date is less than to equal to the project start date. 035 */ 036 public static boolean isValidEndTime(Project project, XMLGregorianCalendar date) { 037 XMLGregorianCalendar lenientEnd = Tstamp.incrementDays(project.getEndTime(), 2); 038 return Tstamp.lessThan(date, lenientEnd); 039 } 040 041 /** 042 * Returns true if the start and end date constitute a valid project interval. This means 043 * that isValidStartDate() and isValidEndDate() return true, and that start is less than end. 044 * @param project The project. 045 * @param start The proposed start date. 046 * @param end The proposed end date. 047 * @return True if start and end are acceptable according to the project definition. 048 */ 049 public static boolean isValidInterval(Project project, XMLGregorianCalendar start, 050 XMLGregorianCalendar end) { 051 return (isValidStartTime(project, start) && isValidEndTime(project, end) && 052 Tstamp.lessThan(start, end)); 053 } 054 }