Java Code Examples for java.time.ZoneId#getId()

The following examples show how to use java.time.ZoneId#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTimeFormatterBuilder.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
    ZoneId zone = context.getValue(TemporalQueries.zoneId());
    if (zone == null) {
        return false;
    }
    String zname = zone.getId();
    if (!(zone instanceof ZoneOffset)) {
        TemporalAccessor dt = context.getTemporal();
        String name = getDisplayName(zname,
                                     dt.isSupported(ChronoField.INSTANT_SECONDS)
                                     ? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD)
                                     : GENERIC,
                                     context.getLocale());
        if (name != null) {
            zname = name;
        }
    }
    buf.append(zname);
    return true;
}
 
Example 2
Source File: DateTimeFormatterBuilder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
    ZoneId zone = context.getValue(TemporalQueries.zoneId());
    if (zone == null) {
        return false;
    }
    String zname = zone.getId();
    if (!(zone instanceof ZoneOffset)) {
        TemporalAccessor dt = context.getTemporal();
        String name = getDisplayName(zname,
                                     dt.isSupported(ChronoField.INSTANT_SECONDS)
                                     ? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD)
                                     : GENERIC,
                                     context.getLocale());
        if (name != null) {
            zname = name;
        }
    }
    buf.append(zname);
    return true;
}
 
Example 3
Source File: DateTimeFormatterBuilder.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
    ZoneId zone = context.getValue(TemporalQueries.zoneId());
    if (zone == null) {
        return false;
    }
    String zname = zone.getId();
    if (!(zone instanceof ZoneOffset)) {
        TemporalAccessor dt = context.getTemporal();
        String name = getDisplayName(zname,
                                     dt.isSupported(ChronoField.INSTANT_SECONDS)
                                     ? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD)
                                     : GENERIC,
                                     context.getLocale());
        if (name != null) {
            zname = name;
        }
    }
    buf.append(zname);
    return true;
}
 
Example 4
Source File: TimeZone.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the {@code TimeZone} for the given {@code zoneId}.
 *
 * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
 * @return the specified {@code TimeZone}, or the GMT zone if the given ID
 *         cannot be understood.
 * @throws NullPointerException if {@code zoneId} is {@code null}
 * @since 1.8
 */
public static TimeZone getTimeZone(ZoneId zoneId) {
    String tzid = zoneId.getId(); // throws an NPE if null
    char c = tzid.charAt(0);
    if (c == '+' || c == '-') {
        tzid = "GMT" + tzid;
    } else if (c == 'Z' && tzid.length() == 1) {
        tzid = "UTC";
    }
    return getTimeZone(tzid, true);
}
 
Example 5
Source File: TimeZone.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the {@code TimeZone} for the given {@code zoneId}.
 *
 * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
 * @return the specified {@code TimeZone}, or the GMT zone if the given ID
 *         cannot be understood.
 * @throws NullPointerException if {@code zoneId} is {@code null}
 * @since 1.8
 */
public static TimeZone getTimeZone(ZoneId zoneId) {
    String tzid = zoneId.getId(); // throws an NPE if null
    char c = tzid.charAt(0);
    if (c == '+' || c == '-') {
        tzid = "GMT" + tzid;
    } else if (c == 'Z' && tzid.length() == 1) {
        tzid = "UTC";
    }
    return getTimeZone(tzid, true);
}
 
Example 6
Source File: DateTimeController.java    From Spring-Boot-2-Fundamentals with MIT License 5 votes vote down vote up
@GetMapping("/api/datetime")
public DateTime datetime() {
    ZonedDateTime now = ZonedDateTime.now();
    String date = now.format(DateTimeFormatter.ISO_LOCAL_DATE);
    String time = now.format(DateTimeFormatter.ISO_LOCAL_TIME);
    ZoneId zone = now.getZone();
    ZoneOffset offset = zone.getRules().getOffset(now.toLocalDateTime());
    String zoneString = String.format("%s (%s)",
            zone.getDisplayName(FULL, Locale.UK), zone.getDisplayName(SHORT, Locale.UK));

    return new DateTime(date, time, zoneString, zone.getId(), offset.getId());
}
 
Example 7
Source File: TimeZone.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the {@code TimeZone} for the given {@code zoneId}.
 *
 * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
 * @return the specified {@code TimeZone}, or the GMT zone if the given ID
 *         cannot be understood.
 * @throws NullPointerException if {@code zoneId} is {@code null}
 * @since 1.8
 */
public static TimeZone getTimeZone(ZoneId zoneId) {
    String tzid = zoneId.getId(); // throws an NPE if null
    char c = tzid.charAt(0);
    if (c == '+' || c == '-') {
        tzid = "GMT" + tzid;
    } else if (c == 'Z' && tzid.length() == 1) {
        tzid = "UTC";
    }
    return getTimeZone(tzid, true);
}
 
