# HG changeset patch # User Ingo Weinzierl # Date 1337332083 0 # Node ID ea263ee87563aada372460eee0a7fc7a96be9c0c # Parent 156904aa7c8552bcee9db684523b20ae9f4a797f Added new helper class DateUtils. artifacts/trunk@4436 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 156904aa7c85 -r ea263ee87563 ChangeLog --- 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 + + * 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 * artifacts-common/src/main/java/de/intevation/artifacts/common/model/KVP.java: diff -r 156904aa7c85 -r ea263ee87563 artifacts-common/src/main/java/de/intevation/artifacts/common/utils/DateUtils.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 date. + * + * @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); + } +}