package net.tasksnow.util;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author D056943
* @since 21:11:37 - 09.01.2013
* @project cFoldersDemo
*/
public class DateUtils {
// ===========================================================
// Constants
// ===========================================================
private static final SimpleDateFormat SAME_DAY = new SimpleDateFormat("yyyyMMdd");
private static final SimpleDateFormat SAME_MONTH = new SimpleDateFormat("yyyyMM");
private static final SimpleDateFormat SAME_YEAR = new SimpleDateFormat("yyyy");
private static final SimpleDateFormat SAME_DAY_FORMATTOR = new SimpleDateFormat("H:mm");
private static final SimpleDateFormat SAME_YEAR_FORMATTOR = new SimpleDateFormat("d. MMM");
private static final SimpleDateFormat OTHER_FORMATTOR = new SimpleDateFormat("dd.MM.yyyy");
// ===========================================================
// Constructors
// ===========================================================
private DateUtils() {
}
// ===========================================================
// Fields
// ===========================================================
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public static boolean isSameDay(Date date1, Date date2) {
return SAME_DAY.format(date1).equals(SAME_DAY.format(date2));
}
public static boolean isSameYear(Date date1, Date date2) {
return SAME_YEAR.format(date1).equals(SAME_YEAR.format(date2));
}
public static boolean isSameMonth(Date date1, Date date2) {
return SAME_MONTH.format(date1).equals(SAME_MONTH.format(date2));
}
public static String getFormattedDate(Date date) {
if (date != null) {
Date currDate = new Date();
if (DateUtils.isSameDay(currDate, date)) {
return SAME_DAY_FORMATTOR.format(date);
}
else if (DateUtils.isSameYear(currDate, date)) {
return SAME_YEAR_FORMATTOR.format(date);
}
return OTHER_FORMATTOR.format(date);
}
else
return null;
}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}