package ch.hesso.master.caldynam.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import ch.hesso.master.caldynam.Constants;

public class DateUtils {

    public static Date endOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(Constants.TIMEZONE);
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    public static Date startOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(Constants.TIMEZONE);
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static boolean sameDay(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setTimeZone(Constants.TIMEZONE);
        cal2.setTimeZone(Constants.TIMEZONE);
        cal1.setTime(date1);
        cal2.setTime(date2);
        return  cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
                cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
    }

    public static String dateToString(Date date) {
        return dateToString(Constants.DATE_FORMAT, date);
    }

    public static String dateToString(String pattern, Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat();
        dateFormat.setTimeZone(Constants.TIMEZONE);
        dateFormat.applyPattern(pattern);
        return dateFormat.format(date);
    }

    public static String dateHourToString(Date date) {
        return dateToString(Constants.DATE_HOUR_FORMAT, date);
    }
}

@@ -121,60 +121,8 @@
 ate;
-%0Aimport java.util.Locale;%0Aimport java.util.TimeZone;
 %0A%0Aim
@@ -189,16 +189,103 @@
 tils %7B%0A%0A
+    public enum DAY_PARTING %7B%0A        MORNING,%0A        DAYTIME,%0A        EVENING%0A    %7D%0A%0A
     publ
@@ -1402,17 +1402,16 @@
  return 
- 
 cal1.get
@@ -1537,32 +1537,1143 @@
 F_YEAR);%0A    %7D%0A%0A
+    public static Date todayDayParting(DAY_PARTING dayParting) %7B%0A        int hourOfDay = 6;%0A        if (dayParting == DAY_PARTING.DAYTIME) %7B%0A            hourOfDay = 12;%0A        %7D else if (dayParting == DAY_PARTING.EVENING) %7B%0A            hourOfDay = 18;%0A        %7D%0A        Calendar calendar = Calendar.getInstance();%0A        calendar.setTimeZone(Constants.TIMEZONE);%0A        calendar.setTime(new Date());%0A        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);%0A        calendar.set(Calendar.MINUTE, 0);%0A        calendar.set(Calendar.SECOND, 0);%0A        calendar.set(Calendar.MILLISECOND, 0);%0A        return calendar.getTime();%0A    %7D%0A%0A    public static DAY_PARTING dayParting(Date date) %7B%0A        Calendar calendar = Calendar.getInstance();%0A        calendar.setTimeZone(Constants.TIMEZONE);%0A        calendar.setTime(date);%0A        if (calendar.get(Calendar.HOUR_OF_DAY) %3E 4 && calendar.get(Calendar.HOUR_OF_DAY) %3C 12) %7B%0A            return DAY_PARTING.MORNING;%0A        %7D else if (calendar.get(Calendar.HOUR_OF_DAY) %3C 18) %7B%0A            return DAY_PARTING.DAYTIME;%0A        %7D%0A        return DAY_PARTING.EVENING;%0A    %7D%0A%0A
     public stati

Add day parting methods