本文整理汇总了Java中org.ofbiz.base.util.TimeDuration类的典型用法代码示例。如果您正苦于以下问题:Java TimeDuration类的具体用法?Java TimeDuration怎么用?Java TimeDuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeDuration类属于org.ofbiz.base.util包,在下文中一共展示了TimeDuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertDurationFields
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
private static void assertDurationFields(String label, int years, int months, int days, int hours, int minutes, int seconds, int milliseconds, String string, TimeDuration duration, boolean isNegative, boolean isZero) {
assertEquals(label + ".years()", years, duration.years());
assertEquals(label + ".months()", months, duration.months());
assertEquals(label + ".days()", days, duration.days());
assertEquals(label + ".hours()", hours, duration.hours());
assertEquals(label + ".minutes()", minutes, duration.minutes());
assertEquals(label + ".seconds()", seconds, duration.seconds());
assertEquals(label + ".milliseconds()", milliseconds, duration.milliseconds());
assertEquals(label + ".isNegative()", isNegative, duration.isNegative());
assertEquals(label + ".toString()", string, duration.toString());
assertEquals(label + ".equals(from/to long)", duration, TimeDuration.fromLong(TimeDuration.toLong(duration)));
assertEquals(label + ".equals(from/to number)", duration, TimeDuration.fromNumber(TimeDuration.toLong(duration)));
assertEquals(label + ".isZero", isZero, duration.isZero());
if (isZero) {
assertEquals(label + ".compareTo(zero) == 0", 0, doCompare(TimeDuration.ZeroTimeDuration, duration));
assertEquals(label + ".compareTo(zero) == 0", 0, doCompare(duration, TimeDuration.ZeroTimeDuration));
} else {
assertNotSame(label + ".compareTo(zero) != 0", 0, doCompare(TimeDuration.ZeroTimeDuration, duration));
assertNotSame(label + ".compareTo(zero) != 0", 0, doCompare(duration, TimeDuration.ZeroTimeDuration));
}
}
示例2: fromDuration
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
protected static Double fromDuration(PropertyList propertyList) {
Duration iCalObj = (Duration) propertyList.getProperty(Duration.DURATION);
if (iCalObj == null) {
return null;
}
Dur dur = iCalObj.getDuration();
TimeDuration td = new TimeDuration(0, 0, (dur.getWeeks() * 7) + dur.getDays(), dur.getHours(), dur.getMinutes(), dur.getSeconds(), 0);
return new Double(TimeDuration.toLong(td));
}
示例3: toDuration
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
protected static Duration toDuration(Double javaObj) {
if (javaObj == null) {
return null;
}
TimeDuration duration = TimeDuration.fromNumber(javaObj);
return new Duration(new Dur(duration.days(), duration.hours(), duration.minutes(), duration.seconds()));
}
示例4: convert
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public TimeDuration convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
if (!obj.contains(":")) {
// Encoded duration
try {
NumberFormat nf = NumberFormat.getNumberInstance(locale);
nf.setMaximumFractionDigits(0);
Number number = nf.parse(obj);
return TimeDuration.fromNumber(number);
} catch (ParseException e) {
throw new ConversionException(e);
}
}
return convert(obj);
}
示例5: assertDuration
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public static void assertDuration(String label, int years, int months, int days, int hours, int minutes, int seconds, int milliseconds) {
TimeDuration lastString = null;
Calendar right = (Calendar) zero.clone();
for (int i = 1; i < 12; i++) {
lastString = assertDurationLoop(i + " " + label, right, i * years, i * months, i * days, i * hours, i * minutes, i * seconds, i * milliseconds, lastString, false);
}
lastString = null;
for (int i = -2; i > -12; i--) {
lastString = assertDurationLoop(i + " " + label, right, i * years, i * months, i * days, i * hours, i * minutes, i * seconds, i * milliseconds, lastString, true);
}
}
示例6: testDuration
import org.ofbiz.base.util.TimeDuration; //导入依赖的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);
}
示例7: DurationToBigDecimal
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToBigDecimal() {
super(TimeDuration.class, java.math.BigDecimal.class);
}
示例8: DurationToDouble
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToDouble() {
super(TimeDuration.class, Double.class);
}
示例9: DurationToFloat
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToFloat() {
super(TimeDuration.class, Float.class);
}
示例10: DurationToList
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToList() {
super(TimeDuration.class);
}
示例11: DurationToLong
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToLong() {
super(TimeDuration.class, Long.class);
}
示例12: DurationToSet
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToSet() {
super(TimeDuration.class);
}
示例13: DurationToString
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public DurationToString() {
super(TimeDuration.class, String.class);
}
示例14: NumberToDuration
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public NumberToDuration() {
super(Number.class, TimeDuration.class);
}
示例15: StringToDuration
import org.ofbiz.base.util.TimeDuration; //导入依赖的package包/类
public StringToDuration() {
super(String.class, TimeDuration.class);
}