当前位置: 首页>>代码示例>>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;未经允许,请勿转载。