當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTimeZone.forOffsetHours方法代碼示例

本文整理匯總了Java中org.joda.time.DateTimeZone.forOffsetHours方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTimeZone.forOffsetHours方法的具體用法?Java DateTimeZone.forOffsetHours怎麽用?Java DateTimeZone.forOffsetHours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.DateTimeZone的用法示例。


在下文中一共展示了DateTimeZone.forOffsetHours方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testExpression_CustomTimeZoneInIndexName

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
public void testExpression_CustomTimeZoneInIndexName() throws Exception {
    DateTimeZone timeZone;
    int hoursOffset;
    int minutesOffset = 0;
    if (randomBoolean()) {
        hoursOffset = randomIntBetween(-12, 14);
        timeZone = DateTimeZone.forOffsetHours(hoursOffset);
    } else {
        hoursOffset = randomIntBetween(-11, 13);
        minutesOffset = randomIntBetween(0, 59);
        timeZone = DateTimeZone.forOffsetHoursMinutes(hoursOffset, minutesOffset);
    }
    DateTime now;
    if (hoursOffset >= 0) {
        // rounding to next day 00:00
        now = DateTime.now(UTC).plusHours(hoursOffset).plusMinutes(minutesOffset).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    } else {
        // rounding to today 00:00
        now = DateTime.now(UTC).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    }
    Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis());
    List<String> results = expressionResolver.resolve(context, Arrays.asList("<.marvel-{now/d{YYYY.MM.dd|" + timeZone.getID() + "}}>"));
    assertThat(results.size(), equalTo(1));
    logger.info("timezone: [{}], now [{}], name: [{}]", timeZone, now, results.get(0));
    assertThat(results.get(0), equalTo(".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.withZone(timeZone))));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:DateMathExpressionResolverTests.java

示例2: testTAI64N

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
public void testTAI64N() {
    DateProcessor dateProcessor = new DateProcessor(randomAsciiOfLength(10), DateTimeZone.forOffsetHours(2), randomLocale(random()),
            "date_as_string", Collections.singletonList("TAI64N"), "date_as_date");
    Map<String, Object> document = new HashMap<>();
    String dateAsString = (randomBoolean() ? "@" : "") + "4000000050d506482dbdf024";
    document.put("date_as_string", dateAsString);
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    dateProcessor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2012-12-22T03:00:46.767+02:00"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:DateProcessorTests.java

示例3: testExpression_CustomTimeZoneInSetting

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
public void testExpression_CustomTimeZoneInSetting() throws Exception {
    DateTimeZone timeZone;
    int hoursOffset;
    int minutesOffset = 0;
    if (randomBoolean()) {
        hoursOffset = randomIntBetween(-12, 14);
        timeZone = DateTimeZone.forOffsetHours(hoursOffset);
    } else {
        hoursOffset = randomIntBetween(-11, 13);
        minutesOffset = randomIntBetween(0, 59);
        timeZone = DateTimeZone.forOffsetHoursMinutes(hoursOffset, minutesOffset);
    }
    DateTime now;
    if (hoursOffset >= 0) {
        // rounding to next day 00:00
        now = DateTime.now(UTC).plusHours(hoursOffset).plusMinutes(minutesOffset).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    } else {
        // rounding to today 00:00
        now = DateTime.now(UTC).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
    }
    Settings settings = Settings.builder()
            .put("date_math_expression_resolver.default_time_zone", timeZone.getID())
            .build();
    DateMathExpressionResolver expressionResolver = new DateMathExpressionResolver(settings);
    Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis());
    List<String> results = expressionResolver.resolve(context, Arrays.asList("<.marvel-{now/d{YYYY.MM.dd}}>"));
    assertThat(results.size(), equalTo(1));
    logger.info("timezone: [{}], now [{}], name: [{}]", timeZone, now, results.get(0));
    assertThat(results.get(0), equalTo(".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.withZone(timeZone))));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:DateMathExpressionResolverTests.java

示例4: testTimeIntervalRounding

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
/**
 * test TimeIntervalRounding, (interval &lt; 12h) with time zone shift
 */
public void testTimeIntervalRounding() {
    DateTimeZone tz = DateTimeZone.forOffsetHours(-1);
    Rounding tzRounding = Rounding.builder(TimeValue.timeValueHours(6)).timeZone(tz).build();
    assertThat(tzRounding.round(time("2009-02-03T00:01:01")), isDate(time("2009-02-02T19:00:00.000Z"), tz));
    assertThat(tzRounding.nextRoundingValue(time("2009-02-02T19:00:00.000Z")), isDate(time("2009-02-03T01:00:00.000Z"), tz));

    assertThat(tzRounding.round(time("2009-02-03T13:01:01")), isDate(time("2009-02-03T13:00:00.000Z"), tz));
    assertThat(tzRounding.nextRoundingValue(time("2009-02-03T13:00:00.000Z")), isDate(time("2009-02-03T19:00:00.000Z"), tz));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:TimeZoneRoundingTests.java

示例5: testDayIntervalRounding

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
/**
 * test DayIntervalRounding, (interval &gt;= 12h) with time zone shift
 */
public void testDayIntervalRounding() {
    DateTimeZone tz = DateTimeZone.forOffsetHours(-8);
    Rounding tzRounding = Rounding.builder(TimeValue.timeValueHours(12)).timeZone(tz).build();
    assertThat(tzRounding.round(time("2009-02-03T00:01:01")), isDate(time("2009-02-02T20:00:00.000Z"), tz));
    assertThat(tzRounding.nextRoundingValue(time("2009-02-02T20:00:00.000Z")), isDate(time("2009-02-03T08:00:00.000Z"), tz));

    assertThat(tzRounding.round(time("2009-02-03T13:01:01")), isDate(time("2009-02-03T08:00:00.000Z"), tz));
    assertThat(tzRounding.nextRoundingValue(time("2009-02-03T08:00:00.000Z")), isDate(time("2009-02-03T20:00:00.000Z"), tz));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:TimeZoneRoundingTests.java

示例6: testTimeRounding

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
public void testTimeRounding() {
    // hour unit
    DateTimeZone tz = DateTimeZone.forOffsetHours(-2);
    Rounding tzRounding = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(tz).build();
    assertThat(tzRounding.round(0), equalTo(0L));
    assertThat(tzRounding.nextRoundingValue(0L), equalTo(TimeValue.timeValueHours(1L).getMillis()));

    assertThat(tzRounding.round(time("2009-02-03T01:01:01")), isDate(time("2009-02-03T01:00:00"), tz));
    assertThat(tzRounding.nextRoundingValue(time("2009-02-03T01:00:00")), isDate(time("2009-02-03T02:00:00"), tz));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:TimeZoneRoundingTests.java

示例7: getOverflowDate

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
@Test
public void getOverflowDate() throws Exception {
    DateTime result = client.datetimes().getOverflow();
    // 9999-12-31T23:59:59.999-14:000
    DateTime expected = new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeZone.forOffsetHours(-14));
    expected = expected.toDateTime(DateTimeZone.UTC);
    Assert.assertEquals(expected, result);
}
 
開發者ID:Azure,項目名稱:autorest.java,代碼行數:9,代碼來源:DatetimeOperationsTests.java

示例8: testSingleValueFieldWithExtendedBoundsTimezone

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
/**
 * Test date histogram aggregation with hour interval, timezone shift and
 * extended bounds (see https://github.com/elastic/elasticsearch/issues/12278)
 */
public void testSingleValueFieldWithExtendedBoundsTimezone() throws Exception {
    String index = "test12278";
    prepareCreate(index)
            .setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 1).put("index.number_of_replicas", 0))
            .execute().actionGet();

    DateMathParser parser = new DateMathParser(Joda.getStrictStandardDateFormatter());

    // we pick a random timezone offset of +12/-12 hours and insert two documents
    // one at 00:00 in that time zone and one at 12:00
    List<IndexRequestBuilder> builders = new ArrayList<>();
    int timeZoneHourOffset = randomIntBetween(-12, 12);
    DateTimeZone timezone = DateTimeZone.forOffsetHours(timeZoneHourOffset);
    DateTime timeZoneStartToday = new DateTime(parser.parse("now/d", System::currentTimeMillis, false, timezone), DateTimeZone.UTC);
    DateTime timeZoneNoonToday = new DateTime(parser.parse("now/d+12h", System::currentTimeMillis, false, timezone), DateTimeZone.UTC);
    builders.add(indexDoc(index, timeZoneStartToday, 1));
    builders.add(indexDoc(index, timeZoneNoonToday, 2));
    indexRandom(true, builders);
    ensureSearchable(index);

    SearchResponse response = null;
    // retrieve those docs with the same time zone and extended bounds
    response = client()
            .prepareSearch(index)
            .setQuery(QueryBuilders.rangeQuery("date").from("now/d").to("now/d").includeLower(true).includeUpper(true).timeZone(timezone.getID()))
            .addAggregation(
                    dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.hours(1)).timeZone(timezone).minDocCount(0)
                            .extendedBounds(new ExtendedBounds("now/d", "now/d+23h"))
            ).execute().actionGet();
    assertSearchResponse(response);

    assertThat("Expected 24 buckets for one day aggregation with hourly interval", response.getHits().getTotalHits(), equalTo(2L));

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(24));

    for (int i = 0; i < buckets.size(); i++) {
        Histogram.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat("InternalBucket " + i + " had wrong key", (DateTime) bucket.getKey(), equalTo(new DateTime(timeZoneStartToday.getMillis() + (i * 60 * 60 * 1000), DateTimeZone.UTC)));
        if (i == 0 || i == 12) {
            assertThat(bucket.getDocCount(), equalTo(1L));
        } else {
            assertThat(bucket.getDocCount(), equalTo(0L));
        }
    }
    internalCluster().wipeIndices("test12278");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:56,代碼來源:DateHistogramIT.java

示例9: putLocalPositiveOffsetMaxDateTime

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
@Test
public void putLocalPositiveOffsetMaxDateTime() throws Exception {
    DateTime body = new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeZone.forOffsetHours(14));
    client.datetimes().putLocalPositiveOffsetMaxDateTime(body);
}
 
開發者ID:Azure,項目名稱:autorest.java,代碼行數:6,代碼來源:DatetimeOperationsTests.java

示例10: putLocalNegativeOffsetMaxDateTime

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
@Test
public void putLocalNegativeOffsetMaxDateTime() throws Exception {
    DateTime body = new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeZone.forOffsetHours(-14));
    client.datetimes().putLocalNegativeOffsetMaxDateTime(body);
}
 
開發者ID:Azure,項目名稱:autorest.java,代碼行數:6,代碼來源:DatetimeOperationsTests.java

示例11: putLocalPositiveOffsetMinDateTime

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
@Test
public void putLocalPositiveOffsetMinDateTime() throws Exception {
    DateTime body = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.forOffsetHours(14));
    client.datetimes().putLocalPositiveOffsetMinDateTime(body);
}
 
開發者ID:Azure,項目名稱:autorest.java,代碼行數:6,代碼來源:DatetimeOperationsTests.java

示例12: putLocalNegativeOffsetMinDateTime

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
@Test
public void putLocalNegativeOffsetMinDateTime() throws Exception {
    DateTime body = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.forOffsetHours(-14));
    client.datetimes().putLocalNegativeOffsetMinDateTime(body);
}
 
開發者ID:Azure,項目名稱:autorest.java,代碼行數:6,代碼來源:DatetimeOperationsTests.java


注:本文中的org.joda.time.DateTimeZone.forOffsetHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。