package org.synyx.urlaubsverwaltung.core.util;

import org.joda.time.DateMidnight;
import org.joda.time.DateTimeConstants;


/**
 * @author  Aljona Murygina
 */
public final class DateUtil {

    private static final int DAY_OF_NEW_YEARS_EVE = 31;
    private static final int DAY_OF_CHRISTMAS_EVE = 24;

    private DateUtil() {

        // Hide constructor for util classes
    }

    /**
     * Check if the given date is a work day.
     *
     * @param  date  to check
     *
     * @return  {@code true} if the given date is a work day, else {@code false}
     */
    public static boolean isWorkDay(DateMidnight date) {

        return !(date.getDayOfWeek() == DateTimeConstants.SATURDAY || date.getDayOfWeek() == DateTimeConstants.SUNDAY);
    }


    /**
     * Check if given date is before April.
     *
     * @param  date  to check
     *
     * @return  {@code true} if the given date is before April, {@code false} if it is after April
     */
    public static boolean isBeforeApril(DateMidnight date) {

        return (date.getMonthOfYear() < DateTimeConstants.APRIL);
    }


    /**
     * Check if given date is on Christmas Eve.
     *
     * @param  date  to check
     *
     * @return  {@code true} if the given date is on Christmas Eve, else {@code false}
     */
    public static boolean isChristmasEve(DateMidnight date) {

        return (date.getDayOfMonth() == DAY_OF_CHRISTMAS_EVE && date.getMonthOfYear() == DateTimeConstants.DECEMBER);
    }


    /**
     * Check if given date is on New Year's Eve.
     *
     * @param  date  to check
     *
     * @return  {@code true} if the given date is on New Year's Eve, else {@code false}
     */
    public static boolean isNewYearsEve(DateMidnight date) {

        return (date.getDayOfMonth() == DAY_OF_NEW_YEARS_EVE && date.getMonthOfYear() == DateTimeConstants.DECEMBER);
    }


    /**
     * Get the first day of the given year.
     *
     * @param  year  to get the first day of
     *
     * @return  the first day of the given year
     */
    public static DateMidnight getFirstDayOfYear(int year) {

        return getFirstDayOfMonth(year, DateTimeConstants.JANUARY);
    }


    /**
     * Get the last day of the given year.
     *
     * @param  year  to get the last day of
     *
     * @return  the last day of the given year
     */
    public static DateMidnight getLastDayOfYear(int year) {

        return getLastDayOfMonth(year, DateTimeConstants.DECEMBER);
    }


    /**
     * Get the first day of the given month in the given year.
     *
     * @param  year  of the month to get the first day of
     * @param  month  to get the first day of
     *
     * @return  the first day of the given month in the given year
     */
    public static DateMidnight getFirstDayOfMonth(int year, int month) {

        DateMidnight monthOfYear = DateMidnight.now().withYear(year).withMonthOfYear(month);

        return monthOfYear.dayOfMonth().withMinimumValue();
    }


    /**
     * Get the last day of the given month in the given year.
     *
     * @param  year  of the month to get the last day of
     * @param  month  to get the first day of
     *
     * @return  the last day of the given month in the given year
     */
    public static DateMidnight getLastDayOfMonth(int year, int month) {

        DateMidnight monthOfYear = DateMidnight.now().withYear(year).withMonthOfYear(month);

        return monthOfYear.dayOfMonth().withMaximumValue();
    }
}

@@ -1021,33 +1021,32 @@
 %0A        return 
-(
 date.getMonthOfY
@@ -1076,17 +1076,16 @@
 ts.APRIL
-)
 ;%0A    %7D%0A
@@ -1351,33 +1351,32 @@
 %0A        return 
-(
 date.getDayOfMon
@@ -1450,33 +1450,32 @@
 nstants.DECEMBER
-)
 ;%0A    %7D%0A%0A%0A    /*
@@ -1742,17 +1742,16 @@
  return 
-(
 date.get
@@ -1833,33 +1833,32 @@
 nstants.DECEMBER
-)
 ;%0A    %7D%0A%0A%0A    /*

remove unnecessary parentheses