@Test public void testSubtract() { CalendarDate baseDate = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, "1950-01-01"); CalendarDate result = baseDate.subtract(CalendarPeriod.of(300, Field.Millisec)); assertThat(result.toString()).isEqualTo("1949-12-31T23:59:59.700Z"); result = baseDate.subtract(CalendarPeriod.of(300, Field.Second)); assertThat(result.toString()).isEqualTo("1949-12-31T23:55:00Z"); result = baseDate.subtract(CalendarPeriod.of(30, Field.Minute)); assertThat(result.toString()).isEqualTo("1949-12-31T23:30:00Z"); result = baseDate.subtract(CalendarPeriod.of(30, Field.Hour)); assertThat(result.toString()).isEqualTo("1949-12-30T18:00:00Z"); result = baseDate.subtract(CalendarPeriod.of(30, Field.Day)); assertThat(result.toString()).isEqualTo("1949-12-02T00:00:00Z"); result = baseDate.subtract(CalendarPeriod.of(30, Field.Month)); assertThat(result.toString()).isEqualTo("1947-07-01T00:00:00Z"); result = baseDate.subtract(CalendarPeriod.of(30, Field.Year)); assertThat(result.toString()).isEqualTo("1920-01-01T00:00:00Z"); }
public CalendarDate subtract(CalendarPeriod period) { switch (period.getField()) { case Millisec: return new CalendarDate(cal, dateTime.minusMillis(period.getValue())); case Second: return new CalendarDate(cal, dateTime.minusSeconds(period.getValue())); case Minute: return new CalendarDate(cal, dateTime.minusMinutes(period.getValue())); case Hour: return new CalendarDate(cal, dateTime.minusHours(period.getValue())); case Day: return new CalendarDate(cal, dateTime.minusDays(period.getValue())); case Month: return new CalendarDate(cal, dateTime.minusMonths(period.getValue())); case Year: return new CalendarDate(cal, dateTime.minusYears(period.getValue())); } throw new UnsupportedOperationException("period units = " + period); }
CalendarDate implements Comparable<CalendarDate> { public CalendarDate subtract(CalendarPeriod period) { switch (period.getField()) { case Millisec: return new CalendarDate(cal, dateTime.minusMillis(period.getValue())); case Second: return new CalendarDate(cal, dateTime.minusSeconds(period.getValue())); case Minute: return new CalendarDate(cal, dateTime.minusMinutes(period.getValue())); case Hour: return new CalendarDate(cal, dateTime.minusHours(period.getValue())); case Day: return new CalendarDate(cal, dateTime.minusDays(period.getValue())); case Month: return new CalendarDate(cal, dateTime.minusMonths(period.getValue())); case Year: return new CalendarDate(cal, dateTime.minusYears(period.getValue())); } throw new UnsupportedOperationException("period units = " + period); } }
CalendarDate implements Comparable<CalendarDate> { public CalendarDate subtract(CalendarPeriod period) { switch (period.getField()) { case Millisec: return new CalendarDate(cal, dateTime.minusMillis(period.getValue())); case Second: return new CalendarDate(cal, dateTime.minusSeconds(period.getValue())); case Minute: return new CalendarDate(cal, dateTime.minusMinutes(period.getValue())); case Hour: return new CalendarDate(cal, dateTime.minusHours(period.getValue())); case Day: return new CalendarDate(cal, dateTime.minusDays(period.getValue())); case Month: return new CalendarDate(cal, dateTime.minusMonths(period.getValue())); case Year: return new CalendarDate(cal, dateTime.minusYears(period.getValue())); } throw new UnsupportedOperationException("period units = " + period); } CalendarDate(Calendar cal, DateTime dateTime); }
CalendarDate implements Comparable<CalendarDate> { public CalendarDate subtract(CalendarPeriod period) { switch (period.getField()) { case Millisec: return new CalendarDate(cal, dateTime.minusMillis(period.getValue())); case Second: return new CalendarDate(cal, dateTime.minusSeconds(period.getValue())); case Minute: return new CalendarDate(cal, dateTime.minusMinutes(period.getValue())); case Hour: return new CalendarDate(cal, dateTime.minusHours(period.getValue())); case Day: return new CalendarDate(cal, dateTime.minusDays(period.getValue())); case Month: return new CalendarDate(cal, dateTime.minusMonths(period.getValue())); case Year: return new CalendarDate(cal, dateTime.minusYears(period.getValue())); } throw new UnsupportedOperationException("period units = " + period); } CalendarDate(Calendar cal, DateTime dateTime); static CalendarDate present(); static CalendarDate present(Calendar cal); static CalendarDate of(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay,
      int minuteOfHour, int secondOfMinute); static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour,
      int secondOfMinute); static CalendarDate of(java.util.Date date); static CalendarDate of(long msecs); static CalendarDate of(Calendar cal, long msecs); @Nullable static CalendarDate parseUdunitsOrIso(String calendarName, String isoOrUdunits); static CalendarDate parseISOformat(String calendarName, String isoDateString); static CalendarDate parseUdunits(String calendarName, String udunits); Calendar getCalendar(); long getMillis(); @Override int compareTo(CalendarDate o); boolean isAfter(CalendarDate o); boolean isBefore(CalendarDate o); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String getTimeUnits(); int getHourOfDay(); int getFieldValue(CalendarPeriod.Field fld); int getDayOfMonth(); @Deprecated CalendarDate add(double value, CalendarPeriod.Field unit); CalendarDate add(CalendarPeriod period); CalendarDate subtract(CalendarPeriod period); CalendarDate truncate(CalendarPeriod.Field fld); java.util.Date toDate(); long getDifferenceInMsecs(CalendarDate o); long getDifference(CalendarDate o, CalendarPeriod.Field fld); GregorianCalendar toGregorianCalendar(); }
