Package java.time

Examples of java.time.ZoneOffset


     * @return the created object, not null
     * @throws IOException if an error occurs
     */
    static ZoneOffsetTransition readExternal(DataInput in) throws IOException {
        long epochSecond = Ser.readEpochSec(in);
        ZoneOffset before = Ser.readOffset(in);
        ZoneOffset after = Ser.readOffset(in);
        if (before.equals(after)) {
            throw new IllegalArgumentException("Offsets must not be equal");
        }
        return new ZoneOffsetTransition(epochSecond, before, after);
    }
View Full Code Here


        TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12];
        int stdByte = (data & (255 << 4)) >>> 4;
        int beforeByte = (data & (3 << 2)) >>> 2;
        int afterByte = (data & 3);
        LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0));
        ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900));
        ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800));
        ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800));
        return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after);
    }
View Full Code Here

            if (zone != null) {
                resolveInstantFields0(zone);
            } else {
                Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
                if (offsetSecs != null) {
                    ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
                    resolveInstantFields0(offset);
                }
            }
        }
    }
View Full Code Here

                long instant = date.atTime(time).atZone(zone).getLong(ChronoField.INSTANT_SECONDS);
                fieldValues.put(INSTANT_SECONDS, instant);
            } else {
                Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
                if (offsetSecs != null) {
                    ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
                    long instant = date.atTime(time).atZone(offset).getLong(ChronoField.INSTANT_SECONDS);
                    fieldValues.put(INSTANT_SECONDS, instant);
                }
            }
        }
View Full Code Here

    @Override public OffsetDateTime toJava(Object... value) {
        Date dt = (Date) value[0];
        if (dt == null) {
            return null;
        }
        ZoneOffset zone = ZoneOffset.of((String) value[1]);
        LocalDateTime ldt = LocalDateTime.ofInstant(dt.toInstant(), zone);
        return OffsetDateTime.of(ldt, zone);
    }
View Full Code Here

  public void testIsValid() {
    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

  public void testIsValid() {
    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

    // daylight saving to ensure this test-case is stable)
    final ZoneId zoneId = ZoneId.of("Africa/Addis_Ababa");
    final ZonedDateTime zonedDateTime = ZonedDateTime.of(2014, Month.AUGUST.getValue(), 30, 21, 40, 20, 0, zoneId);

    // Use ZoneOffset to return the fixed offset of a zoned date/time from UTC
    final ZoneOffset zoneOffset = zonedDateTime.getOffset();
    int threeHoursInSeconds = 3 * 60 * 60;
    assertThat(zoneOffset.getTotalSeconds(), is(threeHoursInSeconds));
  }
View Full Code Here

TOP

Related Classes of java.time.ZoneOffset

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.