本文整理汇总了Java中org.joda.time.PeriodType.forFields方法的典型用法代码示例。如果您正苦于以下问题:Java PeriodType.forFields方法的具体用法?Java PeriodType.forFields怎么用?Java PeriodType.forFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.PeriodType
的用法示例。
在下文中一共展示了PeriodType.forFields方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: numberOfIntervalsBetweenDates
import org.joda.time.PeriodType; //导入方法依赖的package包/类
private long numberOfIntervalsBetweenDates(DateTime timestampStart, DateTime timestampEnd) {
Period period = new Period(timestampStart, timestampEnd,
PeriodType.forFields(new DurationFieldType[] { durationFieldType(intervalType) }));
return period.get(durationFieldType(intervalType));
}
示例2: DateDiscreteDomain
import org.joda.time.PeriodType; //导入方法依赖的package包/类
private DateDiscreteDomain(DurationFieldType iterationFieldType, DateTimeFieldType roundFloorFieldType) {
this.iterationFieldType = iterationFieldType;
this.roundFieldType = roundFloorFieldType;
this.periodType = PeriodType.forFields(new DurationFieldType[] { iterationFieldType });
}
示例3: inferTimeBucketSize
import org.joda.time.PeriodType; //导入方法依赖的package包/类
private String inferTimeBucketSize() {
Period period = new Period(start, end,
PeriodType.forFields(new DurationFieldType[]{DurationFieldType.weeks(), DurationFieldType.days(),
DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds()})
);
// try various sizes from smallest to largest until we find one that gives us number of buckets no more than we want
for(int i = 0; i <= 4; i++) {
int buckets;
String value;
switch (i) {
case 4: {
buckets = period.toStandardWeeks().getWeeks();
value = "1w";
break;
}
case 3: {
buckets = period.toStandardDays().getDays();
value = "1d";
break;
}
case 2: {
buckets = period.toStandardHours().getHours();
value = "1h";
break;
}
case 1: {
buckets = period.toStandardMinutes().getMinutes();
value = "1m";
break;
}
case 0: {
buckets = period.toStandardSeconds().getSeconds();
value = "1s";
break;
}
default: {
throw new RuntimeException("Shouldn't happen");
}
}
if(buckets < MAX_RECOMMENDED_BUCKETS) {
return value;
}
}
// we should never get here but just in case
return "1w";
}