CalendarDate implements Comparable<CalendarDate> { public CalendarDate subtract(CalendarPeriod period) { switch (period.getField()) { case Millisec: return new CalendarDate(cal, dateTime.minusMillis(period.getValue())); case Second: return new CalendarDate(cal, dateTime.minusSeconds(period.getValue())); case Minute: return new CalendarDate(cal, dateTime.minusMinutes(period.getValue())); case Hour: return new CalendarDate(cal, dateTime.minusHours(period.getValue())); case Day: return new CalendarDate(cal, dateTime.minusDays(period.getValue())); case Month: return new CalendarDate(cal, dateTime.minusMonths(period.getValue())); case Year: return new CalendarDate(cal, dateTime.minusYears(period.getValue())); } throw new UnsupportedOperationException("period units = " + period); } CalendarDate(Calendar cal, DateTime dateTime); static CalendarDate present(); static CalendarDate present(Calendar cal); static CalendarDate of(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay,
      int minuteOfHour, int secondOfMinute); static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour,
      int secondOfMinute); static CalendarDate of(java.util.Date date); static CalendarDate of(long msecs); static CalendarDate of(Calendar cal, long msecs); @Nullable static CalendarDate parseUdunitsOrIso(String calendarName, String isoOrUdunits); static CalendarDate parseISOformat(String calendarName, String isoDateString); static CalendarDate parseUdunits(String calendarName, String udunits); Calendar getCalendar(); long getMillis(); @Override int compareTo(CalendarDate o); boolean isAfter(CalendarDate o); boolean isBefore(CalendarDate o); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String getTimeUnits(); int getHourOfDay(); int getFieldValue(CalendarPeriod.Field fld); int getDayOfMonth(); @Deprecated CalendarDate add(double value, CalendarPeriod.Field unit); CalendarDate add(CalendarPeriod period); CalendarDate subtract(CalendarPeriod period); CalendarDate truncate(CalendarPeriod.Field fld); java.util.Date toDate(); long getDifferenceInMsecs(CalendarDate o); long getDifference(CalendarDate o, CalendarPeriod.Field fld); GregorianCalendar toGregorianCalendar(); static final CalendarDate UNKNOWN; static final double MILLISECS_IN_SECOND; static final double MILLISECS_IN_MINUTE; static final double MILLISECS_IN_HOUR; static final double MILLISECS_IN_DAY; static final double MILLISECS_IN_YEAR; static final double MILLISECS_IN_MONTH; }