Week Interval on Date Histogram Facet

This commit is contained in:
kimchy 2011-05-05 01:01:29 +03:00
parent 3000dc78fa
commit d3076945ac
2 changed files with 14 additions and 0 deletions

View File

@ -61,6 +61,8 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
.put("1y", new DateFieldParser.YearOfCentury()) .put("1y", new DateFieldParser.YearOfCentury())
.put("month", new DateFieldParser.MonthOfYear()) .put("month", new DateFieldParser.MonthOfYear())
.put("1m", new DateFieldParser.MonthOfYear()) .put("1m", new DateFieldParser.MonthOfYear())
.put("week", new DateFieldParser.WeekOfWeekyear())
.put("1w", new DateFieldParser.WeekOfWeekyear())
.put("day", new DateFieldParser.DayOfMonth()) .put("day", new DateFieldParser.DayOfMonth())
.put("1d", new DateFieldParser.DayOfMonth()) .put("1d", new DateFieldParser.DayOfMonth())
.put("hour", new DateFieldParser.HourOfDay()) .put("hour", new DateFieldParser.HourOfDay())
@ -209,6 +211,12 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
DateTimeField parse(Chronology chronology); DateTimeField parse(Chronology chronology);
static class WeekOfWeekyear implements DateFieldParser {
@Override public DateTimeField parse(Chronology chronology) {
return chronology.weekOfWeekyear();
}
}
static class YearOfCentury implements DateFieldParser { static class YearOfCentury implements DateFieldParser {
@Override public DateTimeField parse(Chronology chronology) { @Override public DateTimeField parse(Chronology chronology) {
return chronology.yearOfCentury(); return chronology.yearOfCentury();

View File

@ -153,6 +153,12 @@ public class SimpleJodaTests {
time.setMillis(utcTimeInMillis("2009-02-02T23:01:01")); time.setMillis(utcTimeInMillis("2009-02-02T23:01:01"));
assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000Z")); assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000Z"));
assertThat(time.getMillis(), equalTo(utcTimeInMillis("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() { @Test public void testRoundingWithTimeZone() {