java.time.Period#isNegative ( )源码实例Demo

下面列出了java.time.Period#isNegative ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdmn   文件: DefaultDurationLib.java
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);
}
 
源代码2 项目: jdmn   文件: DefaultDurationLib.java
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);
}
 
源代码3 项目: vertexium   文件: CypherDuration.java
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);
}
 
源代码4 项目: groovy   文件: DateTimeExtensions.java
/**
 * 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()));
}