Examples of ZoneId


Examples of java.time.ZoneId

  public void testIsValid() {
    assertTrue( constraint.isValid( null, null ), "null fails validation." );

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

Examples of java.time.ZoneId

  public void testIsValid() {
    assertTrue( constraint.isValid( null, null ), "null fails validation." );

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

Examples of java.time.ZoneId

        Instant instant = clock.instant();
        Date legacyDate = Date.from(instant);


        ZoneId zone1 = ZoneId.of("Europe/Berlin");
        ZoneId zone2 = ZoneId.of("Brazil/East");

        System.out.println(zone1.getRules());
        System.out.println(zone2.getRules());

        // time
        LocalTime now1 = LocalTime.now(zone1);
        LocalTime now2 = LocalTime.now(zone2);
View Full Code Here

Examples of java.time.ZoneId

   */
  @Test
  public void testZoneIdRegionAndFixedOffset() {
    // Create zoned date/time using ZoneId to parse an IANA area/region format TZ ID (use one that doesn't vary with
    // 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;
 
View Full Code Here

Examples of org.threeten.bp.ZoneId

        MonthDay.now((ZoneId) null);
    }

    @Test
    public void now_ZoneId() {
        ZoneId zone = ZoneId.of("UTC+01:02:03");
        MonthDay expected = MonthDay.now(Clock.system(zone));
        MonthDay test = MonthDay.now(zone);
        for (int i = 0; i < 100; i++) {
            if (expected.equals(test)) {
                return;
View Full Code Here

Examples of org.threeten.bp.ZoneId

        Year.now((ZoneId) null);
    }

    @Test
    public void now_ZoneId() {
        ZoneId zone = ZoneId.of("UTC+01:02:03");
        Year expected = Year.now(Clock.system(zone));
        Year test = Year.now(zone);
        for (int i = 0; i < 100; i++) {
            if (expected.equals(test)) {
                return;
View Full Code Here

Examples of org.threeten.bp.ZoneId

        YearMonth.now((ZoneId) null);
    }

    @Test
    public void now_ZoneId() {
        ZoneId zone = ZoneId.of("UTC+01:02:03");
        YearMonth expected = YearMonth.now(Clock.system(zone));
        YearMonth test = YearMonth.now(zone);
        for (int i = 0; i < 100; i++) {
            if (expected.equals(test)) {
                return;
View Full Code Here

Examples of org.threeten.bp.ZoneId

    }

    private static TemporalAccessor adjust(final TemporalAccessor temporal, DateTimeFormatter formatter) {
        // normal case first
        Chronology overrideChrono = formatter.getChronology();
        ZoneId overrideZone = formatter.getZone();
        if (overrideChrono == null && overrideZone == null) {
            return temporal;
        }

        // ensure minimal change
        Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
        ZoneId temporalZone = temporal.query(TemporalQueries.zoneId());
        if (Jdk8Methods.equals(temporalChrono, overrideChrono)) {
            overrideChrono = null;
        }
        if (Jdk8Methods.equals(temporalZone, overrideZone)) {
            overrideZone = null;
        }
        if (overrideChrono == null && overrideZone == null) {
            return temporal;
        }
        final Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono);
        final ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone);
       
        // use overrides
        if (overrideZone != null) {
            // handle instant
            if (temporal.isSupported(INSTANT_SECONDS)) {
                Chronology chrono = (effectiveChrono != null ? effectiveChrono : IsoChronology.INSTANCE);
                return chrono.zonedDateTime(Instant.from(temporal), overrideZone);
            }
            // block changing zone on OffsetTime, and similar problem cases
            ZoneId normalizedOffset = overrideZone.normalized();
            ZoneOffset temporalOffset = temporal.query(TemporalQueries.offset());
            if (normalizedOffset instanceof ZoneOffset && temporalOffset != null && normalizedOffset.equals(temporalOffset) == false) {
                throw new DateTimeException("Invalid override zone for temporal: " + overrideZone + " " + temporal);
            }
        }
        final ChronoLocalDate effectiveDate;
        if (overrideChrono != null) {
View Full Code Here

Examples of org.threeten.bp.ZoneId

        }

        //-----------------------------------------------------------------------
        @Override
        public boolean print(DateTimePrintContext context, StringBuilder buf) {
            ZoneId zone = context.getValue(TemporalQueries.zoneId());
            if (zone == null) {
                return false;
            }
            if (zone.normalized() instanceof ZoneOffset) {
                buf.append(zone.getId());
                return true;
            }
            Long epochSec = context.getTemporal().getLong(INSTANT_SECONDS);
            Instant instant;
            if (epochSec != null) {
                instant = Instant.ofEpochSecond(epochSec);
            } else {
                instant = Instant.ofEpochSecond(-200L * 365 * 86400)// about 1770
            }
            TimeZone tz = TimeZone.getTimeZone(zone.getId());
            boolean daylight = zone.getRules().isDaylightSavings(instant);
            int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
            String text = tz.getDisplayName(daylight, tzstyle, context.getLocale());
            buf.append(text);
            return true;
        }
View Full Code Here

Examples of org.threeten.bp.ZoneId

        }

        //-----------------------------------------------------------------------
        @Override
        public boolean print(DateTimePrintContext context, StringBuilder buf) {
            ZoneId zone = context.getValue(query);
            if (zone == null) {
                return false;
            }
            buf.append(zone.getId());
            return true;
        }
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.