private void pinDayOfMonth(LocalGregorianCalendar.Date date){
  int year=date.getYear();
  int dom=date.getDayOfMonth();
  if (year != getMinimum(YEAR)) {
    date.setDayOfMonth(1);
    jcal.normalize(date);
    int monthLength=jcal.getMonthLength(date);
    if (dom > monthLength) {
      date.setDayOfMonth(monthLength);
    }
 else {
      date.setDayOfMonth(dom);
    }
    jcal.normalize(date);
  }
 else {
    LocalGregorianCalendar.Date d=jcal.getCalendarDate(Long.MIN_VALUE,getZone());
    LocalGregorianCalendar.Date realDate=jcal.getCalendarDate(time,getZone());
    long tod=realDate.getTimeOfDay();
    realDate.addYear(+400);
    realDate.setMonth(date.getMonth());
    realDate.setDayOfMonth(1);
    jcal.normalize(realDate);
    int monthLength=jcal.getMonthLength(realDate);
    if (dom > monthLength) {
      realDate.setDayOfMonth(monthLength);
    }
 else {
      if (dom < d.getDayOfMonth()) {
        realDate.setDayOfMonth(d.getDayOfMonth());
      }
 else {
        realDate.setDayOfMonth(dom);
      }
    }
    if (realDate.getDayOfMonth() == d.getDayOfMonth() && tod < d.getTimeOfDay()) {
      realDate.setDayOfMonth(Math.min(dom + 1,monthLength));
    }
    date.setDate(year,realDate.getMonth(),realDate.getDayOfMonth());
  }
}

private void pinDayOfMonth ( LocalGregorianCalendar . Date date ) { int year = date . getYear ( ) ; int dom = date . getDayOfMonth ( ) ; if ( year != getMinimum ( YEAR ) ) { date . setDayOfMonth ( 1 ) ; jcal . normalize ( date ) ; int monthLength = jcal . getMonthLength ( date ) ; if ( dom > monthLength ) { date . setDayOfMonth ( monthLength ) ; } else { date . setDayOfMonth ( dom ) ; } jcal . normalize ( date ) ; } else { LocalGregorianCalendar . Date d = jcal . getCalendarDate ( Long . MIN_VALUE , getZone ( ) ) ; LocalGregorianCalendar . Date realDate = jcal . getCalendarDate ( time , getZone ( ) ) ; long tod = realDate . getTimeOfDay ( ) ; realDate . addYear ( + 400 ) ; realDate . setMonth ( date . getMonth ( ) ) ; realDate . setDayOfMonth ( 1 ) ; jcal . normalize ( realDate ) ; int monthLength = jcal . getMonthLength ( realDate ) ; if ( dom > monthLength ) { realDate . setDayOfMonth ( monthLength ) ; } else { if ( dom < d . getDayOfMonth ( ) ) { realDate . setDayOfMonth ( d . getDayOfMonth ( ) ) ; } else { realDate . setDayOfMonth ( dom ) ; } } if ( realDate . getDayOfMonth ( ) == d . getDayOfMonth ( ) && tod < d . getTimeOfDay ( ) ) { realDate . setDayOfMonth ( Math . min ( dom + 1 , monthLength ) ) ; } date . setDate ( year , realDate . getMonth ( ) , realDate . getDayOfMonth ( ) ) ; } }
after adjustments such as add ( month ) , add ( year ) , we don ' t want the month to jump around . e . g . , we don ' t want jan 31 + 1 month to go to mar 3 , we want it to go to feb 28 . adjustments which might run into this problem call this method to retain the proper month .
