use of org.joda.time.DateTime in project druid by druid-io.
the class QueryGranularityTest method testPeriodDaylightSaving.
@Test
public void testPeriodDaylightSaving() throws Exception {
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
final DateTime baseTime = new DateTime("2012-11-04T00:00:00", tz);
assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-05T00:00:00.000-08:00"), new DateTime("2012-11-06T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1D"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Days.days(3)).getMillis())));
assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-08:00"), new DateTime("2012-11-04T02:00:00.000-08:00"), new DateTime("2012-11-04T03:00:00.000-08:00")), new PeriodGranularity(new Period("PT1H"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Hours.hours(5)).getMillis())));
final PeriodGranularity hour = new PeriodGranularity(new Period("PT1H"), null, tz);
assertSameDateTime(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-08:00"), new DateTime("2012-11-04T02:00:00.000-08:00"), new DateTime("2012-11-04T03:00:00.000-08:00")), Lists.newArrayList(hour.bucketStart(new DateTime("2012-11-04T00:30:00-07:00")), hour.bucketStart(new DateTime("2012-11-04T01:30:00-07:00")), hour.bucketStart(new DateTime("2012-11-04T01:30:00-08:00")), hour.bucketStart(new DateTime("2012-11-04T02:30:00-08:00")), hour.bucketStart(new DateTime("2012-11-04T03:30:00-08:00"))));
}
use of org.joda.time.DateTime in project druid by druid-io.
the class QueryGranularityTest method testIterableHourSimple.
@Test
public void testIterableHourSimple() throws Exception {
final DateTime baseTime = new DateTime("2011-01-01T09:00:00.000Z");
assertSameInterval(Lists.newArrayList(new DateTime("2011-01-01T09:00:00.000Z"), new DateTime("2011-01-01T10:00:00.000Z"), new DateTime("2011-01-01T11:00:00.000Z")), Granularities.HOUR.getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Hours.hours(3)).getMillis())));
}
use of org.joda.time.DateTime in project druid by druid-io.
the class DefaultObjectMapperTest method testDateTime.
@Test
public void testDateTime() throws Exception {
final DateTime time = new DateTime();
Assert.assertEquals(String.format("\"%s\"", time), mapper.writeValueAsString(time));
}
use of org.joda.time.DateTime in project druid by druid-io.
the class CombiningIterableTest method testMerge.
@Test
public void testMerge() {
List<Result<Object>> resultsBefore = Arrays.asList(new Result<Object>(new DateTime("2011-01-01"), 1L), new Result<Object>(new DateTime("2011-01-01"), 2L));
Iterable<Result<Object>> expectedResults = Arrays.<Result<Object>>asList(new Result<Object>(new DateTime("2011-01-01"), 3L));
Iterable<Result<Object>> resultsAfter = CombiningIterable.create(resultsBefore, new Comparator<Result<Object>>() {
@Override
public int compare(Result<Object> r1, Result<Object> r2) {
return r1.getTimestamp().compareTo(r2.getTimestamp());
}
}, new BinaryFn<Result<Object>, Result<Object>, Result<Object>>() {
@Override
public Result<Object> apply(final Result<Object> arg1, final Result<Object> arg2) {
if (arg1 == null) {
return arg2;
}
if (arg2 == null) {
return arg1;
}
return new Result<Object>(arg1.getTimestamp(), ((Long) arg1.getValue()).longValue() + ((Long) arg2.getValue()).longValue());
}
});
Iterator<Result<Object>> it1 = expectedResults.iterator();
Iterator<Result<Object>> it2 = resultsAfter.iterator();
while (it1.hasNext() && it2.hasNext()) {
Result r1 = it1.next();
Result r2 = it2.next();
Assert.assertEquals(r1.getTimestamp(), r2.getTimestamp());
Assert.assertEquals(r1.getValue(), r2.getValue());
}
}
use of org.joda.time.DateTime in project druid by druid-io.
the class QueryGranularityTest method testIterableMonth.
@Test
public void testIterableMonth() throws Exception {
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
final DateTime baseTime = new DateTime("2012-11-03T10:00:00", tz);
assertSameInterval(Lists.newArrayList(new DateTime("2012-11-01T00:00:00.000-07:00"), new DateTime("2012-12-01T00:00:00.000-08:00"), new DateTime("2013-01-01T00:00:00.000-08:00"), new DateTime("2013-02-01T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1M"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Months.months(3)).getMillis())));
}
Aggregations