Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
//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");
            }
        }
Exemplo n.º 3
0
 /// <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));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Obtains an instance of {@code ZoneId} wrapping an offset.
        /// <para>
        /// 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.
        ///
        /// </para>
        /// </summary>
        /// <param name="prefix">  the time-zone ID, not null </param>
        /// <param name="offset">  the offset, not null </param>
        /// <returns> the zone ID, not null </returns>
        /// <exception cref="IllegalArgumentException"> if the prefix is not one of
        ///     "GMT", "UTC", or "UT", or "" </exception>
        public static ZoneId OfOffset(String prefix, ZoneOffset offset)
        {
            Objects.RequireNonNull(prefix, "prefix");
            Objects.RequireNonNull(offset, "offset");
            if (prefix.Length() == 0)
            {
                return(offset);
            }

            if (!prefix.Equals("GMT") && !prefix.Equals("UTC") && !prefix.Equals("UT"))
            {
                throw new IllegalArgumentException("prefix should be GMT, UTC or UT, is: " + prefix);
            }

            if (offset.TotalSeconds != 0)
            {
                prefix = prefix.Concat(offset.Id);
            }
            return(new ZoneRegion(prefix, offset.Rules));
        }