下面列出了java.time.Period#isNegative ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private javax.xml.datatype.Duration toYearsMonthDuration(DatatypeFactory datatypeFactory, LocalDate date1, LocalDate date2) {
Period between = Period.between(date2, date1);
int years = between.getYears();
int months = between.getMonths();
if (between.isNegative()) {
years = - years;
months = - months;
}
return datatypeFactory.newDurationYearMonth(!between.isNegative(), years, months);
}
private Duration toYearsMonthDuration(DatatypeFactory datatypeFactory, LocalDate date1, LocalDate date2) {
Period between = Period.between(date2, date1);
int years = between.getYears();
int months = between.getMonths();
if (between.isNegative()) {
years = - years;
months = - months;
}
return datatypeFactory.newDurationYearMonth(!between.isNegative(), years, months);
}
public CypherDuration(Period period, Duration duration) {
this.negative = (period.isNegative() || duration.isNegative());
if (period.isNegative()) {
period = period.negated();
}
if (duration.isNegative()) {
duration = duration.negated();
}
this.nanos = ((duration.getSeconds() * NANOS_IN_SECOND) + duration.getNano()) % NANOS_IN_DAY;
this.period = period.minusDays(this.nanos > 0 ? 1 : 0);
}
/**
* Supports the unary plus operator; returns a {@link java.time.Period} with all unit values positive.
* For example, a period of "2 years, -3 months, and -4 days" would result in a period of
* "2 years, 3 months, and 4 days." No normalization is performed.
*
* @param self a Period
* @return a positive Period
* @since 2.5.0
*/
public static Period positive(final Period self) {
return !self.isNegative() ? self : self.withDays(Math.abs(self.getDays()))
.withMonths(Math.abs(self.getMonths()))
.withYears(Math.abs(self.getYears()));
}