[Schmitzm-commits] r2423 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Jul 14 20:50:48 CEST 2016


Author: mojays
Date: 2016-07-14 20:50:48 +0200 (Thu, 14 Jul 2016)
New Revision: 2423

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
LangUtil: new utility methods for date handling

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2016-07-14 17:39:29 UTC (rev 2422)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2016-07-14 18:50:48 UTC (rev 2423)
@@ -539,8 +539,32 @@
 	public static Date decHours(Date date, double hours) {
 		return incHours(date, -hours);
 	}
+	
+	/**
+	 * Calculates the difference between two dates in the specified format.
+	 * @param date1 the oldest date
+	 * @param date2 the newest date
+	 * @param timeUnit the unit in which you want the diff
+	 * @return the diff value, in the provided unit
+	 */
+	public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) {
+	  long diffInMillies = date2.getTime() - date1.getTime();
+	  return timeUnit.convert(diffInMillies,TimeUnit.MILLISECONDS);
+	}
 
 	/**
+	 * Returns the weekday for a date according to {@link GregorianCalendar}.
+	 * @return {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, ...
+	 * #see Calendar#get(int)
+	 */
+    public static int getWeekDay(Date date) {
+      Calendar cal = GregorianCalendar.getInstance();
+	  cal.setTime(date);
+	  return cal.get(Calendar.DAY_OF_WEEK);
+    }
+
+
+	/**
 	 * Tries several date formats to parse a date string.
 	 * 
 	 * @param dateStr



More information about the Schmitzm-commits mailing list