package info.bukova.isspst;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

public class DateTimeUtils
{
	public static Date getDate(Date value)
	{
		if (value == null)
		{
			return value;
		}
		
		// Keep date - truncate time
		return DateUtils.truncate(value, Calendar.DAY_OF_MONTH);
	}
	
	public static boolean isEqualByDate(Date d1, Date d2)
	{
		if (d1 != null && d2 != null)
		{
			d1 = DateTimeUtils.getDate(d1);
			d2 = DateTimeUtils.getDate(d2);
			boolean equals = (d1.compareTo(d2) == 0);
			return equals;
		}
		
		return false;
	}
	
	public static boolean isEqualByDateForFilter(Date value, Date search)
	{
		if (search == null)
		{
			return true;
		}
		else if (value != null)
		{
			return DateTimeUtils.isEqualByDate(value, search);
		}
		
		return false;
	}

	public static Date getCurrDateTime()
	{
		return new Date();
	}

	public static Date getCurrDate()
	{
		return DateTimeUtils.getDate(DateTimeUtils.getCurrDateTime());
	}
}
