/// <summary> /// Parse once a prefix is established. /// </summary> /// <param name="zoneId"> the time-zone ID, not null </param> /// <param name="prefixLength"> the length of the prefix, 2 or 3 </param> /// <returns> the zone ID, not null </returns> /// <exception cref="DateTimeException"> if the zone ID has an invalid format </exception> private static ZoneId OfWithPrefix(String zoneId, int prefixLength, bool checkAvailable) { String prefix = zoneId.Substring(0, prefixLength); if (zoneId.Length() == prefixLength) { return(OfOffset(prefix, ZoneOffset.UTC)); } if (zoneId.CharAt(prefixLength) != '+' && zoneId.CharAt(prefixLength) != '-') { return(ZoneRegion.OfId(zoneId, checkAvailable)); // drop through to ZoneRulesProvider } try { ZoneOffset offset = ZoneOffset.Of(zoneId.Substring(prefixLength)); if (offset == ZoneOffset.UTC) { return(OfOffset(prefix, offset)); } return(OfOffset(prefix, offset)); } catch (DateTimeException ex) { throw new DateTimeException("Invalid ID for offset-based ZoneId: " + zoneId, ex); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static Object readInternal(byte type, java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException private static Object ReadInternal(sbyte type, ObjectInput @in) { switch (type) { case DURATION_TYPE: return(Duration.ReadExternal(@in)); case INSTANT_TYPE: return(Instant.ReadExternal(@in)); case LOCAL_DATE_TYPE: return(LocalDate.ReadExternal(@in)); case LOCAL_DATE_TIME_TYPE: return(LocalDateTime.ReadExternal(@in)); case LOCAL_TIME_TYPE: return(LocalTime.ReadExternal(@in)); case ZONE_DATE_TIME_TYPE: return(ZonedDateTime.ReadExternal(@in)); case ZONE_OFFSET_TYPE: return(ZoneOffset.ReadExternal(@in)); case ZONE_REGION_TYPE: return(ZoneRegion.ReadExternal(@in)); case OFFSET_TIME_TYPE: return(OffsetTime.ReadExternal(@in)); case OFFSET_DATE_TIME_TYPE: return(OffsetDateTime.ReadExternal(@in)); case YEAR_TYPE: return(Year.ReadExternal(@in)); case YEAR_MONTH_TYPE: return(YearMonth.ReadExternal(@in)); case MONTH_DAY_TYPE: return(MonthDay.ReadExternal(@in)); case PERIOD_TYPE: return(Period.ReadExternal(@in)); default: throw new StreamCorruptedException("Unknown serialized type"); } }
/// <summary> /// Parses the ID, taking a flag to indicate whether {@code ZoneRulesException} /// should be thrown or not, used in deserialization. /// </summary> /// <param name="zoneId"> the time-zone ID, not null </param> /// <param name="checkAvailable"> whether to check if the zone ID is available </param> /// <returns> the zone ID, not null </returns> /// <exception cref="DateTimeException"> if the ID format is invalid </exception> /// <exception cref="ZoneRulesException"> if checking availability and the ID cannot be found </exception> internal static ZoneId Of(String zoneId, bool checkAvailable) { Objects.RequireNonNull(zoneId, "zoneId"); if (zoneId.Length() <= 1 || zoneId.StartsWith("+") || zoneId.StartsWith("-")) { return(ZoneOffset.Of(zoneId)); } else if (zoneId.StartsWith("UTC") || zoneId.StartsWith("GMT")) { return(OfWithPrefix(zoneId, 3, checkAvailable)); } else if (zoneId.StartsWith("UT")) { return(OfWithPrefix(zoneId, 2, checkAvailable)); } return(ZoneRegion.OfId(zoneId, checkAvailable)); }