/** * Outputs this zone as a {@code String}, using the ID. * * @return a string representation of this time-zone ID, not null */ @Override public String toString() { return getId(); }
/** * Outputs this zone as a {@code String}, using the ID. * * @return a string representation of this time-zone ID, not null */ @Override public String toString() { return getId(); }
/** * A hash code for this time-zone ID. * * @return a suitable hash code */ @Override public int hashCode() { return getId().hashCode(); }
/** * A hash code for this time-zone ID. * * @return a suitable hash code */ @Override public int hashCode() { return getId().hashCode(); }
/** * Checks if this time-zone ID is equal to another time-zone ID. * <p> * The comparison is based on the ID. * * @param obj the object to check, null returns false * @return true if this is equal to the other time-zone ID */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ZoneId) { ZoneId other = (ZoneId) obj; return getId().equals(other.getId()); } return false; }
/** * Checks if this time-zone ID is equal to another time-zone ID. * <p> * The comparison is based on the ID. * * @param obj the object to check, null returns false * @return true if this is equal to the other time-zone ID */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ZoneId) { ZoneId other = (ZoneId) obj; return getId().equals(other.getId()); } return false; }
/** * Converts a {@code ZoneId} to a {@code TimeZone}. * * @param zoneId the zone, not null * @return the time-zone, not null */ public static TimeZone toTimeZone(ZoneId zoneId) { String tzid = zoneId.getId(); if (tzid.startsWith("+") || tzid.startsWith("-")) { tzid = "GMT" + tzid; } else if (tzid.equals("Z")) { tzid = "UTC"; } return TimeZone.getTimeZone(tzid); }
/** * Converts a {@code ZoneId} to a {@code TimeZone}. * * @param zoneId the zone, not null * @return the time-zone, not null */ public static TimeZone toTimeZone(ZoneId zoneId) { String tzid = zoneId.getId(); if (tzid.startsWith("+") || tzid.startsWith("-")) { tzid = "GMT" + tzid; } else if (tzid.equals("Z")) { tzid = "UTC"; } return TimeZone.getTimeZone(tzid); }
@Override public boolean print(DateTimePrintContext context, StringBuilder buf) { ZoneId zone = context.getValue(query); if (zone == null) { return false; } buf.append(zone.getId()); return true; }
@Override public boolean print(DateTimePrintContext context, StringBuilder buf) { ZoneId zone = context.getValue(query); if (zone == null) { return false; } buf.append(zone.getId()); return true; }
@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; } TemporalAccessor temporal = context.getTemporal(); boolean daylight = false; if (temporal.isSupported(INSTANT_SECONDS)) { Instant instant = Instant.ofEpochSecond(temporal.getLong(INSTANT_SECONDS)); daylight = zone.getRules().isDaylightSavings(instant); } TimeZone tz = TimeZone.getTimeZone(zone.getId()); int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT); String text = tz.getDisplayName(daylight, tzstyle, context.getLocale()); buf.append(text); return true; }
@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; } TemporalAccessor temporal = context.getTemporal(); boolean daylight = false; if (temporal.isSupported(INSTANT_SECONDS)) { Instant instant = Instant.ofEpochSecond(temporal.getLong(INSTANT_SECONDS)); daylight = zone.getRules().isDaylightSavings(instant); } TimeZone tz = TimeZone.getTimeZone(zone.getId()); int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT); String text = tz.getDisplayName(daylight, tzstyle, context.getLocale()); buf.append(text); return true; }
/** * Compares this date-time to another date-time, including the chronology. * <p> * The comparison is based first on the instant, then on the local date-time, * then on the zone ID, then on the chronology. * It is "consistent with equals", as defined by {@link Comparable}. * <p> * If all the date-time objects being compared are in the same chronology, then the * additional chronology stage is not required. * * @param other the other date-time to compare to, not null * @return the comparator value, negative if less, positive if greater */ @Override public int compareTo(ChronoZonedDateTime<?> other) { int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); if (cmp == 0) { cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); if (cmp == 0) { cmp = toLocalDateTime().compareTo(other.toLocalDateTime()); if (cmp == 0) { cmp = getZone().getId().compareTo(other.getZone().getId()); if (cmp == 0) { cmp = toLocalDate().getChronology().compareTo(other.toLocalDate().getChronology()); } } } } return cmp; }
/** * Compares this date-time to another date-time, including the chronology. * <p> * The comparison is based first on the instant, then on the local date-time, * then on the zone ID, then on the chronology. * It is "consistent with equals", as defined by {@link Comparable}. * <p> * If all the date-time objects being compared are in the same chronology, then the * additional chronology stage is not required. * * @param other the other date-time to compare to, not null * @return the comparator value, negative if less, positive if greater */ @Override public int compareTo(ChronoZonedDateTime<?> other) { int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); if (cmp == 0) { cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); if (cmp == 0) { cmp = toLocalDateTime().compareTo(other.toLocalDateTime()); if (cmp == 0) { cmp = getZone().getId().compareTo(other.getZone().getId()); if (cmp == 0) { cmp = toLocalDate().getChronology().compareTo(other.toLocalDate().getChronology()); } } } } return cmp; }