This is a datemath library for Elasticsearch written in Java
It supports the datemath expression standard of Elasticsearch 5.5
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/date-math-expressions.html
DateMathParser dateMathParser = new DateMathBuilder()
.pattern("yyyy-MM-dd HH-ss")
.zone(ZoneId.of("America/New_York"))
.build();
dateMathParser.resolveExpression("1998-09-18 16-43||-4d");
// gets the current datetime and subtracts 5 days
dateMathParser.resolveExpression("now-5d");
// gets the current datetime and substracts 6 months, adds 6 years and rounds the month
dateMathParser.resolveExpression("now-6M+6Y/M");
// gets the datetime of "2017-07-18" and adds 5 minutes
dateMathParser.resolveExpression("2017-07-18||+5m");
// creates a new instance from the current with the new pattern
dateMathBuilder.pattern("yyyy-MM-dd");
// creates a new instance from the current with the new zone
dateMathBuilder.zone(ZoneId.of("America/New_York"));
// creates a new instance from the current with the new nowSupplier
dateMathBuilder.now(() -> ZonedDateTime.now(ZoneId.of("America/New_York")));
// creates a new instance from the current with the new nowPattern
dateMathBuilder.nowPattern("now");
// creates a new DateMathParser instance and returns it
dateMathBuilder.build();
static Collection<String> getAllPatternsBetween(ZonedDateTime start, ZonedDateTime end, String pattern)
// gets all the patterns of datetimes between start and end
DateMathFormatter.getAllPatternsBetween(ZonedDateTime.now().minus(7, ChronoUnit.YEARS), ZonedDateTime.now(), "yyyy-MM-dd HH");
// gets all the patterns of datetimes between start and end
dateMathFormatter.getAllPatternsBetween(ZonedDateTime.now().minus(7, ChronoUnit.YEARS), ZonedDateTime.now(), "yyyy-MM-dd HH");