本文整理汇总了Java中com.ibm.icu.util.Calendar.clone方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.clone方法的具体用法?Java Calendar.clone怎么用?Java Calendar.clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.clone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dayDifference
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* @return the number of days in "until-now"
*/
private static int dayDifference(Calendar until) {
Calendar nowCal = (Calendar)until.clone();
Date nowDate = new Date(System.currentTimeMillis());
nowCal.clear();
nowCal.setTime(nowDate);
int dayDiff = until.get(Calendar.JULIAN_DAY) - nowCal.get(Calendar.JULIAN_DAY);
return dayDiff;
}
示例2: includesDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public boolean includesDate(Calendar cal) {
int dow = cal.get(Calendar.DAY_OF_WEEK);
if (dow == this.start || dow == this.end) {
return true;
}
Calendar compareCal = (Calendar) cal.clone();
while (compareCal.get(Calendar.DAY_OF_WEEK) != this.start) {
compareCal.add(Calendar.DAY_OF_MONTH, 1);
}
while (compareCal.get(Calendar.DAY_OF_WEEK) != this.end) {
if (compareCal.get(Calendar.DAY_OF_WEEK) == dow) {
return true;
}
compareCal.add(Calendar.DAY_OF_MONTH, 1);
}
return false;
}
示例3: testDuration
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public void testDuration() throws Exception {
Calendar now = Calendar.getInstance();
TimeDuration zeroDuration = TimeDuration.ZeroTimeDuration;
assertFalse("zero equals null", zeroDuration.equals(null));
Calendar newTime = (Calendar) now.clone();
zeroDuration.addToCalendar(newTime);
assertEquals("zero same calendar", now, newTime);
assertDurationFields("zero(same zero calendar)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", new TimeDuration(zero, zero), false, true);
assertDurationFields("zero(same now calendar)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", new TimeDuration(now, now), false, true);
assertDurationFields("zero(empty parse)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.parseDuration(""), false, true);
assertDurationFields("zero(zero parse)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.parseDuration("0:0:0:0:0:0:0"), false, true);
assertDurationFields("zero(from null number)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.fromNumber(null), false, true);
assertDurationFields("zero(from null number)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.fromNumber(null), false, true);
assertDuration("millisecond", 0, 0, 0, 0, 0, 0, 1);
assertDuration("second", 0, 0 ,0 ,0, 0, 1, 0);
assertDuration("minute", 0, 0, 0, 0, 1, 0, 0);
assertDuration("hour", 0, 0, 0, 1, 0, 0, 0);
assertDuration("day", 0, 0, 1, 0, 0, 0, 0);
assertDuration("month", 0, 1, 0, 0, 0, 0, 0);
assertDuration("year", 1, 0, 0, 0, 0, 0, 0);
Calendar start = new com.ibm.icu.util.GregorianCalendar(1967, 1, 1, 0, 0, 0);
start.set(Calendar.MILLISECOND, 0);
Calendar end = (Calendar) start.clone();
end.add(Calendar.MILLISECOND, 1);
end.add(Calendar.SECOND, 1);
end.add(Calendar.MINUTE, 1);
end.add(Calendar.HOUR_OF_DAY, 1);
end.add(Calendar.DAY_OF_MONTH, 1);
end.add(Calendar.MONTH, 1);
end.add(Calendar.YEAR, 1);
assertDurationFields("pre-epoch elapsed time", 1, 1, 1, 1, 1, 1, 1, "1:1:1:1:1:1:1", new TimeDuration(start, end), false, false);
}
示例4: 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;
}
示例5: isSubstitutionCandidate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) {
Calendar checkCal = (Calendar) cal.clone();
checkCal.add(Calendar.DAY_OF_MONTH, -1);
while (!includesDate(checkCal)) {
if (expressionToTest.includesDate(checkCal)) {
return true;
}
checkCal.add(Calendar.DAY_OF_MONTH, -1);
}
return false;
}
示例6: 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;
}
示例7: SimpleDateFormat
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Package-private constructor that allows a subclass to specify
* whether it supports fast formatting.
*
* TODO make this API public.
*/
SimpleDateFormat(String pattern, DateFormatSymbols formatData, Calendar calendar, ULocale locale,
boolean useFastFormat, String override) {
this(pattern, (DateFormatSymbols)formatData.clone(), (Calendar)calendar.clone(), null, locale, useFastFormat,override);
}