List of usage examples for javax.xml.datatype Duration subtract
public Duration subtract(final Duration rhs)
From source file:Main.java
/** * Subtract one positive Duration from another, larger positive Duration. * @param d1 The larger positive duration * @param d2 The smaller positive duration * @return The difference/*from w ww. ja va2s . c o m*/ */ private static Duration subtractSmallerPositiveDurationFromLargerPositiveDuration(Duration d1, Duration d2) { BigDecimal s1 = fractionalSeconds(d1); BigDecimal s2 = fractionalSeconds(d2); BigDecimal extraSeconds = s1.subtract(s2); Duration strip1 = stripFractionalSeconds(d1); Duration strip2 = stripFractionalSeconds(d2); Duration stripResult = strip1.subtract(strip2); if (extraSeconds.compareTo(BigDecimal.ZERO) < 0) { stripResult = stripResult.subtract(DURATION_1_SECOND); extraSeconds = extraSeconds.add(BigDecimal.ONE); } BigDecimal properSeconds = BigDecimal.valueOf(stripResult.getSeconds()).add(extraSeconds); return FACTORY.newDuration(true, BigInteger.valueOf(stripResult.getYears()), BigInteger.valueOf(stripResult.getMonths()), BigInteger.valueOf(stripResult.getDays()), BigInteger.valueOf(stripResult.getHours()), BigInteger.valueOf(stripResult.getMinutes()), properSeconds); }