private static Range<Long> extractRange(final List<ExpressionTerm> dateTerms,
                                            final DateTimeSettings dateTimeSettings) {
        long maxRangeFrom = 0;
        long minRangeTo = Long.MAX_VALUE;

        for (final ExpressionTerm term : dateTerms) {
            long rangeFrom = 0;
            long rangeTo = Long.MAX_VALUE;

            if (Condition.BETWEEN.equals(term.getCondition())) {
                final String[] dateArr = term.getValue().split(",");

                if (dateArr.length != 2) {
                    throw RestUtil.badRequest("DateTime term is not a valid format, term: " + term);
                }

                rangeFrom = parseDateTime("from", dateArr[0], dateTimeSettings);
                // add one to make it exclusive
                rangeTo = parseDateTime("to", dateArr[1], dateTimeSettings) + 1;
            } else if (Condition.EQUALS.equals(term.getCondition())) {
                rangeFrom = parseDateTime("from", term.getValue(), dateTimeSettings);
                rangeTo = rangeFrom;
            } else if (Condition.GREATER_THAN.equals(term.getCondition())) {
                rangeFrom = parseDateTime("from", term.getValue(), dateTimeSettings) + 1;
            } else if (Condition.GREATER_THAN_OR_EQUAL_TO.equals(term.getCondition())) {
                rangeFrom = parseDateTime("from", term.getValue(), dateTimeSettings);
            } else if (Condition.LESS_THAN.equals(term.getCondition())) {
                rangeTo = parseDateTime("to", term.getValue(), dateTimeSettings) - 1;
            } else if (Condition.LESS_THAN_OR_EQUAL_TO.equals(term.getCondition())) {
                rangeTo = parseDateTime("to", term.getValue(), dateTimeSettings);
            } else {
                throw RestUtil.badRequest("Unsupported condition for DateTime term: " + term);
            }

            maxRangeFrom = Math.max(maxRangeFrom, rangeFrom);
            minRangeTo = Math.min(minRangeTo, rangeTo);
        }

        return new Range<>(maxRangeFrom, minRangeTo);
    }
Recursive method to populates the passed list with all enabled
{@link ExpressionTerm} nodes found in the tree.
stroom-statistics/stroom-statistics-impl-sql/src/main/java/stroom/statistics/impl/sql/search/StatStoreCriteriaBuilder.java