Created
February 6, 2018 02:50
-
-
Save amaembo/f623da825c1662e0ea4a7a3e8e51b312 to your computer and use it in GitHub Desktop.
BlackboxA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class February31 { | |
private static final int[] kDaysInMonth = { | |
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 | |
}; | |
boolean ValidateDateTime(DateTime time) { | |
if (time.year < 1 || time.year > 9999 || | |
time.month < 1 || time.month > 12 || | |
time.day < 1 || time.day > 31 || | |
time.hour < 0 || time.hour > 23 || | |
time.minute < 0 || time.minute > 59 || | |
time.second < 0 || time.second > 59) { | |
return false; | |
} | |
if (time.month == 2 && IsLeapYear(time.year)) { | |
return time.month <= kDaysInMonth[time.month] + 1; | |
} else { | |
return time.month <= kDaysInMonth[time.month]; | |
} | |
} | |
static boolean IsLeapYear(int year) { | |
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); | |
} | |
static class DateTime { | |
int year, month, day, hour, minute, second; | |
} | |
public static void setMonthLength(int month, int length) { | |
kDaysInMonth[month] = length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment