@Test void getPrevious_onGranularity_returnsPreviousTime() { TimeGranularity granularity = new TimeGranularity(ChronoUnit.HOURS); LocalTime time = LocalTime.of(12, 0, 0); LocalTime expected = LocalTime.of(11, 0, 0); Assert.assertEquals(expected, granularity.getPrevious(time)); }
@Override public LocalTime getPrevious(LocalTime value, int amount) { if (!isCorrectScale(value)) { return trimToGranularity(value); } return value.minus(granularity.getDuration().multipliedBy(amount)); }
TimeGranularity implements Granularity<LocalTime> { @Override public LocalTime getPrevious(LocalTime value, int amount) { if (!isCorrectScale(value)) { return trimToGranularity(value); } return value.minus(granularity.getDuration().multipliedBy(amount)); } }
TimeGranularity implements Granularity<LocalTime> { @Override public LocalTime getPrevious(LocalTime value, int amount) { if (!isCorrectScale(value)) { return trimToGranularity(value); } return value.minus(granularity.getDuration().multipliedBy(amount)); } TimeGranularity(ChronoUnit granularity); }
TimeGranularity implements Granularity<LocalTime> { @Override public LocalTime getPrevious(LocalTime value, int amount) { if (!isCorrectScale(value)) { return trimToGranularity(value); } return value.minus(granularity.getDuration().multipliedBy(amount)); } TimeGranularity(ChronoUnit granularity); static TimeGranularity create(String granularity); @Override Granularity<LocalTime> getFinestGranularity(); @Override boolean isCorrectScale(LocalTime value); @Override Granularity<LocalTime> merge(Granularity<LocalTime> otherGranularity); @Override LocalTime getNext(LocalTime value, int amount); @Override LocalTime getNext(LocalTime value); @Override LocalTime getPrevious(LocalTime value, int amount); @Override LocalTime getPrevious(LocalTime value); @Override LocalTime trimToGranularity(LocalTime value); @Override LocalTime getRandom(LocalTime min, LocalTime max, RandomNumberGenerator randomNumberGenerator); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
TimeGranularity implements Granularity<LocalTime> { @Override public LocalTime getPrevious(LocalTime value, int amount) { if (!isCorrectScale(value)) { return trimToGranularity(value); } return value.minus(granularity.getDuration().multipliedBy(amount)); } TimeGranularity(ChronoUnit granularity); static TimeGranularity create(String granularity); @Override Granularity<LocalTime> getFinestGranularity(); @Override boolean isCorrectScale(LocalTime value); @Override Granularity<LocalTime> merge(Granularity<LocalTime> otherGranularity); @Override LocalTime getNext(LocalTime value, int amount); @Override LocalTime getNext(LocalTime value); @Override LocalTime getPrevious(LocalTime value, int amount); @Override LocalTime getPrevious(LocalTime value); @Override LocalTime trimToGranularity(LocalTime value); @Override LocalTime getRandom(LocalTime min, LocalTime max, RandomNumberGenerator randomNumberGenerator); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final TimeGranularity DEFAULT; }