public static ZoneRules of(ZoneOffset offset) { return offset.getRules(); }
/** * Obtains an instance of {@code ZoneId} from an identifier. * * @param zoneId the time-zone ID, not null * @param checkAvailable whether to check if the zone ID is available * @return the zone ID, not null * @throws DateTimeException if the ID format is invalid * @throws DateTimeException if checking availability and the ID cannot be found */ static ZoneRegion ofId(String zoneId, boolean checkAvailable) { Jdk8Methods.requireNonNull(zoneId, "zoneId"); if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) { throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId); } ZoneRules rules = null; try { // always attempt load for better behavior after deserialization rules = ZoneRulesProvider.getRules(zoneId, true); } catch (ZoneRulesException ex) { // special case as removed from data file if (zoneId.equals("GMT0")) { rules = ZoneOffset.UTC.getRules(); } else if (checkAvailable) { throw ex; } } return new ZoneRegion(zoneId, rules); }
return new ZoneRegion(zoneId, ZoneOffset.UTC.getRules()); ZoneOffset offset = ZoneOffset.of(zoneId.substring(3)); if (offset.getTotalSeconds() == 0) { return new ZoneRegion(zoneId.substring(0, 3), offset.getRules()); return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules()); return new ZoneRegion("UT", offset.getRules()); return new ZoneRegion("UT" + offset.getId(), offset.getRules());
/** * Obtains an instance of {@code ZoneId} wrapping an offset. * <p> * If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId} * with the prefix and the non-zero offset is returned. * If the prefix is empty {@code ""} the {@code ZoneOffset} is returned. * * @param prefix the time-zone ID, not null * @param offset the offset, not null * @return the zone ID, not null * @throws IllegalArgumentException if the prefix is not one of * "GMT", "UTC", or "UT", or "" */ public static ZoneId ofOffset(String prefix, ZoneOffset offset) { Jdk8Methods.requireNonNull(prefix, "prefix"); Jdk8Methods.requireNonNull(offset, "offset"); if (prefix.length() == 0) { return offset; } if (prefix.equals("GMT") || prefix.equals("UTC") || prefix.equals("UT")) { if (offset.getTotalSeconds() == 0) { return new ZoneRegion(prefix, offset.getRules()); } return new ZoneRegion(prefix + offset.getId(), offset.getRules()); } throw new IllegalArgumentException("Invalid prefix, must be GMT, UTC or UT: " + prefix); }
return new ZoneRegion(zoneId, ZoneOffset.UTC.getRules()); ZoneOffset offset = ZoneOffset.of(zoneId.substring(3)); if (offset.getTotalSeconds() == 0) { return new ZoneRegion(zoneId.substring(0, 3), offset.getRules()); return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules()); return new ZoneRegion("UT", offset.getRules()); return new ZoneRegion("UT" + offset.getId(), offset.getRules());