*/
private static Interval<DateUnit> parseDateInterval(JsonNode node) {
try {
if (node.hasNonNull("dateInterval") && node.get("dateInterval").hasNonNull("aggregationType")) {
JsonNode dateInterval = node.get("dateInterval");
DateUnit unit = DateUnit.valueOf(dateInterval.get("aggregationType").asText().toUpperCase(Locale.ENGLISH));
JsonNode interval = dateInterval.get("interval");
String type = interval.get("type").asText().toLowerCase(Locale.ENGLISH);
if ("relative".equals(type)) {
// the server may send numbers inside strings
// or numbers as decimals, e.g. 3.0
// regardless, we treat them all as int
String from = interval.get("from").asText();
String to = interval.get("to").asText();
return new RelativeInterval<DateUnit>(unit, (int) Float.parseFloat(from), (int) Float.parseFloat(to));
} else if ("absolute".equals(type)) {
// an absolute interval
return new AbsoluteInterval<DateUnit>(unit, unit.parseAbsolute(interval.get("from")),
unit.parseAbsolute(interval.get("to")));
} else if ("custom".equals(type)) {
// a custom interval
return new CustomInterval<DateUnit>(unit, interval.get("from").asText(), interval.get("to").asText());
}
}