@Test public void testDec() { ZonedDateTime startTime = ZonedDateTime.of(2019,12,20,11, 20,30, 0, zone); Assert.assertEquals(TimeIterator.dec(startTime, TimeIterator.Granularity.MINUTE, 21).toString(), "2019-12-20T10:59:30-08:00[America/Los_Angeles]"); Assert.assertEquals(TimeIterator.dec(startTime, TimeIterator.Granularity.HOUR, 12).toString(), "2019-12-19T23:20:30-08:00[America/Los_Angeles]"); Assert.assertEquals(TimeIterator.dec(startTime, TimeIterator.Granularity.DAY, 20).toString(), "2019-11-30T11:20:30-08:00[America/Los_Angeles]"); Assert.assertEquals(TimeIterator.dec(startTime, TimeIterator.Granularity.MONTH, 12).toString(), "2018-12-20T11:20:30-08:00[America/Los_Angeles]"); }
public static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units) { switch (granularity) { case MINUTE: return time.minusMinutes(units); case HOUR: return time.minusHours(units); case DAY: return time.minusDays(units); case MONTH: return time.minusMonths(units); } throw new RuntimeException("Unsupported granularity: " + granularity); }
TimeIterator implements Iterator { public static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units) { switch (granularity) { case MINUTE: return time.minusMinutes(units); case HOUR: return time.minusHours(units); case DAY: return time.minusDays(units); case MONTH: return time.minusMonths(units); } throw new RuntimeException("Unsupported granularity: " + granularity); } }
TimeIterator implements Iterator { public static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units) { switch (granularity) { case MINUTE: return time.minusMinutes(units); case HOUR: return time.minusHours(units); case DAY: return time.minusDays(units); case MONTH: return time.minusMonths(units); } throw new RuntimeException("Unsupported granularity: " + granularity); } TimeIterator(ZonedDateTime startTime, ZonedDateTime endTime, Granularity granularity); }
TimeIterator implements Iterator { public static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units) { switch (granularity) { case MINUTE: return time.minusMinutes(units); case HOUR: return time.minusHours(units); case DAY: return time.minusDays(units); case MONTH: return time.minusMonths(units); } throw new RuntimeException("Unsupported granularity: " + granularity); } TimeIterator(ZonedDateTime startTime, ZonedDateTime endTime, Granularity granularity); @Override boolean hasNext(); @Override ZonedDateTime next(); @Override void remove(); static ZonedDateTime inc(ZonedDateTime time, Granularity granularity, long units); static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units); }
TimeIterator implements Iterator { public static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units) { switch (granularity) { case MINUTE: return time.minusMinutes(units); case HOUR: return time.minusHours(units); case DAY: return time.minusDays(units); case MONTH: return time.minusMonths(units); } throw new RuntimeException("Unsupported granularity: " + granularity); } TimeIterator(ZonedDateTime startTime, ZonedDateTime endTime, Granularity granularity); @Override boolean hasNext(); @Override ZonedDateTime next(); @Override void remove(); static ZonedDateTime inc(ZonedDateTime time, Granularity granularity, long units); static ZonedDateTime dec(ZonedDateTime time, Granularity granularity, long units);  }