From d3076945acb6257a84868f711d4e4fe09f9e452e Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 5 May 2011 01:01:29 +0300 Subject: [PATCH] Week Interval on Date Histogram Facet --- .../facet/datehistogram/DateHistogramFacetProcessor.java | 8 ++++++++ .../java/org/elasticsearch/deps/joda/SimpleJodaTests.java | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetProcessor.java index 7fa24e9f614..9acdf777484 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetProcessor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetProcessor.java @@ -61,6 +61,8 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa .put("1y", new DateFieldParser.YearOfCentury()) .put("month", new DateFieldParser.MonthOfYear()) .put("1m", new DateFieldParser.MonthOfYear()) + .put("week", new DateFieldParser.WeekOfWeekyear()) + .put("1w", new DateFieldParser.WeekOfWeekyear()) .put("day", new DateFieldParser.DayOfMonth()) .put("1d", new DateFieldParser.DayOfMonth()) .put("hour", new DateFieldParser.HourOfDay()) @@ -209,6 +211,12 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa DateTimeField parse(Chronology chronology); + static class WeekOfWeekyear implements DateFieldParser { + @Override public DateTimeField parse(Chronology chronology) { + return chronology.weekOfWeekyear(); + } + } + static class YearOfCentury implements DateFieldParser { @Override public DateTimeField parse(Chronology chronology) { return chronology.yearOfCentury(); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java index 8572b9835ff..a4eba9bfd49 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java @@ -153,6 +153,12 @@ public class SimpleJodaTests { time.setMillis(utcTimeInMillis("2009-02-02T23:01:01")); assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000Z")); assertThat(time.getMillis(), equalTo(utcTimeInMillis("2009-02-02T00:00:00.000Z"))); + + time = new MutableDateTime(DateTimeZone.UTC); + time.setRounding(time.getChronology().weekOfWeekyear(), MutableDateTime.ROUND_FLOOR); + time.setMillis(utcTimeInMillis("2011-05-05T01:01:01")); + assertThat(time.toString(), equalTo("2011-05-02T00:00:00.000Z")); + assertThat(time.getMillis(), equalTo(utcTimeInMillis("2011-05-02T00:00:00.000Z"))); } @Test public void testRoundingWithTimeZone() {