Examples of ZoneId


Examples of java.time.ZoneId

            this.description = description;
        }

        @Override
        public boolean format(DateTimePrintContext context, StringBuilder buf) {
            ZoneId zone = context.getValue(query);
            if (zone == null) {
                return false;
            }
            buf.append(zone.getId());
            return true;
        }
View Full Code Here

Examples of java.time.ZoneId

                    Flags flags = Flags.ZERO_PAD;
                    sb.append(localizedMagnitude(null, offset, flags, 4, l));
                    break;
                }
                case DateTime.ZONE:        { // 'Z' (symbol)
                    ZoneId zid = t.query(TemporalQueries.zone());
                    if (zid == null) {
                        throw new IllegalFormatConversionException(c, t.getClass());
                    }
                    if (!(zid instanceof ZoneOffset) &&
                        t.isSupported(ChronoField.INSTANT_SECONDS)) {
                        Instant instant = Instant.from(t);
                        sb.append(TimeZone.getTimeZone(zid.getId())
                                          .getDisplayName(zid.getRules().isDaylightSavings(instant),
                                                          TimeZone.SHORT,
                                                          (l == null) ? Locale.US : l));
                        break;
                    }
                    sb.append(zid.getId());
                    break;
                }
                // Date
                case DateTime.NAME_OF_DAY_ABBREV:     // 'a'
                case DateTime.NAME_OF_DAY:          { // 'A'
View Full Code Here

Examples of java.time.ZoneId

     * @throws DateTimeException if unable to create the date-time
     * @see ChronoZonedDateTime#from(TemporalAccessor)
     */
    default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
        try {
            ZoneId zone = ZoneId.from(temporal);
            try {
                Instant instant = Instant.from(temporal);
                return zonedDateTime(instant, zone);

            } catch (DateTimeException ex1) {
View Full Code Here

Examples of java.time.ZoneId

    }

    static ChronoZonedDateTime<?> readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        ChronoLocalDateTime<?> dateTime = (ChronoLocalDateTime<?>) in.readObject();
        ZoneOffset offset = (ZoneOffset) in.readObject();
        ZoneId zone = (ZoneId) in.readObject();
        return dateTime.atZone(offset).withZoneSameLocal(zone);
        // TODO: ZDT uses ofLenient()
    }
View Full Code Here

Examples of java.time.ZoneId

    }

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

        // ensure minimal change (early return is an optimization)
        Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
        ZoneId temporalZone = temporal.query(TemporalQueries.zoneId());
        if (Objects.equals(overrideChrono, temporalChrono)) {
            overrideChrono = null;
        }
        if (Objects.equals(overrideZone, temporalZone)) {
            overrideZone = null;
        }
        if (overrideChrono == null && overrideZone == null) {
            return temporal;
        }

        // make adjustment
        final Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono);
        if (overrideZone != null) {
            // if have zone and instant, calculation is simple, defaulting chrono if necessary
            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
            if (overrideZone.normalized() instanceof ZoneOffset && temporal.isSupported(OFFSET_SECONDS) &&
                    temporal.get(OFFSET_SECONDS) != overrideZone.getRules().getOffset(Instant.EPOCH).getTotalSeconds()) {
                throw new DateTimeException("Unable to apply override zone '" + overrideZone +
                        "' because the temporal object being formatted has a different offset but" +
                        " does not represent an instant: " + temporal);
            }
        }
        final ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone);
        final ChronoLocalDate effectiveDate;
        if (overrideChrono != null) {
            if (temporal.isSupported(EPOCH_DAY)) {
                effectiveDate = effectiveChrono.date(temporal);
            } else {
View Full Code Here

Examples of java.time.ZoneId

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

Examples of java.time.ZoneId

    setValue(ZoneId.of(text));
  }

  @Override
  public String getAsText() {
    ZoneId value = (ZoneId) getValue();
    return (value != null ? value.getId() : "");
  }
View Full Code Here

Examples of java.time.ZoneId

  public void testAmericaLosAngeles() {
    ZoneIdEditor editor = new ZoneIdEditor();
    editor.setAsText("America/Los_Angeles");

    ZoneId zoneId = (ZoneId) editor.getValue();
    assertNotNull("The zone ID should not be null.", zoneId);
    assertEquals("The zone ID is not correct.", ZoneId.of("America/Los_Angeles"), zoneId);

    assertEquals("The text version is not correct.", "America/Los_Angeles", editor.getAsText());
  }
View Full Code Here

Examples of java.time.ZoneId

  @Test
  public void createDateTimeFormatterWithTimeZone() throws Exception {
    factory.setPattern("yyyyMMddHHmmss Z");
    factory.setTimeZone(TEST_TIMEZONE);
    ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId();
    ZonedDateTime dateTime = ZonedDateTime.of(2009, 10, 21, 12, 10, 00, 00, dateTimeZone);
    String offset = (TEST_TIMEZONE.equals(NEW_YORK) ? "-0400" : "+0200");
    assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000 " + offset));
  }
View Full Code Here

Examples of java.time.ZoneId

    @Override public ZonedDateTime toJava(Object... value) {
        Date dt = (Date) value[0];
        if (dt == null) {
            return null;
        }
        ZoneId zone = ZoneId.of((String) value[1]);
        LocalDateTime ldt = LocalDateTime.from(dt.toInstant());
        return ZonedDateTime.of(ldt, zone);
    }
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.