Example 8
Source File: DesugarTimeZone.java    From desugar_jdk_libs with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the {@code TimeZone} for the given {@code zoneId}.
 *
 * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
 * @return the specified {@code TimeZone}, or the GMT zone if the given ID
 *         cannot be understood.
 * @throws NullPointerException if {@code zoneId} is {@code null}
 * @since 1.8
 */
public static TimeZone getTimeZone(ZoneId zoneId) {
    String tzid = zoneId.getId(); // throws an NPE if null
    char c = tzid.charAt(0);
    if (c == '+' || c == '-') {
        tzid = "GMT" + tzid;
    } else if (c == 'Z' && tzid.length() == 1) {
        tzid = "UTC";
    }
    return TimeZone.getTimeZone(tzid);  // for desugar: call appropriate public TimeZone method
}
 
Example 9
Source File: DateServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsTriggerWhenTheCurrentTimeEqualsWithTheNextTriggerAndZonesAreEquivalentThenItShouldTriggerAnEvent() {
    ZoneId zone = ZoneId.systemDefault();
    String timeZone = zone.getId();
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 0, 0, 0, zone.normalized());
    long monitorUpdateRate = 60000L;

    when(dateTimeService.getDefaultZonedDateTime()).thenReturn(currentZonedTime);
    when(dateTimeService.getZonedDateTime(currentZonedTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert(timeZone);
    assertTrue(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
 
Example 10
Source File: TimeZone.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Gets the {@code TimeZone} for the given {@code zoneId}.
 *
 * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
 * @return the specified {@code TimeZone}, or the GMT zone if the given ID
 *         cannot be understood.
 * @throws NullPointerException if {@code zoneId} is {@code null}
 * @since 1.8
 */
public static TimeZone getTimeZone(ZoneId zoneId) {
    String tzid = zoneId.getId(); // throws an NPE if null
    char c = tzid.charAt(0);
    if (c == '+' || c == '-') {
        tzid = "GMT" + tzid;
    } else if (c == 'Z' && tzid.length() == 1) {
        tzid = "UTC";
    }
    return getTimeZone(tzid, true);
}
 
Example 11
Source File: TimeZone.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@code TimeZone} for the given {@code zoneId}.
 *
 * @param zoneId a {@link ZoneId} from which the time zone ID is obtained
 * @return the specified {@code TimeZone}, or the GMT zone if the given ID
 *         cannot be understood.
 * @throws NullPointerException if {@code zoneId} is {@code null}
 * @since 1.8
 */
public static TimeZone getTimeZone(ZoneId zoneId) {
    String tzid = zoneId.getId(); // throws an NPE if null
    char c = tzid.charAt(0);
    if (c == '+' || c == '-') {
        tzid = "GMT" + tzid;
    } else if (c == 'Z' && tzid.length() == 1) {
        tzid = "UTC";
    }
    return getTimeZone(tzid, true);
}
 
Example 12
Source File: ZoneIdEditor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getAsText() {
	ZoneId value = (ZoneId) getValue();
	return (value != null ? value.getId() : "");
}
 
Example 13
Source File: ZoneIdTypeDescriptor.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public String toString(ZoneId value) {
    return value.getId();
}
 
Example 14
Source File: ZoneIdEditor.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String getAsText() {
	ZoneId value = (ZoneId) getValue();
	return (value != null ? value.getId() : "");
}
 
Example 15
Source File: Json.java    From morpheus-core with Apache License 2.0 4 votes vote down vote up
@Override
public JsonElement serialize(ZoneId value, Type type, JsonSerializationContext context) {
    return value == null ? JsonNull.INSTANCE : new JsonPrimitive(value.getId());
}
 
Example 16
Source File: ZoneIdEditor.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
@Override
public String getAsText() {
	ZoneId value = (ZoneId) getValue();
	return (value != null ? value.getId() : "");
}
 
Example 17
Source File: DateTimeConverters.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 4 votes vote down vote up
public static String toJson(@NonNull final ZoneId zoneId)
{
	return zoneId.getId();
}
 
Example 18
Source File: ZoneIdHandle.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
public ZoneIdHandle(ZoneId o) {
    this.zoneId = o.getId();
}
 
Example 19
Source File: ZoneIdXmlAdapter.java    From threeten-jaxb with Apache License 2.0 4 votes vote down vote up
@Override
public String marshal(ZoneId value) {
    return value != null ? value.getId() : null;
}
 
Example 20
Source File: TimeZoneChooserValues.java    From datacollector with Apache License 2.0 3 votes vote down vote up
/**
   * Create user visible label for given zone id.
   *
   * The created labels are in format $OFFSET $SHORT ($NAME), e.g.
   *
   * +01:00 CET (Europe/Prague)
   * -07:00 PST (America/Los_Angeles)
   */
//  @VisibleForTesting
  static String getLabelForTimeZoneId(ZoneId zoneId) {
    ZoneOffset zos = LocalDateTime.now().atZone(zoneId).getOffset();

    return zos.getId().replaceAll("Z", "+00:00") + " " + zoneId.getDisplayName(TextStyle.SHORT, Locale.getDefault()) + " (" + zoneId.getId() + ")";
  }