DataUtil { public static int getIntervalDays(int year, int month, int day) { if (year >= 1970 && month > 0 && month <= 12 && day > 0 && day <= 31) { int[] minMonths = {4, 6, 9, 11}; for (int element : minMonths) { if (month == element && day == 31) { return -1; } } boolean isLeap = year % 4 == 0 && year % 100 != 0 || year % 400 == 0; if (month == 2) { if (day > 29) { return -1; } if (isLeap && day == 29) { return -1; } } int yearDays = 0; int monthDays = 0; if (year != 1970) { yearDays = getYearIntervalDays(year - 1); } if (month != 1) { monthDays = getMonthIntervalDays(month - 1, isLeap); } return yearDays + monthDays + day - 1; } return -1; }  static int getMatrixHeavy(int[][] matrix, int m, int n); static int maxSequenceSum(int[] array); static int fibonacciRecursive(int n); static int fibonacci(int n); static int findMaxUnContinuousSum(int[] array); static void findContinuousSequenceMethod1(int n); static void findContinuousSequenceMethod2(int n); static void findContinuousSequenceMethod3(int n); static void findContinuousSequenceMethod4(int n); static void pickNum(int[] originArray, int n, int m, int[] selectArray, int startIndex, boolean inorder); static int binarySearch(int[] array, int key); static int findFirstEqual(int[] array, int key); static int findFirstEqualLarger(int[] array, int key); static int findFirstLarger(int[] array, int key); static int findLastEqual(int[] array, int key); static int findLastEqualSmaller(int[] array, int key); static List<Integer> shufflePump(List<Integer> origin); static List<Integer> shuffleSwap(List<Integer> origin); static int[] shuffleSwap(int[] origin); static String getAccurateDivide(int a, int b, int n); static Set<Integer> getPrimeNumInefficient(int range); static Set<Integer> getPrimeNumEfficient(int range); static int getIntervalDays(int year, int month, int day); static int pageHelper(int n, int m); static boolean isOdd(int num);  }
@Test public void testTwoDateInterval() { int year1 = 2018, month1 = 9, day1 = 3; int year2 = 2016, month2 = 12, day2 = 12; int date1Days = DataUtil.getIntervalDays(year1, month1, day1); int date2Days = DataUtil.getIntervalDays(year2, month2, day2); System.out.println("date1Days: " + date1Days); System.out.println("date2Days: " + date2Days); int intervalDays = date1Days - date2Days; System.out.println("intervalDays: " + (intervalDays >= 0 ? intervalDays : -intervalDays)); }