I am doing a compound if statement that calculates whether a certain date is a daylight savings date, but I have become stuck when trying to find a way to calculate if the date is before the first Sunday of November or if it is after. Could someone help me? Here is my code right now:
public class Lab5 {
/**
* Return true if the given date/time is daylight savings.
* Daylight savings time begins 2am the second Sunday of March and ends 2am the first Sunday of November.
*
* @param month - represents the month with 1 = January, 12 = December
* @param date - represents the day of the month, between 1 and 31
* @param day - represents the day of the week with 1 = Sunday, 7 = Saturday
* @param hour - represents the hour of the day with 0 = midnight, 12 = noon
*
* Precondition: the month is between 1 and 12, the date is between 1 and 31, the day is between 1 and 7
* and the hour is between 0 and 23.
*/
public static boolean isDayLightSavings (int month, int date, int day, int hour) {
if (month == 1 || month == 2 || month == 12)
return false;
else if (month == 11) {
if (day == 1 && hour < 2 && date < 8)
return true;
else
return false;
}
else
return true;
}
}
Edit: I believe that my question wasn't clear enough. I know how to find the first Sunday of November
else if (month == 11) {
if (day == 1 && hour < 2 && date < 8)
what I seem to be unable to do is find whether my date is before or after this first Sunday of November. And I need to do it using an if statement, not preloaded libraries, methods or classes.