Advertisement
Supahstar42

Untitled

Sep 17th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. //Array containing days per month
  2. private static final int[] DAYS_IN_MONTH = {0, 31, 28, 31, 30, 31, 30, 31,
  3. 31, 30, 31, 30, 31};
  4.  
  5. //Used for different date formats
  6. private static final String[] MONTHS = {"", "January", "February",
  7. "March", "April", "May", "June", "July", "August", "September",
  8. "October", "November", "December"};
  9.  
  10. //returns the days I’m the given month
  11. public int daysInMonth(int tempMonth) {
  12. int daysInMonth;
  13. if (isLeapYear(year))
  14. DAYS_IN_MONTH[2] = 29;
  15. daysInMonth = DAYS_IN_MONTH[tempMonth];
  16. return daysInMonth;
  17. }
  18.  
  19. //Check if a year is a leap year
  20. public static boolean isLeapYear(int year) {
  21. return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
  22. }
  23.  
  24. //Method to increment thorugh days
  25. public void inc() {
  26. int tempDay = day;
  27. int tempMonth = month;
  28. int tempYear = year;
  29. int count = 0;
  30.  
  31. daysInMonth(tempMonth);
  32.  
  33. if (this.isValidDate()) {
  34. tempDay++;
  35. if (tempDay > DAYS_IN_MONTH[tempMonth]) {
  36. tempDay = 1;
  37. tempMonth++;
  38. }
  39. if (tempMonth == 13) {
  40. tempDay = 1;
  41. tempMonth = 1;
  42. tempYear++;
  43. }
  44. }
  45.  
  46.  
  47. this.day = tempDay + count;
  48. this.month = tempMonth;
  49. this.year = tempYear;
  50. }
  51.  
  52.  
  53. //Method for counting days between 2 dates
  54. public int daysToGo(String fromDate) {
  55. int count = 0;
  56. GeoCountDownTimer tempStart = new GeoCountDownTimer(fromDate);
  57. GeoCountDownTimer tempEnd = this;
  58.  
  59. while (!tempStart.toString().equals(tempEnd.toString())) {
  60. tempStart.inc();
  61. count++;
  62. }
  63.  
  64. return count;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement