Package javax.time

Examples of javax.time.Instant


    //-----------------------------------------------------------------------
    /** {@inheritDoc} */
    @Override
    public ZoneOffset getOffset(InstantProvider instantProvider) {
        Instant instant = Instant.instant(instantProvider);
        long epochSecs = instant.getEpochSeconds();
       
        // check if using last rules
        if (lastRules.length > 0 &&
                epochSecs > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
            OffsetDateTime dt = OffsetDateTime.fromInstant(instant, wallOffsets[wallOffsets.length - 1]);
            ZoneOffsetTransition[] transArray = findTransitionArray(dt.toYear());
            ZoneOffsetTransition trans = null;
            for (int i = 0; i < transArray.length; i++) {
                trans = transArray[i];
                if (instant.isBefore(trans.getInstant())) {
                    return trans.getOffsetBefore();
                }
            }
            return trans.getOffsetAfter();
        }
View Full Code Here


    //-----------------------------------------------------------------------
    /** {@inheritDoc} */
    @Override
    public ZoneOffset getStandardOffset(InstantProvider instantProvider) {
        Instant instant = Instant.instant(instantProvider);
        long epochSecs = instant.getEpochSeconds();
        int index  = Arrays.binarySearch(standardTransitions, epochSecs);
        if (index < 0) {
            // switch negative insert position to start of matched range
            index = -index - 2;
        }
View Full Code Here

     * @param instantProvider  the instant to get the next transition after, not null
     * @return the next transition after the specified instant, null if this is after the last transition
     */
    @Override
    public ZoneOffsetTransition nextTransition(InstantProvider instantProvider) {
        Instant instant = Instant.instant(instantProvider);
        long epochSecs = instant.getEpochSeconds();
       
        // check if using last rules
        if (epochSecs >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
            if (lastRules.length == 0) {
                return null;
            }
            OffsetDateTime dt = OffsetDateTime.fromInstant(instant, wallOffsets[wallOffsets.length - 1]);
            for (Year year = dt.toYear(); true; year = year.next()) {
                ZoneOffsetTransition[] transArray = findTransitionArray(year);
                for (ZoneOffsetTransition trans : transArray) {
                    if (instant.isBefore(trans.getInstant())) {
                        return trans;
                    }
                }
                if (year.getValue() == Year.MAX_YEAR) {
                    return null;
                }
            }
        }
       
        // using historic rules
        int index  = Arrays.binarySearch(savingsInstantTransitions, epochSecs);
        if (index < 0) {
            index = -index - 1// switched value is the next transition
        } else {
            index += 1// exact match, so need to add one to get the next
        }
        Instant transitionInstant = Instant.instant(savingsInstantTransitions[index]);
        OffsetDateTime trans = OffsetDateTime.fromInstant(transitionInstant, wallOffsets[index]);
        return createTransition(trans, wallOffsets[index + 1]);
    }
View Full Code Here

     * @param instantProvider  the instant to get the previous transition after, not null
     * @return the previous transition after the specified instant, null if this is before the first transition
     */
    @Override
    public ZoneOffsetTransition previousTransition(InstantProvider instantProvider) {
        Instant instant = Instant.instant(instantProvider);
        long epochSecs = instant.getEpochSeconds();
        if (instant.getNanoOfSecond() > 0 && epochSecs < Long.MAX_VALUE) {
            epochSecs += 1// allow rest of method to only use seconds
        }
       
        // check if using last rules
        long lastHistoric = savingsInstantTransitions[savingsInstantTransitions.length - 1];
        if (lastRules.length > 0 && epochSecs > lastHistoric) {
            ZoneOffset lastHistoricOffset = wallOffsets[wallOffsets.length - 1];
            OffsetDateTime dt = OffsetDateTime.fromInstant(instant, lastHistoricOffset);
            OffsetDateTime lastHistoricDT = OffsetDateTime.fromInstant(Instant.instant(lastHistoric), lastHistoricOffset);
            for (Year year = dt.toYear(); year.getValue() > lastHistoricDT.getYear(); year = year.previous()) {
                ZoneOffsetTransition[] transArray = findTransitionArray(year);
                for (int i = transArray.length - 1; i >= 0; i--) {
                    if (instant.isAfter(transArray[i].getInstant())) {
                        return transArray[i];
                    }
                }
            }
        }
       
        // using historic rules
        int index  = Arrays.binarySearch(savingsInstantTransitions, epochSecs);
        if (index < 0) {
            index = -index - 1;
        }
        if (index <= 0) {
            return null;
        }
        Instant transitionInstant = Instant.instant(savingsInstantTransitions[index - 1]);
        OffsetDateTime trans = OffsetDateTime.fromInstant(transitionInstant, wallOffsets[index - 1]);
        return createTransition(trans, wallOffsets[index]);
    }
View Full Code Here

     */
    @Override
    public List<ZoneOffsetTransition> getTransitions() {
        List<ZoneOffsetTransition> list = new ArrayList<ZoneOffsetTransition>();
        for (int i = 0; i < savingsInstantTransitions.length; i++) {
            Instant instant = Instant.instant(savingsInstantTransitions[i]);
            OffsetDateTime trans = OffsetDateTime.fromInstant(instant, wallOffsets[i]);
            list.add(createTransition(trans, wallOffsets[i + 1]));
        }
        return list;
    }
View Full Code Here

     * @param zone  the time zone, not null
     * @return the zoned date-time, never null
     * @throws CalendricalException if the result exceeds the supported range
     */
    public static ZonedDateTime fromInstant(InstantProvider instantProvider, TimeZone zone) {
        Instant instant = Instant.instant(instantProvider);
        ISOChronology.checkNotNull(zone, "TimeZone must not be null");
        ZoneRules rules = zone.getRules()// latest rules version
        OffsetDateTime offsetDT = OffsetDateTime.fromInstant(instant, rules.getOffset(instant));
        return new ZonedDateTime(offsetDT, zone);
    }
View Full Code Here

     *
     * @param instantProvider  the instant to find the offset information for, not null
     * @return the difference between the standard and actual offset, never null
     */
    public Period getDaylightSavings(InstantProvider instantProvider) {
        Instant instant = Instant.instant(instantProvider);
        ZoneOffset standardOffset = getStandardOffset(instant);
        ZoneOffset actualOffset = getOffset(instant);
        return actualOffset.toPeriod().minus(standardOffset.toPeriod()).normalized();
    }
View Full Code Here

     *
     * @param instantProvider  the instant to find the offset information for, not null
     * @return the difference between the standard and actual offset, never null
     */
    public Period getDaylightSavings(InstantProvider instantProvider) {
        Instant instant = Instant.from(instantProvider);
        ZoneOffset standardOffset = getStandardOffset(instant);
        ZoneOffset actualOffset = getOffset(instant);
        return actualOffset.toPeriod().minus(standardOffset.toPeriod()).normalized();
    }
View Full Code Here

     */
    @Override
    public List<ZoneOffsetTransition> getTransitions() {
        List<ZoneOffsetTransition> list = new ArrayList<ZoneOffsetTransition>();
        for (int i = 0; i < savingsInstantTransitions.length; i++) {
            Instant instant = Instant.seconds(savingsInstantTransitions[i]);
            OffsetDateTime trans = OffsetDateTime.fromInstant(instant, wallOffsets[i]);
            list.add(createTransition(trans, wallOffsets[i + 1]));
        }
        return list;
    }
View Full Code Here

    //-----------------------------------------------------------------------
    /** {@inheritDoc} */
    @Override
    public ZoneOffset getOffset(InstantProvider instantProvider) {
        Instant instant = Instant.from(instantProvider);
        long epochSecs = instant.getEpochSeconds();
       
        // check if using last rules
        if (lastRules.length > 0 &&
                epochSecs > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
            OffsetDateTime dt = OffsetDateTime.fromInstant(instant, wallOffsets[wallOffsets.length - 1]);
            ZoneOffsetTransition[] transArray = findTransitionArray(dt.toYear());
            ZoneOffsetTransition trans = null;
            for (int i = 0; i < transArray.length; i++) {
                trans = transArray[i];
                if (instant.isBefore(trans.getInstant())) {
                    return trans.getOffsetBefore();
                }
            }
            return trans.getOffsetAfter();
        }
View Full Code Here

TOP

Related Classes of javax.time.Instant

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.