本文整理汇总了Java中com.ibm.icu.util.Calendar.after方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.after方法的具体用法?Java Calendar.after怎么用?Java Calendar.after使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.after方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: advanceCalendar
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private static int advanceCalendar(Calendar start, Calendar end, int units, int type) {
if (units >= 1) {
// Bother, the below needs explanation.
//
// If start has a day value of 31, and you add to the month,
// and the target month is not allowed to have 31 as the day
// value, then the day will be changed to a value that is in
// range. But, when the code needs to then subtract 1 from
// the month, because it has advanced to far, the day is *not*
// set back to the original value of 31.
//
// This bug can be triggered by having a duration of -1 day,
// then adding this duration to a calendar that represents 0
// milliseconds, then creating a new duration by using the 2
// Calendar constructor, with cal1 being 0, and cal2 being the
// new calendar that you added the duration to.
//
// To solve this problem, we make a temporary copy of the
// start calendar, and only modify it if we actually have to.
Calendar tmp = (Calendar) start.clone();
int tmpUnits = units;
tmp.add(type, tmpUnits);
while (tmp.after(end)) {
tmp.add(type, -1);
units--;
}
if (units != 0) {
start.add(type, units);
}
}
return units;
}
示例2: prepareCal
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
protected Calendar prepareCal(Calendar cal) {
// Performs a "sane" skip forward in time - avoids time consuming loops
// like incrementing every second from Jan 1 2000 until today
Calendar skip = (Calendar) cal.clone();
skip.setTime(this.start);
long deltaMillis = cal.getTimeInMillis() - this.start.getTime();
if (deltaMillis < 1000) {
return skip;
}
long divisor = deltaMillis;
if (this.freqType == Calendar.DAY_OF_MONTH) {
divisor = 86400000;
} else if (this.freqType == Calendar.HOUR) {
divisor = 3600000;
} else if (this.freqType == Calendar.MINUTE) {
divisor = 60000;
} else if (this.freqType == Calendar.SECOND) {
divisor = 1000;
} else {
return skip;
}
long units = deltaMillis / divisor;
units -= units % this.freqCount;
skip.add(this.freqType, (int)units);
while (skip.after(cal)) {
skip.add(this.freqType, -this.freqCount);
}
return skip;
}