Created
February 6, 2018 02:51
-
-
Save amaembo/84e76957c855b65d54c6792c3c86ffcd to your computer and use it in GitHub Desktop.
BlackboxB
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
public class February31 { | |
public 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment