// ----------------------------------------------------------------------- public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { if (minuendInstant < subtrahendInstant) { return -getDifference(subtrahendInstant, minuendInstant); } int minuendYear = iChronology.getYear(minuendInstant); int minuendMonth = iChronology.getMonthOfYear(minuendInstant, minuendYear); int subtrahendYear = iChronology.getYear(subtrahendInstant); int subtrahendMonth = iChronology.getMonthOfYear(subtrahendInstant, subtrahendYear); long difference = (minuendYear - subtrahendYear) * ((long) iMax) + minuendMonth - subtrahendMonth; // Before adjusting for remainder, account for special case of add // where the day-of-month is forced to the nearest sane value. int minuendDom = iChronology.getDayOfMonth(minuendInstant, minuendYear, minuendMonth); if (minuendDom == iChronology.getDaysInYearMonth(minuendYear, minuendMonth)) { // Last day of the minuend month... int subtrahendDom = iChronology.getDayOfMonth(subtrahendInstant, subtrahendYear, subtrahendMonth); if (subtrahendDom > minuendDom) { // ...and day of subtrahend month is larger. // Note: This works fine, but it ideally shouldn't invoke other // fields from within a field. subtrahendInstant = iChronology.dayOfMonth().set(subtrahendInstant, minuendDom); } } // Inlined remainder method to avoid duplicate calls. long minuendRem = minuendInstant - iChronology.getYearMonthMillis(minuendYear, minuendMonth); long subtrahendRem = subtrahendInstant - iChronology.getYearMonthMillis(subtrahendYear, subtrahendMonth); if (minuendRem < subtrahendRem) { difference--; } return difference; }
// ----------------------------------------------------------------------- public long roundFloor(long instant) { int year = iChronology.getYear(instant); int month = iChronology.getMonthOfYear(instant, year); return iChronology.getYearMonthMillis(year, month); }