Examples of OffsetDateTime


Examples of java.time.OffsetDateTime

            } else if (type == ZonedDateTime.class) {
                ZonedDateTime zonedDateTime = ZonedDateTime.parse(text);

                return (T) zonedDateTime;
            } else if (type == OffsetDateTime.class) {
                OffsetDateTime offsetDateTime = OffsetDateTime.parse(text);

                return (T) offsetDateTime;
            } else if (type == OffsetTime.class) {
                OffsetTime offsetTime = OffsetTime.parse(text);
               
View Full Code Here

Examples of java.time.OffsetDateTime

    @Test(dependsOnMethods = "createSchema")
    public void all_not_null() throws Exception {
        try (PersistenceSession session = persistenceManager.createSession()) {
            JavatimeConvertEntity inst = new JavatimeConvertEntity();
            inst.setId(99);
            OffsetDateTime dt = OffsetDateTime.ofInstant(new Date().toInstant(), ZoneOffset.of("+0200"));
            LocalDateTime ldt = dt.toLocalDateTime();
            LocalDate ld = ldt.toLocalDate();
            inst.setDateTime(dt);
            inst.setLocalDate(ld);
            inst.setLocalDateTime(ldt);
            session.insert(inst);
View Full Code Here

Examples of java.time.OffsetDateTime

    assertTrue( constraint.isValid( null, null ), "null fails validation." );

    // Test allowed zone offsets (-18 to +18) with 1 hour increments
    for ( int i = -18; i <= 18; i++ ) {
      ZoneOffset offset = ZoneOffset.ofHours( i );
      OffsetDateTime future = OffsetDateTime.now( offset ).plusHours( 1 );
      OffsetDateTime past = OffsetDateTime.now( offset ).minusHours( 1 );
      assertTrue( constraint.isValid( past, null ), "Past OffsetDateTime '" + past + "' fails validation.");
      assertFalse( constraint.isValid( future, null ), "Future OffsetDateTime '" + future + "' validated as past.");
    }
  }
View Full Code Here

Examples of java.time.OffsetDateTime

    assertTrue( constraint.isValid( null, null ), "null fails validation." );

    // Test allowed zone offsets (-18 to +18) with 1 hour increments
    for ( int i = -18; i <= 18; i++ ) {
      ZoneOffset offset = ZoneOffset.ofHours( i );
      OffsetDateTime future = OffsetDateTime.now( offset ).plusHours( 1 );
      OffsetDateTime past = OffsetDateTime.now( offset ).minusHours( 1 );
      assertTrue( constraint.isValid( future, null ), "Future OffsetDateTime '" + future + "' fails validation.");
      assertFalse( constraint.isValid( past, null ), "Past OffsetDateTime '" + past + "' validated as future.");
    }
  }
View Full Code Here

Examples of javax.time.calendar.OffsetDateTime

            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

Examples of javax.time.calendar.OffsetDateTime

        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

Examples of javax.time.calendar.OffsetDateTime

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

Examples of javax.time.calendar.OffsetDateTime

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

Examples of javax.time.calendar.OffsetDateTime

    @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

Examples of javax.time.calendar.OffsetDateTime

        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
TOP
Copyright © 2018 www.massapi.com. 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.