Example usage for javax.xml.datatype DatatypeConstants MINUTES

List of usage examples for javax.xml.datatype DatatypeConstants MINUTES

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConstants MINUTES.

Prototype

Field MINUTES

To view the source code for javax.xml.datatype DatatypeConstants MINUTES.

Click Source Link

Document

A constant that represents the minutes field.

Usage

From source file:Main.java

private static javax.xml.datatype.Duration normaliseSeconds(javax.xml.datatype.Duration duration) {
    BigInteger years = (BigInteger) duration.getField(DatatypeConstants.YEARS);
    BigInteger months = (BigInteger) duration.getField(DatatypeConstants.MONTHS);
    BigInteger days = (BigInteger) duration.getField(DatatypeConstants.DAYS);

    BigInteger hours = (BigInteger) duration.getField(DatatypeConstants.HOURS);
    BigInteger minutes = (BigInteger) duration.getField(DatatypeConstants.MINUTES);
    BigDecimal seconds = (BigDecimal) duration.getField(DatatypeConstants.SECONDS);

    seconds = seconds.stripTrailingZeros();

    boolean positive = duration.getSign() >= 0;

    return FACTORY.newDuration(positive, years, months, days, hours, minutes, seconds);
}

From source file:Main.java

/**
 * Java runtime 1.5 is inconsistent with its handling of days in Duration objects.
 * @param duration A duration object to be normalised
 * @return A day-normalised duration, i.e. all years and months converted to days,
 * e.g. 1Y 3M 3D => 458 days/*  w w w  . ja va2  s .c o m*/
 */
private static javax.xml.datatype.Duration normaliseDays(javax.xml.datatype.Duration duration) {
    final long DAYS_PER_MONTH = 30;
    final long DAYS_PER_YEAR = 365;

    BigInteger days = (BigInteger) duration.getField(DatatypeConstants.DAYS);
    BigInteger months = (BigInteger) duration.getField(DatatypeConstants.MONTHS);
    BigInteger years = (BigInteger) duration.getField(DatatypeConstants.YEARS);

    BigInteger normalisedDays = years.multiply(BigInteger.valueOf(DAYS_PER_YEAR));
    normalisedDays = normalisedDays.add(months.multiply(BigInteger.valueOf(DAYS_PER_MONTH)));
    normalisedDays = normalisedDays.add(days);

    BigInteger hours = (BigInteger) duration.getField(DatatypeConstants.HOURS);
    BigInteger minutes = (BigInteger) duration.getField(DatatypeConstants.MINUTES);
    BigDecimal seconds = (BigDecimal) duration.getField(DatatypeConstants.SECONDS);

    boolean positive = duration.getSign() >= 0;

    return FACTORY.newDuration(positive, BigInteger.ZERO, BigInteger.ZERO, normalisedDays, hours, minutes,
            seconds);
}