@Test public void test_aggregationByHourOverMarch_dst() { ListDataPointGroup group = new ListDataPointGroup("March"); DateTimeZone paris = DateTimeZone.forID("Europe/Paris"); for (DateTime hour = new DateTime(2014, 3, 1, 0, 0, paris); // 1st of March hour.isBefore(new DateTime(2014, 4, 1, 0, 0, paris)); // 1st of April hour = hour.plusHours(1)) { group.addDataPoint(new LongDataPoint(hour.getMillis(), 1L)); } SumAggregator aggregator = new SumAggregator(new DoubleDataPointFactoryImpl()); aggregator.setTimeZone(paris); aggregator.setSampling(new Sampling(1, TimeUnit.MONTHS)); aggregator.setAlignSampling(true); DataPointGroup hourCount = aggregator.aggregate(group); assert hourCount.hasNext(); // 31 * 24 - 1 = 743 hours in March assertThat(hourCount.next().getLongValue(), is(743L)); assertThat(hourCount.hasNext(), is(false)); }
@Test public void test_multipleMonthAggregationWithUTCCheckAlignmentStartTime() { ListDataPointGroup dpGroup = new ListDataPointGroup("range_test"); DateTimeZone utc = DateTimeZone.UTC; DateTime startDate = new DateTime(2014, 1, 1, 1, 1, utc); // LEAP year DateTime stopDate = new DateTime(2014, 7, 10, 1, 1, utc); for (DateTime iterationDT = startDate; iterationDT.isBefore(stopDate); iterationDT = iterationDT.plusDays(5)) { dpGroup.addDataPoint(new LongDataPoint(iterationDT.getMillis(), 1)); } SumAggregator agg = new SumAggregator(new DoubleDataPointFactoryImpl()); agg.setTimeZone(utc); agg.setSampling(new Sampling(3, TimeUnit.MONTHS)); agg.setAlignSampling(true); agg.setAlignStartTime(true); agg.setStartTime(startDate.getMillis()); DataPointGroup dpg = agg.aggregate(dpGroup); assertThat(dpg.hasNext(), is(true)); DataPoint next = dpg.next(); assertThat(new DateTime(next.getTimestamp(), utc), is(new DateTime(2014, 1, 1, 0, 0, utc))); assertThat(dpg.hasNext(), is(true)); next = dpg.next(); assertThat(new DateTime(next.getTimestamp(), utc), is(new DateTime(2014, 4, 1, 0, 0, utc))); assertThat(dpg.hasNext(), is(true)); next = dpg.next(); assertThat(new DateTime(next.getTimestamp(), utc), is(new DateTime(2014, 7, 1, 0, 0, utc))); assertThat(dpg.hasNext(), is(false)); }