26 lines
679 B
Java
26 lines
679 B
Java
package org.lucares.utils;
|
|
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.time.temporal.Temporal;
|
|
import java.time.temporal.TemporalAdjuster;
|
|
|
|
public class EndOfInterval implements TemporalAdjuster {
|
|
|
|
private final DateBucketUnit unit;
|
|
|
|
public EndOfInterval(final DateBucketUnit unit) {
|
|
this.unit = unit;
|
|
}
|
|
|
|
@Override
|
|
public Temporal adjustInto(final Temporal temporal) {
|
|
Temporal result = temporal;
|
|
final BeginningOfNextInterval beginningOfnextInterval = new BeginningOfNextInterval(unit);
|
|
result = result.with(beginningOfnextInterval);
|
|
|
|
result = result.minus(1, ChronoUnit.NANOS);
|
|
return result;
|
|
}
|
|
|
|
}
|