Package javax.time.calendar

Examples of javax.time.calendar.OffsetDateTime$Rule


            if (dow != null) {
                date = date.with(DateAdjusters.nextOrCurrent(dow));
            }
        }
        LocalDateTime localDT = LocalDateTime.dateTime(date, time);
        OffsetDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
        return new ZoneOffsetTransition(transition, offsetAfter);
    }
View Full Code Here


        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();
View Full Code Here

        // 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

       
        // 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

        Period savings = Period.ZERO;
        if (firstWindow.fixedSavingAmount != null) {
            savings = firstWindow.fixedSavingAmount;
        }
        ZoneOffset firstWallOffset = deduplicate(standardOffset.plus(savings));
        OffsetDateTime windowStart = deduplicate(OffsetDateTime.dateTime(Year.MIN_YEAR, 1, 1, 0, 0, firstWallOffset));
       
        // build the windows and rules to interesting data
        for (TZWindow window : windowList) {
            // tidy the state
            window.tidy(windowStart.getYear());
           
            // calculate effective savings at the start of the window
            Period effectiveSavings = window.fixedSavingAmount;
            if (effectiveSavings == null) {
                // apply rules from this window together with the standard offset and
                // savings from the last window to find the savings amount applicable
                // at start of this window
                effectiveSavings = Period.ZERO;
                for (TZRule rule : window.ruleList) {
                    ZoneOffsetTransition trans = rule.toTransition(standardOffset, savings);
                    if (trans.getDateTime().isAfter(windowStart)) {
                        // previous savings amount found, which could be the savings amount at
                        // the instant that the window starts (hence isAfter)
                        break;
                    }
                    effectiveSavings = rule.savingAmount;
                }
            }
           
            // check if standard offset changed, and update it
            if (standardOffset.equals(window.standardOffset) == false) {
                standardOffset = deduplicate(window.standardOffset);
                standardOffsetList.add(deduplicate(windowStart.withOffsetSameInstant(standardOffset)));
            }
           
            // check if the start of the window represents a transition
            ZoneOffset effectiveWallOffset = deduplicate(standardOffset.plus(effectiveSavings));
            if (windowStart.getOffset().equals(effectiveWallOffset) == false) {
                ZoneOffsetTransition trans = new ZoneOffsetTransition(windowStart, effectiveWallOffset);
                transitionList.add(trans);
            }
            savings = effectiveSavings;
           
View Full Code Here

                }
            }
            date = deduplicate(date);
            LocalDateTime ldt = deduplicate(LocalDateTime.dateTime(date, time));
            ZoneOffset wallOffset = deduplicate(standardOffset.plus(savingsBefore));
            OffsetDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset));
            return new ZoneOffsetTransition(dt, offsetAfter);
        }
View Full Code Here

     * @param instant  the instant to find the offset information for, not null
     * @return the offset information, never null
     */
    public OffsetInfo getOffsetInfo(Instant instant) {
        ZoneOffset offset = getOffset(instant);
        OffsetDateTime odt = OffsetDateTime.fromInstant(instant, offset);
        return getOffsetInfo(odt.toLocalDateTime());
    }
View Full Code Here

        Period savings = Period.ZERO;
        if (firstWindow.fixedSavingAmount != null) {
            savings = firstWindow.fixedSavingAmount;
        }
        ZoneOffset firstWallOffset = deduplicate(standardOffset.plus(savings));
        OffsetDateTime windowStart = deduplicate(OffsetDateTime.of(Year.MIN_YEAR, 1, 1, 0, 0, firstWallOffset));
       
        // build the windows and rules to interesting data
        for (TZWindow window : windowList) {
            // tidy the state
            window.tidy(windowStart.getYear());
           
            // calculate effective savings at the start of the window
            Period effectiveSavings = window.fixedSavingAmount;
            if (effectiveSavings == null) {
                // apply rules from this window together with the standard offset and
                // savings from the last window to find the savings amount applicable
                // at start of this window
                effectiveSavings = Period.ZERO;
                for (TZRule rule : window.ruleList) {
                    ZoneOffsetTransition trans = rule.toTransition(standardOffset, savings);
                    if (trans.getDateTime().isAfter(windowStart)) {
                        // previous savings amount found, which could be the savings amount at
                        // the instant that the window starts (hence isAfter)
                        break;
                    }
                    effectiveSavings = rule.savingAmount;
                }
            }
           
            // check if standard offset changed, and update it
            if (standardOffset.equals(window.standardOffset) == false) {
                standardOffset = deduplicate(window.standardOffset);
                standardOffsetList.add(deduplicate(windowStart.withOffsetSameInstant(standardOffset)));
            }
           
            // check if the start of the window represents a transition
            ZoneOffset effectiveWallOffset = deduplicate(standardOffset.plus(effectiveSavings));
            if (windowStart.getOffset().equals(effectiveWallOffset) == false) {
                ZoneOffsetTransition trans = new ZoneOffsetTransition(windowStart, effectiveWallOffset);
                transitionList.add(trans);
            }
            savings = effectiveSavings;
           
View Full Code Here

                }
            }
            date = deduplicate(date);
            LocalDateTime ldt = deduplicate(LocalDateTime.from(date, time));
            ZoneOffset wallOffset = deduplicate(standardOffset.plus(savingsBefore));
            OffsetDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset));
            return new ZoneOffsetTransition(dt, offsetAfter);
        }
View Full Code Here

TOP

Related Classes of javax.time.calendar.OffsetDateTime$Rule

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.