Search in sources :

Example 76 with DateTimeZone

use of org.joda.time.DateTimeZone in project joda-time-android by dlew.

the class TestDateTimeZone method testGetNameKey.

public void testGetNameKey() {
    DateTimeZone zone = DateTimeZone.forID("Europe/London");
    assertEquals("BST", zone.getNameKey(TEST_TIME_SUMMER));
    assertEquals("GMT", zone.getNameKey(TEST_TIME_WINTER));
}
Also used : DateTimeZone(org.joda.time.DateTimeZone)

Example 77 with DateTimeZone

use of org.joda.time.DateTimeZone in project joda-time-android by dlew.

the class TestDateTimeZone method testGetOffset_long.

//-----------------------------------------------------------------------
public void testGetOffset_long() {
    DateTimeZone zone = DateTimeZone.forID("Europe/Paris");
    assertEquals(2L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(TEST_TIME_SUMMER));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(TEST_TIME_WINTER));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getStandardOffset(TEST_TIME_SUMMER));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getStandardOffset(TEST_TIME_WINTER));
    assertEquals(2L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffsetFromLocal(TEST_TIME_SUMMER));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffsetFromLocal(TEST_TIME_WINTER));
    assertEquals(false, zone.isStandardOffset(TEST_TIME_SUMMER));
    assertEquals(true, zone.isStandardOffset(TEST_TIME_WINTER));
}
Also used : DateTimeZone(org.joda.time.DateTimeZone)

Example 78 with DateTimeZone

use of org.joda.time.DateTimeZone in project elasticsearch by elastic.

the class DateHistogramIT method testSingleValuedFieldWithTimeZone.

public void testSingleValuedFieldWithTimeZone() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(1).timeZone(DateTimeZone.forID("+01:00"))).execute().actionGet();
    DateTimeZone tz = DateTimeZone.forID("+01:00");
    assertSearchResponse(response);
    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(6));
    DateTime key = new DateTime(2012, 1, 1, 23, 0, DateTimeZone.UTC);
    Histogram.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
    key = new DateTime(2012, 2, 1, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
    key = new DateTime(2012, 2, 14, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
    key = new DateTime(2012, 3, 1, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(3);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
    key = new DateTime(2012, 3, 14, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(4);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
    key = new DateTime(2012, 3, 22, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(5);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 79 with DateTimeZone

use of org.joda.time.DateTimeZone in project elasticsearch by elastic.

the class DateHistogramIT method testSingleValued_timeZone_epoch.

public void testSingleValued_timeZone_epoch() throws Exception {
    String format = randomBoolean() ? "epoch_millis" : "epoch_second";
    int millisDivider = format.equals("epoch_millis") ? 1 : 1000;
    if (randomBoolean()) {
        format = format + "||date_optional_time";
    }
    DateTimeZone tz = DateTimeZone.forID("+01:00");
    SearchResponse response = client().prepareSearch("idx").addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(1).timeZone(tz).format(format)).execute().actionGet();
    assertSearchResponse(response);
    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(6));
    List<DateTime> expectedKeys = new ArrayList<>();
    expectedKeys.add(new DateTime(2012, 1, 1, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 2, 1, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 2, 14, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 3, 1, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 3, 14, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 3, 22, 23, 0, DateTimeZone.UTC));
    Iterator<DateTime> keyIterator = expectedKeys.iterator();
    for (Histogram.Bucket bucket : buckets) {
        assertThat(bucket, notNullValue());
        DateTime expectedKey = keyIterator.next();
        assertThat(bucket.getKeyAsString(), equalTo(Long.toString(expectedKey.getMillis() / millisDivider)));
        assertThat(((DateTime) bucket.getKey()), equalTo(expectedKey));
        assertThat(bucket.getDocCount(), equalTo(1L));
    }
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 80 with DateTimeZone

use of org.joda.time.DateTimeZone in project elasticsearch by elastic.

the class DateHistogramIT method testIssue6965.

public void testIssue6965() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(dateHistogram("histo").field("date").timeZone(DateTimeZone.forID("+01:00")).dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)).execute().actionGet();
    assertSearchResponse(response);
    DateTimeZone tz = DateTimeZone.forID("+01:00");
    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(3));
    DateTime key = new DateTime(2011, 12, 31, 23, 0, DateTimeZone.UTC);
    Histogram.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(1L));
    key = new DateTime(2012, 1, 31, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(2L));
    key = new DateTime(2012, 2, 29, 23, 0, DateTimeZone.UTC);
    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo(getBucketKeyAsString(key, tz)));
    assertThat(((DateTime) bucket.getKey()), equalTo(key));
    assertThat(bucket.getDocCount(), equalTo(3L));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) Bucket(org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

DateTimeZone (org.joda.time.DateTimeZone)263 DateTime (org.joda.time.DateTime)123 ArrayList (java.util.ArrayList)36 Test (org.testng.annotations.Test)35 LocalDate (org.joda.time.LocalDate)27 Test (org.junit.Test)21 TimeIntervalRounding (org.elasticsearch.common.rounding.Rounding.TimeIntervalRounding)18 TimeUnitRounding (org.elasticsearch.common.rounding.Rounding.TimeUnitRounding)18 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)15 UUID (java.util.UUID)14 TimeFormat (org.gephi.graph.api.TimeFormat)13 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)12 Date (java.util.Date)12 Chronology (org.joda.time.Chronology)12 LocalDateTime (org.joda.time.LocalDateTime)12 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)11 LocalTime (org.joda.time.LocalTime)10 SubscriptionBaseTransition (org.killbill.billing.subscription.api.user.SubscriptionBaseTransition)10