本文整理汇总了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));
}
}
}
}
示例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;
}
示例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));
}