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


Java DateTimeZone.getOffset方法代碼示例

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


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

示例1: testRoundingRandom

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
/**
 * Randomized test on TimeUnitRounding. Test uses random
 * {@link DateTimeUnit} and {@link DateTimeZone} and often (50% of the time)
 * chooses test dates that are exactly on or close to offset changes (e.g.
 * DST) in the chosen time zone.
 *
 * It rounds the test date down and up and performs various checks on the
 * rounding unit interval that is defined by this. Assumptions tested are
 * described in
 * {@link #assertInterval(long, long, long, Rounding, DateTimeZone)}
 */
public void testRoundingRandom() {
    for (int i = 0; i < 1000; ++i) {
        DateTimeUnit timeUnit = randomTimeUnit();
        DateTimeZone tz = randomDateTimeZone();
        Rounding rounding = new Rounding.TimeUnitRounding(timeUnit, tz);
        long date = Math.abs(randomLong() % (2 * (long) 10e11)); // 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
        long unitMillis = timeUnit.field(tz).getDurationField().getUnitMillis();
        if (randomBoolean()) {
            nastyDate(date, tz, unitMillis);
        }
        final long roundedDate = rounding.round(date);
        final long nextRoundingValue = rounding.nextRoundingValue(roundedDate);

        assertInterval(roundedDate, date, nextRoundingValue, rounding, tz);

        // check correct unit interval width for units smaller than a day, they should be fixed size except for transitions
        if (unitMillis <= DateTimeConstants.MILLIS_PER_DAY) {
            // if the interval defined didn't cross timezone offset transition, it should cover unitMillis width
            if (tz.getOffset(roundedDate - 1) == tz.getOffset(nextRoundingValue + 1)) {
                assertThat("unit interval width not as expected for [" + timeUnit + "], [" + tz + "] at "
                        + new DateTime(roundedDate), nextRoundingValue - roundedDate, equalTo(unitMillis));
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:37,代碼來源:TimeZoneRoundingTests.java

示例2: execute

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
@Override
public ServerTimeZoneResponse execute(ServerTimeZoneRequest request, SessionContext context) {
	Date first = null, last = null;
	for (Session session: SessionDAO.getInstance().findAll()) {
		if (first == null || first.after(session.getEventBeginDate()))
			first = session.getEventBeginDate();
		if (last == null || last.before(session.getEventEndDate()))
			last = session.getEventEndDate();
	}
	DateTimeZone zone = DateTimeZone.getDefault();
	int offsetInMinutes = zone.getOffset(first.getTime()) / 60000;
	ServerTimeZoneResponse ret = new ServerTimeZoneResponse();
	ret.setId(zone.getID());
	ret.addName(zone.getName(new Date().getTime()));
	ret.setTimeZoneOffsetInMinutes(offsetInMinutes);
	long time = first.getTime();
	long transition;
	while (time != (transition = zone.nextTransition(time)) && time < last.getTime()) {
		int adjustment = (zone.getOffset(transition) / 60000) - offsetInMinutes;
		ret.addTransition((int)(transition / 3600000), adjustment);
		time = transition;
	}
	return ret;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:25,代碼來源:ServerTimeZoneBackend.java

示例3: testSingleValueFieldWithDateMath

import org.joda.time.DateTimeZone; //導入方法依賴的package包/類
public void testSingleValueFieldWithDateMath() throws Exception {
    DateTimeZone timezone = randomDateTimeZone();
    int timeZoneOffset = timezone.getOffset(date(2, 15));
    // if time zone is UTC (or equivalent), time zone suffix is "Z", else something like "+03:00", which we get with the "ZZ" format
    String feb15Suffix = timeZoneOffset == 0 ? "Z" : date(2,15, timezone).toString("ZZ");
    String mar15Suffix = timeZoneOffset == 0 ? "Z" : date(3,15, timezone).toString("ZZ");
    long expectedFirstBucketCount = timeZoneOffset < 0 ? 3L : 2L;

    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("date")
                    .addUnboundedTo("2012-02-15")
                    .addRange("2012-02-15", "2012-02-15||+1M")
                    .addUnboundedFrom("2012-02-15||+1M")
                    .timeZone(timezone))
            .execute().actionGet();

    assertSearchResponse(response);

    Range range = response.getAggregations().get("range");
    assertThat(range, notNullValue());
    assertThat(range.getName(), equalTo("range"));
    List<? extends Bucket> buckets = range.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("*-2012-02-15T00:00:00.000" + feb15Suffix));
    assertThat(((DateTime) bucket.getFrom()), nullValue());
    assertThat(((DateTime) bucket.getTo()), equalTo(date(2, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(bucket.getFromAsString(), nullValue());
    assertThat(bucket.getToAsString(), equalTo("2012-02-15T00:00:00.000" + feb15Suffix));
    assertThat(bucket.getDocCount(), equalTo(expectedFirstBucketCount));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-02-15T00:00:00.000" + feb15Suffix +
            "-2012-03-15T00:00:00.000" + mar15Suffix));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(2, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(((DateTime) bucket.getTo()), equalTo(date(3, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(bucket.getFromAsString(), equalTo("2012-02-15T00:00:00.000" + feb15Suffix));
    assertThat(bucket.getToAsString(), equalTo("2012-03-15T00:00:00.000" + mar15Suffix));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-03-15T00:00:00.000" + mar15Suffix + "-*"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(3, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(((DateTime) bucket.getTo()), nullValue());
    assertThat(bucket.getFromAsString(), equalTo("2012-03-15T00:00:00.000" + mar15Suffix));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(numDocs - 2L - expectedFirstBucketCount));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:54,代碼來源:DateRangeIT.java


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