Package javax.time.period

Examples of javax.time.period.Period


     * @param periodProvider  the period to add, not null
     * @return a new updated ZoneOffset, never null
     * @throws IllegalArgumentException if the offset is not in the required range
     */
    public ZoneOffset plus(PeriodProvider periodProvider) {
        Period otherPeriod = Period.period(periodProvider);
        otherPeriod = Period.hoursMinutesSeconds(otherPeriod.getHours(), otherPeriod.getMinutes(), otherPeriod.getSeconds());
        Period thisPeriod = toPeriod();
        Period combined = thisPeriod.plus(otherPeriod).normalized();
        return zoneOffset(combined.getHours(), combined.getMinutes(), combined.getSeconds());
    }
View Full Code Here


     * @param periodProvider  the period to add, not null
     * @return a new updated YearMonth, never null
     * @throws CalendricalException if the result exceeds the supported date range
     */
    public YearMonth plus(PeriodProvider periodProvider) {
        Period period = Period.period(periodProvider);
        return plusYears(period.getYears()).plusMonths(period.getMonths());
    }
View Full Code Here

     * @param periodProvider  the period to subtract, not null
     * @return a new updated YearMonth, never null
     * @throws CalendricalException if the result exceeds the supported date range
     */
    public YearMonth minus(PeriodProvider periodProvider) {
        Period period = Period.period(periodProvider);
        return minusYears(period.getYears()).minusMonths(period.getMonths());
    }
View Full Code Here

     *
     * @param periodProvider  the period to add, not null
     * @return a new updated LocalTime, never null
     */
    public LocalTime plus(PeriodProvider periodProvider) {
        Period period = Period.period(periodProvider);
        // safe from overflow
        long totalNanos = period.getHours() * NANOS_PER_HOUR +
                period.getMinutes() * NANOS_PER_MINUTE +
                period.getSeconds() * NANOS_PER_SECOND;
        return plusNanos(totalNanos).plusNanos(period.getNanos());
    }
View Full Code Here

     *
     * @param periodProvider  the period to subtract, not null
     * @return a new updated LocalTime, never null
     */
    public LocalTime minus(PeriodProvider periodProvider) {
        Period period = Period.period(periodProvider);
        // safe from overflow
        long totalNanos = period.getHours() * NANOS_PER_HOUR +
                period.getMinutes() * NANOS_PER_MINUTE +
                period.getSeconds() * NANOS_PER_SECOND;
        return minusNanos(totalNanos).minusNanos(period.getNanos());
    }
View Full Code Here

     *
     * @param periodProvider  the period to add, not null
     * @return an Overflow instance with the resulting time and overflow, never null
     */
    Overflow plusWithOverflow(PeriodProvider periodProvider) {
        Period period = Period.period(periodProvider);
        // safe from overflow
        long totalNanos = period.getHours() * NANOS_PER_HOUR +
                period.getMinutes() * NANOS_PER_MINUTE +
                period.getSeconds() * NANOS_PER_SECOND;
        Overflow overflow = plusNanosWithOverflow(totalNanos);
        if (period.getNanos() == 0) {
            return overflow;
        }
        Overflow overflow2 = overflow.getResultTime().plusNanosWithOverflow(period.getNanos());
        return new Overflow(overflow2.getResultTime(), overflow.getOverflowDays() + overflow2.getOverflowDays());
    }
View Full Code Here

     *
     * @param periodProvider  the period to subtract, not null
     * @return an Overflow instance with the resulting time and overflow, never null
     */
    Overflow minusWithOverflow(PeriodProvider periodProvider) {
        Period period = Period.period(periodProvider);
        // safe from overflow
        long totalNanos = period.getHours() * NANOS_PER_HOUR +
                period.getMinutes() * NANOS_PER_MINUTE +
                period.getSeconds() * NANOS_PER_SECOND;
        Overflow overflow = minusNanosWithOverflow(totalNanos);
        if (period.getNanos() == 0) {
            return overflow;
        }
        Overflow overflow2 = overflow.getResultTime().minusNanosWithOverflow(period.getNanos());
        return new Overflow(overflow2.getResultTime(), overflow.getOverflowDays() + overflow2.getOverflowDays());
    }
View Full Code Here

     * @param periodProvider  the period to subtract, not null
     * @return a {@code LocalDateTime} with the period subtracted, never null
     * @throws CalendricalException if the result exceeds the supported date range
     */
    public LocalDateTime minus(PeriodProvider periodProvider) {
        Period period = Period.from(periodProvider)// TODO: overflows long->int PeriodFields
        // TODO: correct algorithm
        LocalDate date = this.date.minusYears(period.getYears())
                .minusMonths(period.getMonths()).minusDays(period.getDays());
        Overflow overflow = this.time.minusWithOverflow(
                period.getHours(), period.getMinutes(), period.getSeconds(), period.getNanos());
        LocalDateTime result = overflow.toLocalDateTime(date);
        return (result.equals(this) ? this : result);
    }
View Full Code Here

     * @param periodProvider  the period to add, not null
     * @return a new updated ZoneOffset, never null
     * @throws IllegalArgumentException if the offset is not in the required range
     */
    public ZoneOffset plus(PeriodProvider periodProvider) {
        Period otherPeriod = Period.from(periodProvider);
        otherPeriod = Period.hoursMinutesSeconds(otherPeriod.getHours(), otherPeriod.getMinutes(), otherPeriod.getSeconds());
        Period thisPeriod = toPeriod();
        Period combined = thisPeriod.plus(otherPeriod).normalized();
        return hoursMinutesSeconds(combined.getHours(), combined.getMinutes(), combined.getSeconds());
    }
View Full Code Here

     * @return a {@code LocalDateTime} with the period added, never null
     * @throws CalendricalException if the provider contains time period units
     * @throws CalendricalException if the result exceeds the supported date range
     */
    public LocalDate plus(PeriodProvider periodProvider) {
        Period period = Period.from(periodProvider)// TODO: overflows long->int PeriodFields
        if ((period.getHours() | period.getMinutes() | period.getSeconds() | period.getNanos()) != 0) {
            throw new CalendricalException("Unable to add to date as the period contains time units");
        }
        // TODO: calculate in one go - 31st Mar plus P1M-1D should be 30th Apr
        return plusYears(period.getYears()).plusMonths(period.getMonths()).plusDays(period.getDays());
    }
View Full Code Here

TOP

Related Classes of javax.time.period.Period

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.