private long convertToMilis(long julianDate) { return PersianCalendarConstants.MILLIS_JULIAN_EPOCH + julianDate * PersianCalendarConstants.MILLIS_OF_A_DAY + PersianCalendarUtils.ceil( getTimeInMillis() - PersianCalendarConstants.MILLIS_JULIAN_EPOCH, PersianCalendarConstants.MILLIS_OF_A_DAY); }
/** * set the persian date it converts PersianDate to the Julian and assigned equivalent milliseconds * to the instance * * @param persianYear * @param persianMonth * @param persianDay */ public void setPersianDate(int persianYear, int persianMonth, int persianDay) { this.persianYear = persianYear; this.persianMonth = persianMonth; this.persianDay = persianDay; setTimeInMillis( convertToMilis( PersianCalendarUtils.persianToJulian( this.persianYear > 0 ? this.persianYear : this.persianYear + 1, this.persianMonth - 1, this.persianDay))); }
/** * Calculate persian date from current Date and populates the corresponding fields(persianYear, * persianMonth, persianDay) */ protected void calculatePersianDate() { long julianDate = ((long) Math.floor((getTimeInMillis() - PersianCalendarConstants.MILLIS_JULIAN_EPOCH)) / PersianCalendarConstants.MILLIS_OF_A_DAY); long PersianRowDate = PersianCalendarUtils.julianToPersian(julianDate); long year = PersianRowDate >> 16; int month = (int) (PersianRowDate & 0xff00) >> 8; int day = (int) (PersianRowDate & 0xff); this.persianYear = (int) (year > 0 ? year : year - 1); this.persianMonth = month; this.persianDay = day; }
/** * Determines if the given year is a leap year in persian calendar. Returns true if the given year * is a leap year. * * @return boolean */ public boolean isPersianLeapYear() { // calculatePersianDate(); return PersianCalendarUtils.isPersianLeapYear(this.persianYear); }