@Override public boolean isLeapYear(long prolepticYear) { return HijrahDate.isLeapYear(prolepticYear); }
/** * Returns adjusted month days as Integer array form the year specified. * * @param year a year * @return an Integer array */ private static Integer[] getAdjustedMonthDays(int year) { Integer[] newMonths; try { newMonths = ADJUSTED_MONTH_DAYS.get(new Integer(year)); } catch (ArrayIndexOutOfBoundsException e) { newMonths = null; } if (newMonths == null) { if (isLeapYear(year)) { newMonths = DEFAULT_LEAP_MONTH_DAYS; } else { newMonths = DEFAULT_MONTH_DAYS; } } return newMonths; }
/** * Returns adjusted month length as Integer array form the year specified. * * @param year a year * @return an Integer array */ private static Integer[] getAdjustedMonthLength(int year) { Integer[] newMonths; try { newMonths = ADJUSTED_MONTH_LENGTHS.get(new Integer(year)); } catch (ArrayIndexOutOfBoundsException e) { newMonths = null; } if (newMonths == null) { if (isLeapYear(year)) { newMonths = DEFAULT_LEAP_MONTH_LENGTHS; } else { newMonths = DEFAULT_MONTH_LENGTHS; } } return newMonths; }
/** * Returns year length. * * @param year year * @return year length */ static int getYearLength(int year) { int cycleNumber = (year - 1) / 30; Integer[] cycleYears; try { cycleYears = ADJUSTED_CYCLE_YEARS.get(cycleNumber); } catch (ArrayIndexOutOfBoundsException e) { cycleYears = null; } if (cycleYears != null) { int yearInCycle = (year - 1) % 30; if (yearInCycle == 29) { return ADJUSTED_CYCLES[cycleNumber + 1].intValue() - ADJUSTED_CYCLES[cycleNumber].intValue() - cycleYears[yearInCycle].intValue(); } return cycleYears[yearInCycle + 1].intValue() - cycleYears[yearInCycle].intValue(); } else { return isLeapYear(year) ? 355 : 354; } }
/** * Returns day-of-month. * * @param dayOfYear day of year * @param month month * @param year year * @return day-of-month */ private static int getDayOfMonth(int dayOfYear, int month, int year) { Integer[] newMonths = getAdjustedMonthDays(year); if (dayOfYear >= 0) { if (month > 0) { return dayOfYear - newMonths[month].intValue(); } else { return dayOfYear; } } else { dayOfYear = (isLeapYear(year) ? (dayOfYear + 355) : (dayOfYear + 354)); if (month > 0) { return dayOfYear - newMonths[month].intValue(); } else { return dayOfYear; } } }
/** * Returns month-of-year. 0-based. * * @param dayOfYear day-of-year * @param year a year * @return month-of-year */ private static int getMonthOfYear(int dayOfYear, int year) { Integer[] newMonths = getAdjustedMonthDays(year); if (dayOfYear >= 0) { for (int i = 0; i < newMonths.length; i++) { if (dayOfYear < newMonths[i].intValue()) { return i - 1; } } return 11; } else { dayOfYear = (isLeapYear(year) ? (dayOfYear + 355) : (dayOfYear + 354)); for (int i = 0; i < newMonths.length; i++) { if (dayOfYear < newMonths[i].intValue()) { return i - 1; } } return 11; } }
boolean isStartYLeap = isLeapYear(startYear); boolean isEndYLeap = isLeapYear(endYear);
/** * Constructs an instance with the specified date. * * @param gregorianDay the number of days from 0001/01/01 (Gregorian), caller calculated */ private HijrahDate(long gregorianDay) { int[] dateInfo = getHijrahDateInfo(gregorianDay); checkValidYearOfEra(dateInfo[1]); checkValidMonth(dateInfo[2]); checkValidDayOfMonth(dateInfo[3]); checkValidDayOfYear(dateInfo[4]); this.era = HijrahEra.of(dateInfo[0]); this.yearOfEra = dateInfo[1]; this.monthOfYear = dateInfo[2]; this.dayOfMonth = dateInfo[3]; this.dayOfYear = dateInfo[4]; this.dayOfWeek = DayOfWeek.of(dateInfo[5]); this.gregorianEpochDay = gregorianDay; this.isLeapYear = isLeapYear(this.yearOfEra); }
year = cycleNumber * 30 - yearInCycle; // negative number. year = 1 - year; dayOfYear = (isLeapYear(year) ? (dayOfYear + 355) : (dayOfYear + 354)); month = getMonthOfYear(dayOfYear, year);