Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Array containing days per month
- private static final int[] DAYS_IN_MONTH = {0, 31, 28, 31, 30, 31, 30, 31,
- 31, 30, 31, 30, 31};
- //Used for different date formats
- private static final String[] MONTHS = {"", "January", "February",
- "March", "April", "May", "June", "July", "August", "September",
- "October", "November", "December"};
- //returns the days I’m the given month
- public int daysInMonth(int tempMonth) {
- int daysInMonth;
- if (isLeapYear(year))
- DAYS_IN_MONTH[2] = 29;
- daysInMonth = DAYS_IN_MONTH[tempMonth];
- return daysInMonth;
- }
- //Check if a year is a leap year
- public static boolean isLeapYear(int year) {
- return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
- }
- //Method to increment thorugh days
- public void inc() {
- int tempDay = day;
- int tempMonth = month;
- int tempYear = year;
- int count = 0;
- daysInMonth(tempMonth);
- if (this.isValidDate()) {
- tempDay++;
- if (tempDay > DAYS_IN_MONTH[tempMonth]) {
- tempDay = 1;
- tempMonth++;
- }
- if (tempMonth == 13) {
- tempDay = 1;
- tempMonth = 1;
- tempYear++;
- }
- }
- this.day = tempDay + count;
- this.month = tempMonth;
- this.year = tempYear;
- }
- //Method for counting days between 2 dates
- public int daysToGo(String fromDate) {
- int count = 0;
- GeoCountDownTimer tempStart = new GeoCountDownTimer(fromDate);
- GeoCountDownTimer tempEnd = this;
- while (!tempStart.toString().equals(tempEnd.toString())) {
- tempStart.inc();
- count++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement