public Duration newDurationDayTime()

in jaxp-api-1.4/src/main/java/javax/xml/datatype/DatatypeFactory.java [372:423]


    public Duration newDurationDayTime(final long durationInMilliseconds) {
        long _durationInMilliseconds = durationInMilliseconds;
        if (_durationInMilliseconds == 0) {
            return newDuration(true, DatatypeConstants.FIELD_UNDEFINED,
                    DatatypeConstants.FIELD_UNDEFINED, 0, 0, 0, 0);
        }
        boolean tooLong = false;
        final boolean isPositive;
        if (_durationInMilliseconds < 0) {
            isPositive = false;
            if (_durationInMilliseconds == Long.MIN_VALUE) {
                _durationInMilliseconds++;
                tooLong = true;
            }
            _durationInMilliseconds *= -1;
        }
        else {
            isPositive = true;
        }

        long val = _durationInMilliseconds;
        int milliseconds = (int) (val % 60000L); // 60000 milliseconds per minute
        if (tooLong) {
            ++milliseconds;
        }
        if (milliseconds % 1000 == 0) {
            int seconds = milliseconds / 1000;
            val = val / 60000L;
            int minutes = (int) (val % 60L); // 60 minutes per hour
            val = val / 60L;
            int hours = (int) (val % 24L); // 24 hours per day
            long days = val / 24L;
            if (days <= ((long) Integer.MAX_VALUE)) {
                return newDuration(isPositive, DatatypeConstants.FIELD_UNDEFINED,
                        DatatypeConstants.FIELD_UNDEFINED, (int) days, hours, minutes, seconds);
            }
            else {
                return newDuration(isPositive, null, null,
                        BigInteger.valueOf(days), BigInteger.valueOf(hours),
                        BigInteger.valueOf(minutes), BigDecimal.valueOf(milliseconds, 3));
            }
        }

        BigDecimal seconds = BigDecimal.valueOf(milliseconds, 3);
        val = val / 60000L;
        BigInteger minutes = BigInteger.valueOf(val % 60L); // 60 minutes per hour
        val = val / 60L;
        BigInteger hours = BigInteger.valueOf(val % 24L); // 24 hours per day
        val = val / 24L;
        BigInteger days = BigInteger.valueOf(val);
        return newDuration(isPositive, null, null, days, hours, minutes, seconds);
    }