changeset 389:ea263ee87563

Added new helper class DateUtils. artifacts/trunk@4436 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 18 May 2012 09:08:03 +0000
parents 156904aa7c85
children d5db5483b376 bf0c7b7e2b71
files ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/DateUtils.java
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue May 15 07:05:20 2012 +0000
+++ b/ChangeLog	Fri May 18 09:08:03 2012 +0000
@@ -1,3 +1,8 @@
+2012-05-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/DateUtils.java:
+	  New utility class that provides functions that helps working with dates.
+
 2012-05-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifacts-common/src/main/java/de/intevation/artifacts/common/model/KVP.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/DateUtils.java	Fri May 18 09:08:03 2012 +0000
@@ -0,0 +1,30 @@
+package de.intevation.artifacts.common.utils;
+
+import java.util.Calendar;
+import java.util.Date;
+
+
+public class DateUtils {
+
+    private DateUtils() {
+    }
+
+
+    /**
+     * This function extracts the year as int value from <i>date</i>.
+     *
+     * @param date The source date.
+     *
+     * @return the year as integer or -1 if date is empty.
+     */
+    public static int getYearFromDate(Date date) {
+        if (date == null) {
+            return -1;
+        }
+
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+
+        return cal.get(Calendar.YEAR);
+    }
+}

http://dive4elements.wald.intevation.org