DateUtilExtensions { public static Calendar previous(Calendar self) { Calendar result = (Calendar) self.clone(); result.add(Calendar.DATE, -1); return result; }  static int getAt(Date self, int field); static Calendar toCalendar(Date self); static int getAt(Calendar self, int field); static void putAt(Calendar self, int field, int value); static void putAt(Date self, int field, int value); static void set(Calendar self, Map<Object, Integer> updates); static Calendar updated(Calendar self, Map<Object, Integer> updates); static Calendar copyWith(Calendar self, Map<Object, Integer> updates); static void set(Date self, Map<Object, Integer> updates); static Date updated(Date self, Map<Object, Integer> updates); static Date copyWith(Date self, Map<Object, Integer> updates); static Date next(Date self); static Calendar next(Calendar self); static Calendar previous(Calendar self); static java.sql.Date next(java.sql.Date self); static Date previous(Date self); static java.sql.Date previous(java.sql.Date self); static Date plus(Date self, int days); static java.sql.Date plus(java.sql.Date self, int days); static Timestamp plus(Timestamp self, int days); static Date minus(Date self, int days); static java.sql.Date minus(java.sql.Date self, int days); static Timestamp minus(Timestamp self, int days); static int minus(Calendar self, Calendar then); static int minus(Date self, Date then); static String format(Date self, String format); static String format(Date self, String format, TimeZone tz); static String getDateString(Date self); static String getTimeString(Date self); static String getDateTimeString(Date self); static Date clearTime(final Date self); static java.sql.Date clearTime(final java.sql.Date self); static Calendar clearTime(final Calendar self); static String format(Calendar self, String pattern); static void upto(Date self, Date to, Closure closure); static void upto(Calendar self, Calendar to, Closure closure); static void downto(Date self, Date to, Closure closure); static void downto(Calendar self, Calendar to, Closure closure);  }
@Test public void previous() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Calendar calendar = Calendar.getInstance(); calendar.setTime(sdf.parse("20180101")); assertEquals("20171231", sdf.format(DateUtilExtensions.previous(calendar).getTime())); }