summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshawn.f.cook2011-12-21 16:01:56 (EST)
committer Roberto E. Escobar2011-12-21 16:01:56 (EST)
commit867a5e306a35b787b35ec44324b8280212edeabc (patch)
treeefec20bfd7b26e7c7b374ad0921b32614e0a5eb8
parent7f096d30b6f0ed36471488cc7b999f0b0557399f (diff)
downloadorg.eclipse.osee-867a5e306a35b787b35ec44324b8280212edeabc.zip
org.eclipse.osee-867a5e306a35b787b35ec44324b8280212edeabc.tar.gz
org.eclipse.osee-867a5e306a35b787b35ec44324b8280212edeabc.tar.bz2
refinement[bgz_367370]: Add methods to DateUtil class
Signed-off-by: jmisinco <misinco@gmail.com>
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/DateUtil.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/DateUtil.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/DateUtil.java
index 3c69727..a2c307f 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/DateUtil.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/DateUtil.java
@@ -165,4 +165,79 @@ public class DateUtil {
return difference;
}
+ /**
+ * @param startDate The first date of the interpolation. MUST be before endDate.
+ * @param endDate The last date of the interpolation. MUST be after startDate
+ * @param interDate The date between startDate and endDate.
+ * @return The interpolation ratio of interDate between startDate and endDate. Where if interDate <= startDate then
+ * return 0.0 and if interDate >= endDate return 1.0.
+ */
+ public static double getInterpolationRatioBetweenDates(Date startDate, Date endDate, Date interDate) {
+ double interRatio = 0.0;
+
+ if (interDate.before(startDate) || interDate.compareTo(startDate) == 0) {
+ return 0.0;
+ }
+ if (interDate.after(endDate) || interDate.compareTo(endDate) == 0) {
+ return 1.0;
+ }
+ if (endDate.before(startDate)) {
+ return 0.0;
+ }
+
+ long startMillis = startDate.getTime();
+ long endMillis = endDate.getTime();
+ long interMillis = interDate.getTime();
+
+ long rangeMillis = endMillis - startMillis;
+ if (rangeMillis == 0.0) {
+ return 0.0;
+ }
+ long normalizedInterMillis = interMillis - startMillis;
+ interRatio = (double) normalizedInterMillis / (double) rangeMillis;
+
+ return interRatio;
+ }
+
+ /**
+ * @param date The date to add weeks to.
+ * @param manyWeeks How many weeks to add to the date.
+ * @return Return = [date] + [manyWeeks]
+ */
+ public static Date addWeeks(Date date, int manyWeeks) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+ cal.add(Calendar.WEEK_OF_YEAR, manyWeeks);
+ return cal.getTime();
+ }
+
+ /**
+ * @param a One date. Sequential order with other date parameter does not matter.
+ * @param b Another date. Sequential order with other date parameter does not matter.
+ * @return Returns the number of weeks difference between Date a and Date b.
+ */
+ public static int getManyWeeksDifference(Date a, Date b) {
+ int weeks = 0;
+ Calendar aCal = Calendar.getInstance();
+ Calendar bCal = Calendar.getInstance();
+ aCal.setTime(a);
+ bCal.setTime(b);
+
+ Calendar startCal, endCal;
+ if (aCal.before(bCal)) {
+ startCal = aCal;
+ endCal = bCal;
+ } else {
+ startCal = bCal;
+ endCal = aCal;
+ }
+
+ while (startCal.before(endCal)) {
+ startCal.add(Calendar.WEEK_OF_YEAR, 1);
+ weeks++;
+ }
+
+ return weeks;
+ }
+
}