public static void round(Calendar c,String unit){
  Integer uu=CALENDAR_UNITS.get(unit);
  if (null == uu) {
    throw new IllegalArgumentException("Rounding Unit not recognized: " + unit);
  }
  int u=uu.intValue();
switch (u) {
case Calendar.YEAR:
    c.clear(Calendar.MONTH);
case Calendar.MONTH:
  c.clear(Calendar.DAY_OF_MONTH);
c.clear(Calendar.DAY_OF_WEEK);
c.clear(Calendar.DAY_OF_WEEK_IN_MONTH);
c.clear(Calendar.DAY_OF_YEAR);
c.clear(Calendar.WEEK_OF_MONTH);
c.clear(Calendar.WEEK_OF_YEAR);
case Calendar.DATE:
c.clear(Calendar.HOUR_OF_DAY);
c.clear(Calendar.HOUR);
c.clear(Calendar.AM_PM);
case Calendar.HOUR_OF_DAY:
c.clear(Calendar.MINUTE);
case Calendar.MINUTE:
c.clear(Calendar.SECOND);
case Calendar.SECOND:
c.clear(Calendar.MILLISECOND);
break;
default :
throw new IllegalStateException("No logic for rounding value (" + u + ") "+ unit);
}
}

public static void round ( Calendar c , String unit ) { Integer uu = CALENDAR_UNITS . get ( unit ) ; if ( null == uu ) { throw new IllegalArgumentException ( "Rounding Unit not recognized: " + unit ) ; } int u = uu . intValue ( ) ; switch ( u ) { case Calendar . YEAR : c . clear ( Calendar . MONTH ) ; case Calendar . MONTH : c . clear ( Calendar . DAY_OF_MONTH ) ; c . clear ( Calendar . DAY_OF_WEEK ) ; c . clear ( Calendar . DAY_OF_WEEK_IN_MONTH ) ; c . clear ( Calendar . DAY_OF_YEAR ) ; c . clear ( Calendar . WEEK_OF_MONTH ) ; c . clear ( Calendar . WEEK_OF_YEAR ) ; case Calendar . DATE : c . clear ( Calendar . HOUR_OF_DAY ) ; c . clear ( Calendar . HOUR ) ; c . clear ( Calendar . AM_PM ) ; case Calendar . HOUR_OF_DAY : c . clear ( Calendar . MINUTE ) ; case Calendar . MINUTE : c . clear ( Calendar . SECOND ) ; case Calendar . SECOND : c . clear ( Calendar . MILLISECOND ) ; break ; default : throw new IllegalStateException ( "No logic for rounding value (" + u + ") " + unit ) ; } }
modifies the specified calendar by " rounding " down to the specified unit
