package com.github.omribromberg.elasticsearch.datemath.formatter;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalUnit;
import java.util.*;

public class DateMathFormatter {
    public static Collection<String> getAllPatternsBetween(ZonedDateTime start, ZonedDateTime end, String pattern) {
        final Collection<String> formattedPatterns = new ArrayList<>();
        final TemporalUnit lowestUnit = getLowestField(pattern).getTemporal().getBaseUnit();
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);

        for (int i = 0; i <= lowestUnit.between(start.truncatedTo(lowestUnit), end.truncatedTo(lowestUnit)); i++) {
            formattedPatterns.add(formatter.format(start.plus(i, lowestUnit)));
        }

        return formattedPatterns;
    }

    private static FieldSymbol getLowestField(String pattern) {
        final Set<FieldSymbol> fields = new HashSet<>();

        boolean escaped = false;
        FieldSymbol lowest = null;

        for (char current : pattern.toCharArray()) {
            if (current == '\'') {
                escaped = !escaped;
            } else if (!escaped) {
                final FieldSymbol symbol = FieldSymbol.of(current);
                if (Objects.nonNull(symbol)) {
                    fields.add(symbol);
                    if (lowest == null || lowest.ordinal() > symbol.ordinal()) {
                        lowest = symbol;
                    }
                }
            }
        }

        if (Objects.isNull(lowest)) {
            throw new DateMathFormatException("Pattern '" + pattern + "' does not contain any field symbols");
        }

        if (!lowest.checkDependencies(fields)) {
            throw new DateMathFormatException("Field '" + lowest.name() + "' does not have all of his dependencies");
        }

        return lowest;
    }

}

@@ -229,16 +229,266 @@
 atter %7B%0A
+    private final FieldSymbol lowestField;%0A    private final DateTimeFormatter formatter;%0A%0A    public DateMathFormatter(String pattern) %7B%0A        lowestField = getLowestField(pattern);%0A        formatter = DateTimeFormatter.ofPattern(pattern);%0A    %7D%0A%0A
     publ
@@ -600,80 +600,8 @@
 ) %7B%0A
-        final Collection%3CString%3E formattedPatterns = new ArrayList%3C%3E();%0A
     
@@ -768,24 +768,333 @@
 (pattern);%0A%0A
+        return getAllPatternsBetween(start, end, lowestUnit, formatter);%0A    %7D%0A%0A    private static Collection%3CString%3E getAllPatternsBetween(ZonedDateTime start, ZonedDateTime end, TemporalUnit lowestUnit, DateTimeFormatter formatter) %7B%0A        final Collection%3CString%3E formattedPatterns = new ArrayList%3C%3E();%0A%0A
         for 
@@ -2389,10 +2389,213 @@
 %0A    %7D%0A%0A
+    public Collection%3CString%3E getAllPatternsBetween(ZonedDateTime start, ZonedDateTime end) %7B%0A        return getAllPatternsBetween(start, end, lowestField.getTemporal().getBaseUnit(), formatter);%0A    %7D%0A%0A
 %7D%0A

Add non static option for DateMathFormatter