replace the dateTo with an interval
I hope an interval is easier to handle than having to change two date fields
This commit is contained in:
@@ -5,6 +5,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -26,7 +27,7 @@ public class PlotSettings {
|
||||
|
||||
private String dateFrom;
|
||||
|
||||
private String dateTo;
|
||||
private String dateRange;
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
@@ -84,12 +85,12 @@ public class PlotSettings {
|
||||
this.dateFrom = dateFrom;
|
||||
}
|
||||
|
||||
public String getDateTo() {
|
||||
return dateTo;
|
||||
public String getDateRange() {
|
||||
return dateRange;
|
||||
}
|
||||
|
||||
public void setDateTo(final String dateTo) {
|
||||
this.dateTo = dateTo;
|
||||
public void setDateRange(final String dateRange) {
|
||||
this.dateRange = dateRange;
|
||||
}
|
||||
|
||||
public OffsetDateTime dateFrom() {
|
||||
@@ -103,10 +104,40 @@ public class PlotSettings {
|
||||
}
|
||||
|
||||
public OffsetDateTime dateTo() {
|
||||
if (StringUtils.isEmpty(dateTo)) {
|
||||
|
||||
final int period = Integer.parseInt(dateRange.split(" ")[0]);
|
||||
final ChronoUnit unit = toChronoUnit(dateRange.split(" ")[1]);
|
||||
|
||||
if (StringUtils.isEmpty(dateRange)) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
|
||||
} else {
|
||||
return LocalDateTime.parse(dateTo, DATE_FORMAT).atOffset(ZoneOffset.UTC);
|
||||
return dateFrom().plus(period, unit);
|
||||
}
|
||||
}
|
||||
|
||||
private ChronoUnit toChronoUnit(final String string) {
|
||||
|
||||
switch (string) {
|
||||
case "second":
|
||||
case "seconds":
|
||||
return ChronoUnit.SECONDS;
|
||||
case "minute":
|
||||
case "minutes":
|
||||
return ChronoUnit.MINUTES;
|
||||
case "hour":
|
||||
case "hours":
|
||||
return ChronoUnit.HOURS;
|
||||
case "day":
|
||||
case "days":
|
||||
return ChronoUnit.DAYS;
|
||||
case "week":
|
||||
case "weeks":
|
||||
return ChronoUnit.WEEKS;
|
||||
case "month":
|
||||
case "months":
|
||||
return ChronoUnit.MONTHS;
|
||||
default:
|
||||
throw new IllegalArgumentException(string + " is an unknown chrono unit");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user